- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Script giving error
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-16-2011 08:12 PM
тАО01-16-2011 08:12 PM
Script giving error
I am trying a write a script if an user's account gets disabled, then the script would run and mailx reporting the same.
Below is a script that i am trying to create, which is giving an error along with the output.
Kindly let me know what changes needs to be done.
I am looking for a similar script for non-trusted system also. Hope someone can help me sort out this error.
lbsdr-4CPU@APP>cat test1.sh
#!/usr/bin/sh
for USER in $(cat /tmp/users)
do
PCT=$(/usr/lbin/getprpw -m lockout $USER | tr -cd "[1\012]")
PCS=$(hostname)
if (( ${PCT} != 0 )) ; then
echo "Account '$USER' is disabled in the server ${PCS}. Kindly get in touch with UNIX Admin to enable the account"
fi
done
lbsdr-4CPU@APP>
lbsdr-4CPU@APP>cat /tmp/users
sridhar
plasbo
The output says:
lbsdr-4CPU@APP>./test1.sh
Account 'sridhar' is disabled in the server lbsdr. Kindly get in touch with UNIX Admin to enable the account
./test1.sh[6]: != 0 : Assignment requires an lvalue.
Kindly let me know what has to be done here.
Thanks,
Sridhar
- Tags:
- passwd
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-16-2011 08:40 PM
тАО01-16-2011 08:40 PM
Re: Script giving error
Try using a square brackets [] instead of normal brackets () for the IF statement:
if [ ${PCT} != 0 ]
Regards,
Vidhya
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-16-2011 09:17 PM
тАО01-16-2011 09:17 PM
Re: Script giving error
Now it gives me a different error.
lbsdr-4CPU@APP>./test1.sh
Account 'sridhar' is disabled in the server lbsdr. Kindly get in touch with UNIX Admin to enable the account
./test1.sh[6]: test: Specify a parameter with this command.
lbsdr-4CPU@APP>cat test1.sh
#!/usr/bin/sh
for USER in $(cat /tmp/users)
do
PCT=$(/usr/lbin/getprpw -m lockout $USER | tr -cd "[1\012]")
PCS=$(hostname)
if [ ${PCT} != 0 ] ; then
echo "Account '$USER' is disabled in the server ${PCS}. Kindly get in touch with UNIX Admin to enable the account"
fi
done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-16-2011 09:52 PM
тАО01-16-2011 09:52 PM
Re: Script giving error
> here.
Kindly explain what you wish to do here.
What is the output from the simple command?:
/usr/lbin/getprpw -m lockout $USER | tr -cd "[1\012]"
or, even simpler, from:
/usr/lbin/getprpw -m lockout $USER
?
Or in the script:
echo ">${PCT}<"
If you're not sure what's in a variable like
PCT, then it's safer to use some quotation
marks around its value. For example:
if [ "${PCT}" != 0 ] ; then
Are you trying to test the character string
output from this command, or its exit status
value, or what?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-16-2011 10:01 PM
тАО01-16-2011 10:01 PM
Re: Script giving error
What i am trying to do is to run a script to mailx and tell that a particular account is locked among a list of accounts.
I haven't added mailx in the script as of now, but want the script to say that an account has been locked and it needs to be unlocked.
Further, i can add mailx upon the script running successfully.
Thanks,
Sridhar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-17-2011 12:40 AM
тАО01-17-2011 12:40 AM
Re: Script giving error
You are using text comparision operators with numeric values, I suggest you try this into your if statment:
if [ "${PCT}" != "0" ]
then
echo "Account '$USER' is disabled in the server ${PCS}. Kindly get in touch with UNIX Admin to enable the account"
fi
Rgds.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-17-2011 12:48 AM
тАО01-17-2011 12:48 AM
Re: Script giving error
>if (( ${PCT} != 0 )) ; then
This seems like the right syntax. But you don't need to treat PCT special in arithmetic expressions:
if (( PCT != 0 )); then
If this fails, PCT isn't numeric. As Steven said, you should print out its value to see if your tr(1) is correct.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-17-2011 05:45 AM
тАО01-17-2011 05:45 AM
Re: Script giving error
Ok. Did you stop reading at the first
question mark?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-17-2011 05:57 AM
тАО01-17-2011 05:57 AM
Re: Script giving error
If you are running on a non-trusted system, 'getprpw' isn't going to be available. It applies only to the root user of trusted systems.
This said, I would suspect that your 'PCT' variable is simply empty giving you the error you see.
As Steven has said, echo the 'PCT' value with visible surrounding characters of your choice to confirm its emptiness or expose its value.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-17-2011 06:32 AM
тАО01-17-2011 06:32 AM
Re: Script giving error
When double quotes encloses a variable or value convert them into characters values.
So to solve this you only needs set double quotes in your "IF" statement as I have indicated you previously. In this way you can compare any valor that adopt the $PCT variable against the character zero (not value).
Rgds.