- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: HP-UX 11 shell script: getting return code fro...
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
Forums
Discussions
Discussions
Discussions
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
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
08-15-2003 06:55 AM
08-15-2003 06:55 AM
HP-UX 11 shell script: getting return code from embedded command
I want to know how I can get the return code of a command that is embedded within the sudo command. For example:
$sudo logins -l zinzan
>>user zinzan does not exist
$echo $?
>>0
It seems that the return code 0 I get is for the sudo command and not the logins. Is there a way to isolate the return code of the embedded command?
Thanks
Bob Swail
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-15-2003 06:59 AM
08-15-2003 06:59 AM
Re: HP-UX 11 shell script: getting return code from embedded command
Not 100% sure but sudo should be handling this return code and a sudo switch might give you the code.
I do not have sudo or a server at present to check it.
Something like this.
$sudo -
Paula
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-15-2003 07:03 AM
08-15-2003 07:03 AM
Re: HP-UX 11 shell script: getting return code from embedded command
RETURN VALUES
Upon successful execution of a program, the return value from sudo will simply be the return value of the program that was executed.
Otherwise, sudo quits with an exit value of 1 if there is a configuration/permission problem or if sudo cannot execute the given command. In the latter case the error string is printed to stderr. If sudo cannot stat(2) one or more entries in the user's PATH an error is printed on stderr. (If the directory does not exist or if it is not really a directory, the entry is ignored and no error is printed.) This should not happen under normal circumstances. The most common reason for stat(2) to return ``permission denied'' is if you are running an automounter and one of the directories in your PATH is on a machine that is currently unreachable.
Manual here:-
http://www.courtesan.com/sudo/man/sudo.html#return_values
Paula
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-15-2003 07:14 AM
08-15-2003 07:14 AM
Re: HP-UX 11 shell script: getting return code from embedded command
$login root
#logins -l zinzan
>>login 'zinzan' not found
#echo $?
>>253
#login bswail
$sudo logins -l zinzan
>>login 'zinzan' not found
#echo $?
>>0
If sudo was returning the return code of the logins command, I would expect to see 253 as is tha case when running logins as root.
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-15-2003 07:52 AM
08-15-2003 07:52 AM
Re: HP-UX 11 shell script: getting return code from embedded command
The sudo return code you are seeing is the return code of the "sudo 'login'" command itself.
It is not thr return code of "logins -l zinzan".
A code of 0 indicated that sudo was able to run "logins".
Sudu is a pseudo shell and as such you are dealing with two levels of return codes.
try this:-
create a script say test.sudo
#!/bin/sh
logins -| zinzan
echo $? >
give it ececute permissions, then
$sudo test.sudo
$echo $?
the echo in the script should return the error code from the login command and the echo from the command line the return code of 0 to indicate that sudo ran logins.
HTH
Paula
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-15-2003 10:52 AM
08-15-2003 10:52 AM
Re: HP-UX 11 shell script: getting return code from embedded command
No go.
$cat test.sudo
>>logins -l zinzan
>>echo $?
$sudo test.sudo
>>login 'zinzan' not found
>>0
$echo $?
>>0
Seems like we're still getting the return code from the sudo command and not logins.
Thanks for your help anyway!
Bob