Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game. |
| Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
05-06-2005, 11:20 AM
|
#1
|
|
LQ Newbie
Registered: Jan 2005
Location: Pakistan
Distribution: Red Hat
Posts: 17
Rep:
|
Problems in running a script as a daemon at startup
HI
I want to run a bash script which is as follows at startup:
#!/bin/sh
#
# chkconfig: 345 85 15
# Source function library
. /etc/rc.d/init.d/functions
case "$1" in
start)
echo -n "Starting update: "
daemon update
echo touch /var/lock/subsys/update
lab=1
rm -f /home/exporte/*
rm -f /home/localwork/*
rm -f /home/currentuser/*
#An infinite loop. The problem is somewhere here
while test $lab="1"
do
cp -u /home/localwork/* /home/currentuser
cp -u /home/exporte/* /home/u02062
done
;;
stop)
echo -n "Shutting down update :"
killproc update
echo update
rm -f /var/log/subsys/update
;;
*)
echo "usage: update.init {start|stop}"
exit 1
esac
exit 0
Now after placing this script in /etc/rc.d/init.d and doing chkconfig --add update when i restart the computer, my service update runs.
The problem is that due to the infinite loop that i want to execute in the script, the system doesnt moves forward and no other service is activated and i dont get the logon screen.
Please tell me how can i run this script at startup so that this script is always running on my computer and also the system loads all the service and i am able to do login properly.
|
|
|
|
05-06-2005, 11:44 AM
|
#2
|
|
Member
Registered: Feb 2005
Location: Sunnyvale, CA
Distribution: Ubuntu
Posts: 205
Rep:
|
Hi,
A very simple technique that I have used is to simply code your endless loop functionality into a second script or executable. From within the primary script that is run during init you invoke (execute) the second script as a background program ie "/bin/sh second_script.sh &". This will cause the primary script to fork/exec the secondary script while the primary script runs to completion and terminates properly.
|
|
|
|
05-06-2005, 12:34 PM
|
#3
|
|
Member
Registered: May 2005
Distribution: debian
Posts: 79
Rep:
|
where are you changing the value of $lab? it always seems to be 1 and stuck in the while loop.
|
|
|
|
03-07-2012, 05:38 AM
|
#4
|
|
LQ Newbie
Registered: Mar 2012
Posts: 2
Rep: 
|
Problem in daemon startup script
HI
I have tried to run a startup script as daemon
#!/bin/sh
#
# chkconfig: 345 85 15
# Source function library
. /etc/rc.d/init.d/functions
case "$1" in
start)
echo -n "Starting update: "
daemon update ---->> daemon "test.sh" #This is the script i want to make as daemon
echo touch /var/lock/subsys/update
lab=1
rm -f /home/exporte/*
rm -f /home/localwork/*
rm -f /home/currentuser/*
#An infinite loop. The problem is somewhere here
while test $lab="1"
do
cp -u /home/localwork/* /home/currentuser
cp -u /home/exporte/* /home/u02062
done
;;
stop)
echo -n "Shutting down update :"
killproc update
echo update
rm -f /var/log/subsys/update
;;
*)
echo "usage: update.init {start|stop}"
exit 1
esac
exit 0
THis is not getting converted to a daemon process.Can we provide /etc/init.d/myScript as argument to 'daemon'; or only bindary files can be given.???
|
|
|
|
03-07-2012, 06:25 AM
|
#5
|
|
LQ Newbie
Registered: Mar 2012
Posts: 2
Rep: 
|
Problem in daemon startup script
HI
I have tried to run a bash script as daemon using 'daemon <shell script.sh>'
#!/bin/sh
#
# chkconfig: 345 85 15
# Source function library
. /etc/rc.d/init.d/functions
case "$1" in
start)
echo -n "Starting update: "
daemon "test.sh" #This is the script i want to make as daemon
echo touch /var/lock/subsys/test
lab=1
rm -f /home/exporte/*
rm -f /home/localwork/*
rm -f /home/currentuser/*
#An infinite loop. The problem is somewhere here
while test $lab="1"
do
cp -u /home/localwork/* /home/currentuser
cp -u /home/exporte/* /home/u02062
done
;;
stop)
echo -n "Shutting down test.sh:"
killproc test.sh
echo test.sh
rm -f /var/log/subsys/test
;;
*)
echo "usage: test.sh.init {start|stop}"
exit 1
esac
exit 0
While executing, this is not getting converted to a daemon process.Can we provide /etc/init.d/myScript.sh as argument to 'daemon';
OR only binary files can be given.???
We are observing that the if we try to invoke any binary with 'daemon <binaryName>' it is getting daemonized.
Also if it is invoked with 'daemon <shell script> &', it starts as a daemon process.
Appreciate any help...
Thanks
|
|
|
|
03-07-2012, 07:24 AM
|
#6
|
|
LQ 5k Club
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian Squeeze (server), Slackware 13.37 (netbook), Slackware64 14.0 (desktop),
Posts: 8,357
|
As oblivious69 pointed out in post 3 of this thread, the script never increments $lab so the test $lab="1" is always true (after substitution it is "1=1" which is a non-empty string so always tests true) and the loop never completes.
Even if you changed $lab in the loop it would never exit because the equality operator = must have spaces on either side.
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 12:30 AM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|