LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Timed Script (https://www.linuxquestions.org/questions/programming-9/timed-script-198953/)

rridler 06-28-2004 11:58 PM

Timed Script
 
I have a little problem.
I need to run an ipcheck script 5 - 10 seconds after all other operations are done and the firewall script has run.
Also, it needs to be run every 20 minutes or so to keep my dynamic host IP address updated. This at the suggestion of my ISP. They have a very short lease on the IP that they assign.
Anyone have a way to do this?

Ridler

:Pengy: :scratch:

btmiller 06-29-2004 12:43 AM

Something like this maybe:

#!/bin/bash

# do all the setup stuff you need to do
sleep 5

# slept 5 seconds, run IP check
ipcheck whatever

# now run every 20 minutes more or less -- this isn't exact thanks to
# the vagarities of kernel scheduling, but it should be close enough
while true
do
ipcheck whatever
sleep 20*60 # 20 minutes
done

rridler 06-29-2004 02:22 PM

Will this continue to loop?

Ridler :scratch:

jim mcnamara 06-29-2004 03:07 PM

Yes it will. It will abort on error.

rridler 06-30-2004 01:08 AM

I created the script like you outlined and it loops like I want it to, but I ran into a problem.
It will not give the OS control of the computer, it stays in a continous loop of the script and never completes the boot process.

What needs to be done now?

Ridler :scratch:

Hko 06-30-2004 11:55 AM

Another solution:
Have you firewall script touch /tmp/__my_firewall (yes, in /tmp because when the system reboots it will be deleted usually). Than make the ipcheck-script test if /tmp/__my_firewall, and only if the file exists actually do the ip-check. Then put your script in /etc/crontab to have run every 20 minutes.

rridler 06-30-2004 02:35 PM

I do have a firewall script (fw3) and it is called from the /etc/rc.d/rc.local, it runs before the ipcheck script (ipcheck) also in the /etc/rc.d/rc.local.
Is there a better way to call this script, so that it loops and also allows complete booting of the OS?

Ridler :scratch:

Hko 07-01-2004 07:31 AM

Like I mentioned before: call it from /etc/crontab
See "man cron" and "man crontab".

cck23 07-01-2004 09:09 AM

Hko's suggestion should work but you could also run the script with the command:

script_file.sh & (note: & at the end)

The rc scripts will run it in the background and carry on with the rest of the boot process. But having said that, cron is better as something could kill your background process accidentally, make your choice.

Hko 07-01-2004 06:29 PM

Quote:

Hko's suggestion should work but you could also run the script with the command:

script_file.sh & (note: & at the end)
That's true. Maybe even better:
Code:

nohup script_file.sh >/dev/null 2>&1&
Quote:

cron is better as something could kill your background process accidentally, make your choice.
I think my suggestion with "nohup" will also prevent that. Myself I'd still prefer the cron way though.

rridler 07-01-2004 10:52 PM

I have used "crontab" and it does seem to be working, but it needs to run for the first time 5 - 10 seconds after startup too.


ipcheck.sh

or

nohup ipcheck.sh >/dev/null 2>&1&


I am not sure I am following the process correctly.

Ridler :scratch:


All times are GMT -5. The time now is 02:06 PM.