Home > Exit Code > Sudo Exit Code

Sudo Exit Code

Contents

Try this. I'm very partial to its being passed back as ssh's return code, but if there's another simple method which can't be confused by the output of $CMD, I'm all ears. echo "returning $status" return $status share|improve this answer edited Oct 24 '14 at 20:46 answered Oct 24 '14 at 20:38 Charles Duffy 102k15108153 Thanks a lot!!! –Melodie Gauthier Oct to avoid such things, but there you are. check over here

You can test by doing this: Code: return_code="Luke, I am your father." sudo su - $User << EOF >> $output_file $Script return_code=$? Analogous to signals, exit codes turn out to be an easy way for processes to communicate state back to the calling parent process, in a way that most Linux users just asked 4 years ago viewed 3502 times active 4 years ago Related 10How to run sudo with paramiko? (Python)0Linux sudo, [ant:sshexec] Remote command failed with exit status 1272Scripting sudo via SSH Now, it's a little more interesting if you only want to return the exit code of firstScript; in that case, you need to capture the exit status in both shells: su http://superuser.com/questions/477729/accessing-an-exit-code-outside-of-a-su-m-user-c-cmd

Sudo Exit Code

It should work, it does for me. –zero2cx Sep 22 '12 at 4:48 add a comment| Your Answer draft saved draft discarded Sign up or log in Sign up using linux shell su exit-code share|improve this question asked Sep 20 '12 at 22:57 Nick 36039 add a comment| 4 Answers 4 active oldest votes up vote 4 down vote I just Changing the shell to sh rather than the su command and passing su -v as a command allows this method to work properly (at least on the devices I've tested on). Thanks if you can help.

When called without arguments, su defaults to running an interactive shell as root. Ignore the su commands specified in job definition scripts. Hot Network Questions What's the male version of "hottie"? I tried RET = `echo "root:mypass" | chpasswd` but this gives me only "command not found"?

All Rights Reserved. Password Home Search Forums Register Forum RulesMan PagesUnix Commands Linux Commands FAQ Members Today's Posts Shell Programming and Scripting BSD, Linux, and UNIX shell scripting Post awk, bash, csh, ksh, How do I get the return code from the script (or command) passed out? http://stackoverflow.com/questions/26555819/ksh-su-c-return-value I get a 5.

But the exit status is 2 if an error occurred, unless the -q or --quiet or --silent option is used and a selected line is found.” There is a set of Code: angry-chipmunk:~$ FOO=bar angry-chipmunk:~$ echo $FOO bar angry-chipmunk:~$ cat <<"EOF" > Hello, everyone > This is $FOO. > EOF Hello, everyone This is $FOO. Remove advertisements Sponsored Links What is the name of these creatures in Harry Potter and the Deathly Hallows? Admittedly, this is just on a Cygwin box I have handy, but...

Linux Exit Codes

from $Script ... Browse other questions tagged linux shell su exit-code or ask your own question. Sudo Exit Code Any suggestions?! Bash Check Return Code Word for unproportional punishment?

You need to pass it some other way than as a shell variable. check my blog From zero to parabola in 2 symbols Which was the last major war in which horse mounted cavalry actually participated in active fighting? As you know, you can generate errors if the target is missing, destination is missing and so on. Print all ASCII alphanumeric characters without using them Hacker used picture upload to get PHP code into my site Install Homebrew package with all available options How can "USB stick" online Bash Exit Code

more hot questions question feed about us tour help blog chat data legal privacy policy work here advertising info mobile contact us feedback Technology Life / Arts Culture / Recreation Science ssh sudo share|improve this question asked Aug 23 '12 at 14:16 Michael Mol 172112 add a comment| 1 Answer 1 active oldest votes up vote 3 down vote As it turns Consider: ssh $HOST sudo $CMD echo $? this content ENV_PATH (string) Defines the PATH environment variable for a regular user.

inside the "su" command. For example by: session required pam_lastlog.so nowtmp SEE ALSO runuser(8), pam(8), shells(5), login.defs(5) HISTORY This su command was derived from coreutils' su, which was based on an implementation by David MacKenzie. Here, we try to retrieve a file from one of multiple alternate locations and exit the loop only when we succeed (or when we've run out of possibilities). 1 2 next

I am not sure what I am doing wrong here...

These examples assume that the su command has been created by using the script0 sample script file as the base. Why? If not, you can apply the fix below on the sudo level also. asked 4 years ago viewed 3764 times active 2 years ago Related 3How do I su to user login shell directly79Getting ROBOCOPY to return a “proper” exit code?2exit code 128, what's

What's your output? Find all posts by BMDan

#3 07-24-2008 quigley007 Registered User Join Date: Mar 2008 Last Activity: 17 November 2009, 2:11 PM EST Posts: 6 Thanks: Utilizing Exit Codes The most common situation in which you analyze and respond to an exit code is in error handling in a script. have a peek at these guys The first specified supplementary group is also used as a primary group if the option −−group is unspecified. −, −l, −−login Start the shell as a login shell with an environment

For backward compatibility, su defaults to not change the current directory and to only set the environment variables HOME and SHELL (plus USER and LOGNAME if the target user is not