run a shellscript in background after startup


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting run a shellscript in background after startup
# 1  
Old 07-15-2010
run a shellscript in background after startup

hi.

i need to start a shellscript AFTER full system startup

the script will then run permanently in a loop checking the server every minute and in case of major hangs it just reboots the machine.

i put it into /etc/rc.local file like this:
Code:
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.

/checkerscript1 &
/checkerscript2 &

exit 0


now this works, but when i check running processes with "top" i see multiple instances of the script running,
which is definitely not what i want.

how can i start a script correctly after full system startup???


thanks for any answers!
# 2  
Old 07-15-2010
Can you post the scripts? What you show so far will not cause multiple running copies. Maybe the script calls itself?
# 3  
Old 07-15-2010
yeah, the script calls itself.
then thats the problem.

now i call the script itself with a & at the end and it works fine now.

thanks sir, great help

Last edited by scarfake; 07-15-2010 at 03:00 PM..
# 4  
Old 07-15-2010
Sorry, without knowing what the script is going to do it would be pure guesswork how best to start the script. It is also usual to build in a means of stopping a background process.
# 5  
Old 07-15-2010
well the script does this:

it fetches a small textfile from the local running webserver via curl
if the webserver doesnt respond within 15 seconds the script restarts the webserver.

Code:
sleep 120
xxx=`curl -m 15 http://localhost/online.txt`
if [ $xxx == online ]
then
echo running
else
apache2ctl restart
fi
/webservercheck &


works fine now.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to find the shellscript which is running In background is completed or not?

HI All, I need the answer of below question? 1) how to find the shellscript which is running In background is completed or not ? ex: I know the shellscript name abc.sh which is running in background through cronjob. I want to know this is job is still running or stopped, how to... (3 Replies)
Discussion started by: pspriyanka
3 Replies

2. Solaris

run a service via startup script (correct me if I am wrong)

Environment Solaris 9 I have configured the Solaris9 as NTP client in which Solaris9 is syncing the time with a windows2008 R2 Server which is runing fine. Now I want that the xntpd service should start at startup. I did this via a script. Kindly correct if I did any thing wrong: 1.)Made... (9 Replies)
Discussion started by: z_haseeb
9 Replies

3. Shell Programming and Scripting

Run application at startup

We have a Windows Service written in C# ported over to linux using Mono Develop... The code is working 100% when we run a script file which runs the exe... but we want the application to run at startup.... The application gathers info of the computer eg. Hard Disk Space etc... And compress it into... (1 Reply)
Discussion started by: yodzaan
1 Replies

4. AIX

Run script with different user at the startup ..

Run script with different user at the startup .. I have created this user appuser And I have a script should to be up thru the startup by this user appuser I have defined the path of the script /user/appstart.sh in /etc/rc But at the startup starting will be by root , I’d like to keep... (6 Replies)
Discussion started by: Mr.AIX
6 Replies

5. SuSE

Unable to Run a script at startup in suse

Hi I have a script myscript.sh that needs to be run whenever the server boots. The script is actually logging Syslog-ng messages to sql server. I need to lauch it at startup I have copied the script in etc/init.d i have also added the link ln -s /etc/init.d/syslog-ng-mssql-pipe.sh... (5 Replies)
Discussion started by: SystemEng
5 Replies

6. UNIX for Dummies Questions & Answers

run a script at startup

hi, i am using rhel 5, and i wanna run a script as soon as the operating system open. How can i do this ? ( i was reading rc.d files but i could not understand exactly what are the run levels and where should i put the my shell script. my script will be : #!/bin/ksh iptables -I INPUT... (1 Reply)
Discussion started by: futi
1 Replies

7. Shell Programming and Scripting

Need to run script at startup.

Hi guys , I Need to run a specific command (pinging a particular machine). Which need to run every time i reboot the server till the time it shut down. What is the preferred way of doing this. Will it impact my system performance. My Operating system is as below. # lsb_release -a... (3 Replies)
Discussion started by: pinga123
3 Replies

8. AIX

run script at startup

I am using AIX 5.3 in P6 machine. I have a script "test.sh", when i run it manually it runs properly. I want to run the script automatically when system starts. I kept the script in /etc/rc.d/init.d and also in /etc/rc.d/rc2.d but it is not working. Do i have to write it in inittab instead of... (1 Reply)
Discussion started by: pchangba1
1 Replies

9. Linux

Run a script during reboot/startup

Hi all, i have a script in /etc/init.d directory. -rwxr-xr-x 1 root root 26 Mar 28 16:00 myscript I need it to run when my linux reboots/startup. However is it not being executed. Do i need to put in in the rc.local directory? (1 Reply)
Discussion started by: new2ss
1 Replies

10. UNIX for Dummies Questions & Answers

Run tomcat at startup

Is it possible to run tomcat automatically when Linux boots without having to log in? (4 Replies)
Discussion started by: Spetnik
4 Replies
Login or Register to Ask a Question