[NTLUG:Discuss] Script help
Eric Schnoebelen
eric at cirr.com
Tue Sep 14 23:03:28 CDT 2010
Fred writes:
- I am somewhat embarassed because I can't remember how to do this:
-
- I wrote a little script that works just fine when I invoke it manually
- but when I put it into the /etc/init.d startup scrip "local" (where I have
- other misc scripts) it refuses to start... or continue to run after the
- rc5.d quits, or whatever. Bottom line is that when I do a ps -ef |grep
- <scriptname>
- it is not running.
-
- The script:
-
#!/bin/sh # always specify the interpreter to be used.
- #########################################
- #
- # pingtest
- #
- # A network test tool
- #
Need to explicitly set PATH!
PATH=/usr/bin:/bin:/usr/sbin:/sbin:/etc
# maybe /usr/local/{s,}bin as well?
# /etc probably isn't needed, but on older systems, ping was in /etc
Probably need to set a trap, since some inits will try to kill
everything that is directly a child when the script exits.
trap : INT HUP QUIT TERM
- LOG=/etc/netup.log
-
- while true
- do
- date >> $LOG
-
- # ping -c1 199.2.252.10 >> $LOG
-
- count=$(ping -c1 199.2.252.10 | grep 'received' | awk -F',' '{ prin
- t $2
- }' | awk '{ print $1 }')
Ugh, two awk invocations and one grep, where a single awk will
do..
count=$(ping -c1 199.2.252.10 | awk -F',' '/received/ { split($2, a, / /); print a[2]}')
- if [ $count -eq 0 ]; then
- # 100% failed
- echo "Net down" >> $LOG
- fi
-
- sleep 60
- done
-
- -------------------
-
- Entry in my /etc/init.d/local:
-
- /etc/pingtest &
- (I have tried several different invocations, all with the same result)
Try "nohup /etc/pingtest"
That will do some signal catching, perhaps keeping init from
killing the "rogue" start up script..
--
Eric Schnoebelen eric at cirr.com http://www.cirr.com
"The universe is not only stranger than we imagine, it is stranger
than we can imagine." -J. B. S. Haldane
More information about the Discuss
mailing list