Operating System - HP-UX
1834218 Members
3765 Online
110066 Solutions
New Discussion

Re: Run script in background as process

 
SOLVED
Go to solution
N Gopal
Frequent Advisor

Run script in background as process

Hi,

I am having one .scr script. I want to run it as background process means once it is scheduled it will running like deamon i am not bother to run it manuaaly.
Can anyone suggest me how to do it please?

Thanks
7 REPLIES 7
Hein van den Heuvel
Honored Contributor

Re: Run script in background as process


Typically you would use 'cron' for jobs which 'end' and should be scheduled at set intervals.

And you would use 'init' for jobs to be launched when the system is started.

Please read up on the manpages for cron and init and look for examples on your system.
If you have further, detailed questions, after trying some, please elaborate with the exact commands tried and the (exact) problems (error messages) you experienced.

Good luck!
Hein.
Michael Steele_2
Honored Contributor
Solution

Re: Run script in background as process

From the command line: nohup script &
From cron: # # # # # script &
Refer to '&' meta characters in korn shell, C, Poxis, etc.
Support Fatherhood - Stop Family Law
Jeff_Traigle
Honored Contributor

Re: Run script in background as process

Create an infinite loop in the script. The following is a piece of a script we use as part of a "poor man's" failover environment that I implemented.

while true
do
/failover/rsync.sh ${RSYNC_CFG}
sleep ${INTERVAL}
done
--
Jeff Traigle
Laurent Menase
Honored Contributor

Re: Run script in background as process

nohup toto /dev/null &
the redirection can be explicit to /dev/null, a file or a pipe, but if still tty, output will be redirect to $HOME/nohup.out
N Gopal
Frequent Advisor

Re: Run script in background as process

Hi All,

Apologies for late reply. Thanks for your valuable reply.
nohup script & is working for me.

Thanks
Mark Ellzey
Valued Contributor

Re: Run script in background as process

Hello,

I have always followed the following conventions when running 'persistant' scripts:

1. If the script does not absolutly need to run when the machine is rebooted, allow a user with sufficient permissions to start the script. I usually write a short shell wrapper so the user doesn't have to worry about the details of the script.

2. If the script must be started each time the machine is rebooted, you have 2 choices:
a. an rc script which will start the process on reboot - or -
b. an entry in the /etc/inittab file.

Which method I use is determined by the the following:
1. If the script needs to be running at all times, I use /etc/inittab with the 'respawn' option.
2. If it can fail or be terminated without causing a major problem, I use the rc start-up method.

Just my 2cts. worth

Mark
Vivek Bhatia
Trusted Contributor

Re: Run script in background as process

Hi Gopal,

Go through this link.

This will guide you with examples for scheduling the scripts.

http://www.adminschoice.com/docs/crontab.htm

Thanks
Vivek Bhatia