1753500 Members
3241 Online
108794 Solutions
New Discussion юеВ

Re: Unix Script

 
sum vedak
Advisor

Unix Script

I am running a script for fsck and mount operation for some filesystems. at the end of the script I want to call script2 and exit or continue from main script, without waiting for the completion/result of second script(script2).

Kindly suggest how to call the second script.
9 REPLIES 9
Ganesan R
Honored Contributor

Re: Unix Script

Hi,

At the end of script1, call script2 to run in the background and return to shell using &

Best wishes,

Ganesh.
sum vedak
Advisor

Re: Unix Script

Hi , thankz..
i tried in background also...but it is waiting till second script completes, then it continues the next line..
Laurent Menase
Honored Contributor

Re: Unix Script

do you mean you remsh or ssh script1 ?


if yes, then you need to do

nohup script2 /dev/null 2>&1 &
- if you want the errors and output of that scrip then
nohup script2 /tmp/result 2>&1 &
sum vedak
Advisor

Re: Unix Script

This is ssh script. Can u explain in detail whay nohup will do ?
Suraj K Sankari
Honored Contributor

Re: Unix Script

Hi,

Suppose I have 2 script /tmp/s1.sh and /tmp/s2.sh and i need both the script should run in a single shot.
in this case I have to make a 3rd file name
vi /tmp/main.sh
sh /tmp/s1.sh &
sh /tmp/s2.sh &

save the file

now run sh /tmp/main.sh

Suraj
sum vedak
Advisor

Re: Unix Script

hi suraj,

Actually I want to run another script2 through script1 and script1 should not wait for completion of script2.

and second question is how can I write a script to check continously the contents of log file and once the particular string found in log file that script will do the required action.
Sani
Frequent Advisor

Re: Unix Script

Hi Sumit ,

Call the second script "script2" as below ,

script2.sh >/dev/null 2>&1 &
exit

It works

Regards
Sanil
Suraj K Sankari
Honored Contributor

Re: Unix Script

Hi,
>>Actually I want to run another script2 through script1 and script1 should not wait for completion of script2.

here also script 1 will not wait for script 2 if you call 2nd script from last line of the script 1 then it will executed once 1 st script will finish his job.

>> and second question is how can I write a script to check continously the contents of log file and once the particular string found in log file that script will do the required action.

If you wana search a string for a file then you have to used grep command and you have to run this command through crontab you can set 1 min to 59 min├в s interval to search string from a file.

Suraj
Laurent Menase
Honored Contributor

Re: Unix Script

nohup is made to make it insensitive to SIGHUP sent by the pty when the ptymaster is closed by ssh.
So it is usefull when you use ssh forcing the use of a pty ( -t ) when doing a remote command
- or run an interactive ssh, start your script , exit from the ssh.


if no specific options are used, ssh will use pipes as stdin&out&err of the child process.
sshd will wait until all process using the other side of those pipes close it before exiting.

so if you do not redirect inputs and outputs it makes that sshd wait for that script to exit before exiting itself

since it is pipes no SIGHUP is sent on closure, so nohup is not necessary if no -t option is used on ssh or if the script can't be start interactively.