Results 1 to 6 of 6
Hi,
I need some help figuring out what I need to do here
I have made a shell script that is ran every 5 minutes (using crontab) that does the ...
- 06-03-2010 #1Just Joined!
- Join Date
- Jun 2010
- Posts
- 4
[SOLVED] Anyway to start a cron job from runlevels?
Hi,
I need some help figuring out what I need to do here
I have made a shell script that is ran every 5 minutes (using crontab) that does the following:
(please disregard the '.' in ht.tp .. I'm under 15 post...can't post URLs yet
)
(this script might look pretty bad but hey, it's my first one!)Code:#!/bin/bash wget -q --read-timeout=0.0 --wait=5 --tries=5 -O /var/log/dynamicDNS.data ht.tp://someURL echo "[$(date)] $(cat /var/log/dynamicDNS.data)" >>/var/log/dynamicDNS.log rm /var/log/dynamicDNS.data >/dev/null exit 0
That works perfectly! Though, I need to have this "cron" run from startup (boot) without the need to open a terminal and leave it open.
I understand I can use runlevels to start a program from boot but that will have it run only once.
I have thought of the following script(launched using the "&" at defaults runlevel):
(pseudo code)
but I want to avoid this at all cost for obvious reasons.Code:loop: wget options ht.tp://someURL sleep(5 minutes) goto loop
I am sure Linux can offer me a very easy way to achieve what I wish to do here but I just don't know where to look at anymore.
Any help is appreciated,
Regards,
Daniel
- 06-04-2010 #2
I think you need to wait for networking to start before wget will work & I don't think you want it to be a cron job unless it's going to run on a set time schedule.
source: ahinc.com/linux101/loginout.htm#scriptsLogin Scripts
Behind the scenes, when you login, the following shell scripts are executed. They are used to set environment variables and system settings.
/etc/profile
* This is the first script that is executed.
* This script is used to set global parameters that are common to all users.
/home/<username>/.profile
* This is the next script that is normally executed.
* Most likely the contents of this file will be the same for all users.
* It can be changed to set unique parameters for each user.
about runlevels:
wiki.debian.org/RunLevel
comptechdoc.org/os/linux/howlinuxworks/linux_hlrunscripts.html
================================================== ===
DynDNS Update Script:
brandonhutchinson.com/DynDNS_update_script.html
- 06-04-2010 #3Just Joined!
- Join Date
- Jun 2010
- Posts
- 4
Thanks for the quick response dmk06 and also thanks for this information.
Basically, what I understand is that I need to create a daemon and start it at a runlevel higher than "network initialization" or at least, higher than the level needed to run wget.
I checked the DynDNS script you linked but it simply looks too complex for my tiny needs and beside, I'm using a different service than DynDNS.
I would like to avoid having a daemon running in the background for this kind of task. I will continue my search and post more info as I found them.
Meanwhile, if anyone has any info that could help me achieve what i'm trying to, please let me know,
for now, i'm using cron --> to run my script at every 5 minutes intervals
Regards,
Daniel
- 06-07-2010 #4
Sorry, I'm not an expert on the subject...
sourceforge.net/apps/trac/ddclient]ddclient
-OR-Introduction
DDclient is a Perl client used to update dynamic DNS entries for accounts on Dynamic DNS Network Services' free DNS service. It was originally written by Paul Burry and is now maintained by developers for ddclient on sourceforge. It has the capability to update more than just dyndns and it can fetch your WAN-ipaddress in a few different ways. Check the configuration pages to find how to do this. [.....]
sourceforge.net/apps/trac/ddclient]ddclient
If you edit one of the above it will execute it at login (either for specific user or all users depending on what you want) and if it's set to update in cron every 5mins then I think you're set.Login Scripts
Behind the scenes, when you login, the following shell scripts are executed. They are used to set environment variables and system settings.
/etc/profile
* This is the first script that is executed.
* This script is used to set global parameters that are common to all users.
/home/<username>/.profile
* This is the next script that is normally executed.
* Most likely the contents of this file will be the same for all users.
* It can be changed to set unique parameters for each user.
-OR-
Below is a quote from the wget manual for startup files....
source: gnu.org/software/wget/manual/html_node/Startup-File.html6 Startup File
Once you know how to change default settings of Wget through command line arguments, you may wish to make some of those settings permanent. You can do that in a convenient way by creating the Wget startup file—.wgetrc.
Besides .wgetrc is the “main” initialization file, it is convenient to have a special facility for storing passwords. Thus Wget reads and interprets the contents of $HOME/.netrc, if it finds it. You can find .netrc format in your system manuals.
Wget reads .wgetrc upon startup, recognizing a limited set of commands.
* Wgetrc Location: Location of various wgetrc files.
* Wgetrc Syntax: Syntax of wgetrc.
* Wgetrc Commands: List of available commands.
* Sample Wgetrc: A wgetrc example.
Hope this helps
- 06-07-2010 #5Just Joined!
- Join Date
- Jun 2010
- Posts
- 4
Thanks dmk06 for your help
I learned some valuable things from the informations you posted.
I did some testing during the weekend and noticed that cron under root account were executed from startup. I don't really know why though. All I know is that the cron job I set under the root account are executed at startup. Once the system is loaded, the root cron jobs are being executed.
I noticed the cron service is being started during the system loading but now i'm wondering, are cron jobs executed even though the user is not logged on or is this a 'special case' with the root account... This is the next test i'm going to perform.
My problem is solved but now I need to understand why
I'll try to find the answer to this question and post it before making this post as solved.
Regards,
Daniel
- 06-07-2010 #6Just Joined!
- Join Date
- Jun 2010
- Posts
- 4
Ok, I did more testing and found the exact information I was searching for.
First, the tests:
cron jobs are executed even though the user is not logged on. They are executed just as if he was.
Now, the 'exact' information I was searching for:
The therm used in Linux/Unix for this is "system-wide cron jobs". I found out that there is a system-wide crontab and this is were I should launched my script from.
[System-wide crontab]
This crontab in found under /etc/crontab. Unlike other crontab that need to be edited via crontab -e, this crontab is directly edited via a text editor. (ht.tp://ww.w.geekcomix.com/cgi-bin/classnotes/wiki.pl?UNIX01/System_Wide_Cronjobs) <== sorry for the malformed url, can't post urls yet
Regards,
Daniel



