Wednesday, January 7, 2009

nohup and running a process in background....

There are scenarios that we encounter that we run a job that will take more time to complete than our session time out.

Eg. We run an export for database which run for 6 hrs where are our ssh session will have a time out of 30 or 45, once the job in process and no input from keyboard to our ssh session then the session idle timeout count start. Once the idle time out happen our session and the job running in the session gets terminated.

There are three ways that we can overcome this situation.

1. Hard core just press enter in our ssh ( putty window) though it make no sence just to keep session active.
2. Run job in background using & option.
3. Use “ nohup option”

Option 2:

Eg.
# exp sys@dbname file=exp_dbname_date.exp log=exp_dbname_date.log full=y &

This will send the export process to back ground but, export process get terminated the moment the session terminates.

You can use the below script to keep your session alive with a simple while loop to run infinite loop.

#while true
>do
>echo " Exp going on"
>sleep 200
>done
Here you will not get prompt till you press Ctl + c (^c). This process will keep your session alive till you press enter.


Option 3:

Using nohup option

Eg.
# nohup exp sys@dbname file=exp_dbname_date.exp log=exp_dbname_date.log full=y &

or

# vi exp_script.sh
exp sys@dbname file=exp_dbname_date.exp log=exp_dbname_date.log full=y
:wq

# ls –l
Check the permissions if that has execute permissions
#chomod 755 exp_script.sh

# nohup ./exp_script.sh &

Here even when your session terminates job run in background.

No comments: