SlackwareThis Forum is for the discussion of Slackware Linux.
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.
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.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Can I put a little script that recall himself after a sleep time in my rc.local file or this will prevent my system from booting?
My script is very simple and should recall himself every 5min of sleep
If I put this in my rc.local, is my system will be able to boot or it will wait for the end of the script forever?
Yeah you don't necessarily need to put a script in the rc.local for this type of job if its not needed at boot time, you can actually have it anywhere you want, setup a cron job to run it whenever needed as acid said.
Herm... What is cron job?
I want to put my script in my iptables script (or near it) because my Ispoften change my Ip but my iptables still use the old ip. The script check every 5min if my ip still the same or not, if not restart iptables, ip-updater,server etc.... (please do not tell me to use interface, It gives me other problems!)
So well... If I add something like ./script & to my rc.local, or in my iptables script, will it work? I fact I want this script to recall himself every 5 min, so I use a sleep command. If you know a better way to do please tell me
(Btw Acid sorry for the double post, I just tried to "export" my problem to another forum because it is not really about Slack but mostly about programming)
herm that was a very bad idea...
If I start the script with & when it recall himself, it recall another script without closing the first one and another and another....
So I have now something like 150 process of this script running and the same number of -bash hehehehe
Anyone know a better way? What if, instead of recalling the same script after the sleep time, I just ask my script to "go to" the first line? (what's the syntax of that btw?)
You asked what cron is... it is a daemon for running tasks at certain times. It allows you to set up tasks that run automatically on certain time intervals. Thus its purpose is to allow you to do things like what you are attempting. Man contrab is a bettter place to look though, man cron might not exsist on your slackware system (I know it doesn't on mine).
There is a howto on cron.
Originally posted by jtshaw Man contrab is a bettter place to look though, man cron might not exsist on your slackware system (I know it doesn't on mine).
Yeah, man cron doesn't exist but it is:
man crontab to clear up anyone that might not realize that was a spelling mistake on jtshaw behalf.
I'd suggest using cron, but here are starter scripts for either cron or a daemon script. These are just examples to get you started, they have not been tested. It's not a good idea to have a script call itself, as you probably figured out.
Daemon script run from rc.local like: ./testInterface &
Code:
#!/bin/sh
LAST_IP=""
while [ 1 ]; do
IP=`ifconfig eth0 \
| grep "inet addr" \
| cut -d":" -f2 \
| awk ' { print $1 }'`
if [ "$IP" != "$LAST_IP" ]; then
if [ "$LAST_IP" = "" ]; then
LAST_IP=$IP
else
echo restart
LAST_IP=""
fi
else
LAST_IP=$IP
fi
sleep 300
done
Code for a script run from Cron every x minutes:
Code:
#!/bin/sh
IP_FILE="/etc/lastip"
if [ -e $IP_FILE ]; then
LAST_IP=`cat $IP_FILE`
fi
IP=`ifconfig eth0 \
| grep "inet addr" \
| cut -d":" -f2 \
| awk ' { print $1 }'`
if [ "$IP" != "$LAST_IP" ]; then
if [ "$LAST_IP" = "" ]; then
echo $IP > $IP_FILE
else
# restart iptables
rm $IP_FILE
fi
else
echo $IP > $IP_FILE
fi
but why THIS : [ "$IP" != "$LAST_IP" ]
I tried without the ! and it works...
and what is #!/bin/sh
I saw it often but I never found any explication about this useless comment.
It says the path of the script auto-run or something like that it is that right?
can I write something to check error msg too? this is not suppose to happen but if my DSL isn't connected when the script start it can't find the right interface so I want to ask my script to restart the dsl in this case.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.