1833748 Members
2588 Online
110063 Solutions
New Discussion

script needed

 
Ridzuan Zakaria
Frequent Advisor

script needed

Hi,

I am using the below script to swtich to another id and run a script.

.....
(sleep 2
echo /home/users/reset.sh
sleep 20
echo exit) | sw rkat
......

What the above script does is switch to user rkat and execute reset.sh script.

My problem the reset.sh will terminated after 20 second or depend on the value that assign to sleep. I am hoping the above code will run reset.sh until finish and sleep for 20 second and exit not to exit after 20 second while reset.sh is still running. Since the time taken to run reset.sh can not be determined in advance and I am not able to run the above script (reset.sh) to finish.

Any idea to get around with the problem?

I have tried to use & but still it doesn't help

(sleep 2
echo "/home/users/reset.sh &"
sleep 20
echo exit) | sw rkat

Thanks.

quest for perfections
4 REPLIES 4
steven Burgess_2
Honored Contributor

Re: script needed

Hi

You simply need to use wait , instead of sleep. This will wait for process to finish before cotinuing with next task

HTH

Steve
take your time and think things through
Ridzuan Zakaria
Frequent Advisor

Re: script needed

Hi,

I have tried you suggestion to use wait instead, somehow it still doesn't work. Probably I didn't do it right. Here is what I did

sleep 2
echo "/home/users/reset.sh &"
wait
echo exit) | sw rkat

By doing this the script exit immediately.

Please advised
quest for perfections
Jeff Schussele
Honored Contributor

Re: script needed

Hi Ridzuan,

I have no idea what this script does or whether it *needs* to run in the background - but you ought to ba able to do the following:

su rkat -c "/home/users/reset.sh ; exit"

This will run the script as the rkat user & the exit will not occur until the script returns.

The problem with the wait command is that it needs to work on a PID.

HTH,
Jeff
PERSEVERANCE -- Remember, whatever does not kill you only makes you stronger!
T G Manikandan
Honored Contributor

Re: script needed

use

su - -c '