LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices


Reply
  Search this Thread
Old 06-02-2002, 02:32 AM   #1
Half_Elf
LQ Guru
 
Registered: Sep 2001
Location: Montreal, Canada
Distribution: Slackware; Debian; Gentoo...
Posts: 2,163

Rep: Reputation: 46
Rc.Local


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?
 
Old 06-02-2002, 02:55 AM   #2
sakeeb
Member
 
Registered: Apr 2002
Posts: 270

Rep: Reputation: 31
i think the it will stop your system from booting if you are using sleep command.
 
Old 06-02-2002, 09:47 AM   #3
Half_Elf
LQ Guru
 
Registered: Sep 2001
Location: Montreal, Canada
Distribution: Slackware; Debian; Gentoo...
Posts: 2,163

Original Poster
Rep: Reputation: 46
arrr... ok
Is there are any other way to do?
Can I use something else instead of a sleep that will not stop my system? Or can I put it somewhere else?

Last edited by Half_Elf; 06-02-2002 at 09:56 AM.
 
Old 06-02-2002, 10:12 AM   #4
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
put the scipt in a fiel and fork it into the background:

script &

that's how to solve your problem, but it's a very bad solution to a trivial task. you'd be better off setting a cron job or something similar.
 
Old 06-02-2002, 11:39 AM   #5
trickykid
LQ Guru
 
Registered: Jan 2001
Posts: 24,149

Rep: Reputation: 269Reputation: 269Reputation: 269
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.
 
Old 06-02-2002, 04:59 PM   #6
Half_Elf
LQ Guru
 
Registered: Sep 2001
Location: Montreal, Canada
Distribution: Slackware; Debian; Gentoo...
Posts: 2,163

Original Poster
Rep: Reputation: 46
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)
 
Old 06-02-2002, 05:27 PM   #7
Half_Elf
LQ Guru
 
Registered: Sep 2001
Location: Montreal, Canada
Distribution: Slackware; Debian; Gentoo...
Posts: 2,163

Original Poster
Rep: Reputation: 46
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?)

Last edited by Half_Elf; 06-02-2002 at 05:29 PM.
 
Old 06-02-2002, 05:44 PM   #8
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
"Anyone know a better way?"

YES.

A
CRON
JOB

man cron.
 
Old 06-02-2002, 10:31 PM   #9
jtshaw
Senior Member
 
Registered: Nov 2000
Location: Seattle, WA USA
Distribution: Ubuntu @ Home, RHEL @ Work
Posts: 3,892
Blog Entries: 1

Rep: Reputation: 67
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.
 
Old 06-02-2002, 10:56 PM   #10
Half_Elf
LQ Guru
 
Registered: Sep 2001
Location: Montreal, Canada
Distribution: Slackware; Debian; Gentoo...
Posts: 2,163

Original Poster
Rep: Reputation: 46
Thanx, jtshaw, I will look at this.
 
Old 06-02-2002, 11:24 PM   #11
trickykid
LQ Guru
 
Registered: Jan 2001
Posts: 24,149

Rep: Reputation: 269Reputation: 269Reputation: 269
Quote:
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.
 
Old 06-03-2002, 09:49 AM   #12
jtshaw
Senior Member
 
Registered: Nov 2000
Location: Seattle, WA USA
Distribution: Ubuntu @ Home, RHEL @ Work
Posts: 3,892
Blog Entries: 1

Rep: Reputation: 67
....opps People keep telling me to read my own posts.....
 
Old 06-04-2002, 08:47 PM   #13
crabboy
Senior Member
 
Registered: Feb 2001
Location: Atlanta, GA
Distribution: Slackware
Posts: 1,821

Rep: Reputation: 121Reputation: 121
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
 
Old 06-05-2002, 12:09 AM   #14
Half_Elf
LQ Guru
 
Registered: Sep 2001
Location: Montreal, Canada
Distribution: Slackware; Debian; Gentoo...
Posts: 2,163

Original Poster
Rep: Reputation: 46
Hum these script are really better than mine

Using a loop is a good idea too I will try it

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.
 
Old 06-05-2002, 03:49 AM   #15
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
!= means not equal to. so obiovusly just removing the ! will make it WRONG

#!/bin/sh defines the interpreter, normal shell in this case, could be perl or a load of others
 
  


Reply



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
Setup local machine to allow lan machines to retrieve its local user mail. Brian1 Linux - Networking 3 03-30-2006 05:04 AM
Local webserver -- How to deny all client install their local web server--Please help b:z Linux - Networking 13 04-16-2005 07:11 PM
Regarding rc.local subaruwrx Linux - Newbie 11 10-11-2004 08:04 AM
where's my rc.local TheChicken Linux - Newbie 4 04-05-2004 01:38 PM
Cannot resolve local addresses on local network danielgrenyer Linux - Networking 6 01-14-2004 11:03 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware

All times are GMT -5. The time now is 07:02 AM.

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
Open Source Consulting | Domain Registration