Operating System - HP-UX
1833802 Members
2235 Online
110063 Solutions
New Discussion

Re: script always run in background

 
kholikt
Super Advisor

script always run in background

Hi,

Is there any way that I can put a shell script that act like a daemon. I mean to make it always run in background.

abc
6 REPLIES 6
kholikt
Super Advisor

Re: script always run in background

I just want to put this in my script. The whole script should run in background

svrmgrl
connect internal;
recover managed standby database;
abc
Nicolas Dumeige
Esteemed Contributor

Re: script always run in background

Hello,

To put a script in the background detached from tty : nohup.

As for the deamon aspect - like automatic start at boot : /etc/rc scripts

You might want to do another script (in crontab for instance) to check that the first one is always running.

Anyway, can you explain how / why you entend to use such script ?

Cheers

Nicolas
All different, all Unix
Jean-Luc Oudart
Honored Contributor

Re: script always run in background

The other possibility is to manage the daemon from /etc/inittab

man inittab

Regards,
Jean-Luc
fiat lux
kholikt
Super Advisor

Re: script always run in background

Actually I expect my script to run in background and wait for some input once it got the input it will process it.
abc
Francisco J. Soler
Honored Contributor

Re: script always run in background

Hi kholikt,
You can get some ideas from /etc/init.d/functions and search for the daemon function.

Frank.
Linux?. Yes, of course.
Matti_Kurkela
Honored Contributor

Re: script always run in background

The last two lines need to be passed into the svrmgrl command. A "here document" ( command <
To make it automatically run itself in the background, you will have to append "&" to the command. You might also have to redirect output of the command somewhere; preferably not /dev/null though, since I think you might one day dearly wish to see what went wrong with "recover managed standby database".

So, something like this:

#!/bin/sh

( svrmgrl connect internal;
recover managed standby database;
EOC ) >/tmp/recover.out 2>&1 &

Now /tmp/recover.out will always have the output of the *latest* run of the script, and only that.
MK