need to know status from "su -c"


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting need to know status from "su -c"
# 1  
Old 01-28-2009
need to know status from "su -c"

Hi,

I am executing a script as root user which needs to do something as oracle user.

So I have following in my script:

Code:
 
#!/bin/sh
..........
..........
su - oracle -c "export ORACLE_SID=MYSID; cd /global/home/orasql/$ORACLE_SID; ./doSomething.sh"
if [ $? -ne 0 ]; then echo "Error running doSomething.sh"
fi


If doSomething.sh returns an error, my echo stmt does not execute (maybe because su succeeds). How do I make it execute? Thanks.
# 2  
Old 01-28-2009
How about...
Code:
su - oracle -c "export ORACLE_SID=MYSID; cd /global/home/orasql/$ORACLE_SID; ./doSomething.sh; [ $? -ne 0 ] &&  echo 'Error running doSomething.sh' "

# 3  
Old 01-28-2009
That works Smilie

Preferably I want status code so that I can exit from the main script depending on the status code.

Thanks again.
# 4  
Old 01-29-2009
Trying writing the status to a file in the child script and processing it back in the parent...
Code:
su - oracle -c "export ORACLE_SID=MYSID; cd /global/home/orasql/$ORACLE_SID; ./doSomething.sh; echo $? > /tmp/doSomething.stat "
if [ `cat /tmp/doSomething.stat` -ne 0 ]; then
 echo "Error running doSomething.sh" 
fi
rm /tmp/doSomething.stat

Jerry
# 5  
Old 01-29-2009
Actually the following works well:

Code:
 
su - oracle -c "/global/home/orasql/MYSID/doSomething.sh"

if [ $? -ne 0 ]; then echo "Error running doSomething.sh"
fi

I can now get status from doSomething.sh w/o any problem. Thanks.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. AIX

Apache 2.4 directory cannot display "Last modified" "Size" "Description"

Hi 2 all, i have had AIX 7.2 :/# /usr/IBMAHS/bin/apachectl -v Server version: Apache/2.4.12 (Unix) Server built: May 25 2015 04:58:27 :/#:/# /usr/IBMAHS/bin/apachectl -M Loaded Modules: core_module (static) so_module (static) http_module (static) mpm_worker_module (static) ... (3 Replies)
Discussion started by: penchev
3 Replies

2. Shell Programming and Scripting

Bash script - Print an ascii file using specific font "Latin Modern Mono 12" "regular" "9"

Hello. System : opensuse leap 42.3 I have a bash script that build a text file. I would like the last command doing : print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt where : print_cmd ::= some printing... (1 Reply)
Discussion started by: jcdole
1 Replies

3. UNIX for Dummies Questions & Answers

Using "mailx" command to read "to" and "cc" email addreses from input file

How to use "mailx" command to do e-mail reading the input file containing email address, where column 1 has name and column 2 containing “To” e-mail address and column 3 contains “cc” e-mail address to include with same email. Sample input file, email.txt Below is an sample code where... (2 Replies)
Discussion started by: asjaiswal
2 Replies

4. Ubuntu

What is solution for this error "tar: Exiting with failure status due to previous errors"?

Does anyone know what is solution for this error ?tar: Exiting with failure status due to previous errors from last 3 days I am trying to take backup of home/user directory getting again and again same error please anyone give me solution (8 Replies)
Discussion started by: Akshay Hegde
8 Replies

5. HP-UX

BOGGLED!! User information incorrect when viewing "ps" Process Status

Hello Anyone: I have run into an issue that I have never seen or heard of. Recently on a specific server I have encountered a random issue that I've not been able to repliate on demand... When I view the processes status of a certain process, the information returned to the screen has a... (2 Replies)
Discussion started by: DEN1022
2 Replies

6. UNIX for Dummies Questions & Answers

print queue hung in "SENDING" status

Dear All, Realized recently some of the print queue configured with rembak, are hung in "SENDING" status. The only workaround for this is to disable and enable back the print queue. This issue happen very random and frequent. I turned on the debug mode for a print queue and the... (0 Replies)
Discussion started by: nj1986
0 Replies

7. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

8. UNIX for Dummies Questions & Answers

Explain the line "mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`"

Hi Friends, Can any of you explain me about the below line of code? mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'` Im not able to understand, what exactly it is doing :confused: Any help would be useful for me. Lokesha (4 Replies)
Discussion started by: Lokesha
4 Replies

9. Shell Programming and Scripting

Failed to check status code in "rsh" command

Hi folks, I wrote a ksh program which run scripts from remote server. To check the status code I wrote the following function: check_remote_status() { status_code=`tail -1 $installLog` if ] ; then echo $errMsg | tee -a $installLog exit 1 else echo $validMsg >> $installLog fi... (9 Replies)
Discussion started by: nir_s
9 Replies
Login or Register to Ask a Question