LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 07-02-2007, 08:19 AM   #1
falloutboy205
LQ Newbie
 
Registered: Jul 2006
Posts: 2

Rep: Reputation: 0
running script as daemon at boot


Hi,

I am trying to run a script as a daemon at boot that creates a vpn connection and then has an infinite loop that checks its still working every 3 mins. It looks like this:

Code:
#!/bin/bash
# start vpnc
vpnc /home/ol/uni.conf > /dev/null &
#loop runs forever and checks the vpn connection every 3 mins
while true; do 
	
	string=$(ping -w 4 vpn2.shef.ac.uk | grep 'packet loss')
	
	sleep 180
	if   [[ -z $string || $string = "*unreachable*" ]] ; then 	
		vpnc-disconnect
		killall vpnc
		killall dhclient
		dhclient eth0
		vpnc /home/ol/uni.conf > /dev/null &
	fi
done
It is saved as vpn and I have a script in /etc/init.d to start it:

Code:
#!/bin/bash
#
# hopefully starts vpn script from /usr/local/bin
#
#chkconfig: 345 99 1
#description: vpn
#
# Source function library.
. /etc/rc.d/init.d/functions


RETVAL=0

start() {
    echo -n $"Starting vpn daemon: "
    daemon /usr/local/bin/vpn
    RETVAL=$?
    echo
    return $RETVAL 
    
}

stop() {
    echo -n $"Stopping vpn daemon: "
    killproc vpn -TERM
    RETVAL=$?
    echo
    return $RETVAL
}

# See how we were called.
case "$1" in
    start)
        start
        ;;
    stop)
        stop
        ;;
    restart)
        stop
	sleep 3
        start
        ;;

    *)
        echo $"Usage: $0 {start|stop|restart}"
        exit 1
esac
exit $RETVAL
I made the last one by copying bits from other init scripts so it may well be the problem!

Anyway, when I reboot my machine or do service vpn start it just hangs forever and I don't know why.

Any help appreciated, I've spent all morning trying to work out whats wrong
 
Old 07-02-2007, 08:35 AM   #2
fayez
Member
 
Registered: Aug 2004
Location: Amman
Distribution: Red Hat
Posts: 50

Rep: Reputation: 15
You have to call your script as

daemon /usr/local/bin/vpn &

in the /etc/init.d file.
you forgot to add '&' at the end of the line...
 
Old 07-02-2007, 08:46 AM   #3
falloutboy205
LQ Newbie
 
Registered: Jul 2006
Posts: 2

Original Poster
Rep: Reputation: 0
yup, that would seem to do it...
Thanks
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Problems in running a script as a daemon at startup fahad26 Programming 5 03-07-2012 08:24 AM
bash script running as daemon Satriani Programming 12 03-29-2011 06:23 PM
Running a script on boot Brynn Linux - Software 3 08-04-2006 09:09 AM
Running script as daemon StinkyFinger Linux - Newbie 2 08-28-2003 08:31 PM
how can I get/make a proper squid daemon startup script for boot time binkybuckle Debian 0 07-05-2003 08:58 PM


All times are GMT -5. The time now is 10:56 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration