Operating System - HP-UX
1753259 Members
4613 Online
108792 Solutions
New Discussion

ksh: script to handle switch beetween users

 
SOLVED
Go to solution
support_billa
Valued Contributor

ksh: script to handle switch beetween users

hello,

 

i want to collect some scripts to one script . i want start with "root" user, do some steps and switch to an "oracle" user.

in the oracle user i want to start another program  with "nohup ./script 2>&1 > script.log &" .

 

- how can i check , if the script is finished and ok  in the oracle user?

 

i also want to make the programm restart able.

 

what's the best way to handle this .

 

example :

 

#1.root

mkdir /oracle/mnt

echo "1. mkdir"  >> /tmp/steps

chown oracle /tmp/steps

 

#2. oracle

su oracle <<-EOF

.

EOF

echo $?

echo "2. oracle"  >> /tmp/steps

 

#3. oracle

# the special with nohup

su oracle <<-EOF

nohup ./script 2>&1 > script.log &

EOF

echo $?

echo "3. oracle"  >> /tmp/steps

 

when an error will detect, the program stops and i have to check and solve the problem. then i will start the programm again and i will check with "awk", i one step was finished ?

 

regards

 

 

6 REPLIES 6
Ken Grabowski
Respected Contributor

Re: ksh: script to handle switch between users

I never recommend large monolithic scripts that do a lot of processing that could be broken down into smaller easier to restart scripts. However, they are sometimes required when you have complex processes that require a lot of global data to be passed from one process step to another. I also recommend making use of any job control system you may have, like control-m or autosys.

 

With that said,  the methods I've seen use flag file(s) to record processing steps and their exit status. In the event of a failure that causes the process to halt, the core script can be restarted with either a restart flag, or designed to find and read the last unsuccessful flag and start processing again from that point.

 

 

Dennis Handly
Acclaimed Contributor

Re: ksh: script to handle switch between users

>in the oracle user I want to start another program  with "nohup ./script 2>&1 > script.log &" .

 

If the outer script isn't doing anything else, you could wait, instead of putting it in the background.  But you may not want to have it hangup on you.

 

>if the script is finished and ok in the oracle user?

>nohup ./script 2>&1 > script.log &

>EOF

>echo $?

 

The exit status here will just check to see if the su and nohup started but not the status of "script".

 

As Ken said, you need to record your status in a file.  Either the contents or the existence of one.

 

support_billa
Valued Contributor

Re: ksh: script to handle switch between users

hello,

 

thank you for your answers.

 

it is a great idea to use a job control tool but for my issue it is a little overhead

why :

we have to do this steps ( or installation ) not every day or week, sometimes one time in a month .

 

>if the script is finished and ok in the oracle user?

>nohup ./script 2>&1 > script.log &

>EOF

>echo $?

 

this can we change from the background to the foreground for a better handling ?

 

so ,  i think , i have to do the jobs step by step and not i a whole script with user switches.

 

regards

Dennis Handly
Acclaimed Contributor

Re: ksh: script to handle switch between users

>this can we change from the background to the foreground for a better handling?

 

Yes.  It's not like the script has anything else to do while waiting?

support_billa
Valued Contributor

Re: ksh: script to handle switch between users

> Yes.  It's not like the script has anything else to do while waiting?

 

no nothing, these step runs about 30 minutes or longer. so we start the script in the background because want to prevent interruption of network connection and so on.

Dennis Handly
Acclaimed Contributor
Solution

Re: ksh: script to handle switch between users

>because want to prevent interruption of network connection and so on.

 

nohup will do that without putting it in the background.