Solved

Schedule hourly event to execute .sh - Cron?

Posted on 2000-03-03
12
641 Views
Last Modified: 2013-12-16
Redhat 6.x -

I have a .sh script to update my IP with a dynamic DNS server that I run by hand each time i boot my PC.  I run a PPP connection to the net and IP masq on the same box, so the PPP hangs up once in a while.  I want to be able to, every 30 minutes or so, execute the file dns_update.sh.   I think I need to use Cron to do this, but my Cron knowledge is very lacking.  Could someone help me out with this? Much appreciated.
0
Comment
Question by:kittlej
  • 7
  • 5
12 Comments
 
LVL 40

Accepted Solution

by:
jlevie earned 100 total points
ID: 2581020
Just create a crontab to auto execute it. If you don't need special privs in the script you can use any user account, otherwise pick a user that has the necessary privs. Create the entry with "crontab -e" and add the line:

0,30 * * * * /path-to/dyn-update-script

Any output from what cron executes will be mailed to the user who "owns" the crontab.
0
 
LVL 1

Author Comment

by:kittlej
ID: 2581403
I'm going to hold off on accepting the answer for a moment, as It's good, but I'm still missing a piece of the puzzle.  I understand that Cron is used to schedule, and it stores the schedules in a crontab file, but is there 1 master crontab file for the system, or how are the crontab files organized and "told" to run?  Does each user have a crontab or is it organized another way?


0
 
LVL 1

Author Comment

by:kittlej
ID: 2581412
I'm going to hold off on accepting the answer for a moment, as It's good, but I'm still missing a piece of the puzzle.  I understand that Cron is used to schedule, and it stores the schedules in a crontab file, but is there 1 master crontab file for the system, or how are the crontab files organized and "told" to run?  Does each user have a crontab or is it organized another way?


0
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
LVL 40

Expert Comment

by:jlevie
ID: 2581686
The system does have it's own crontab, typically with a different format. Those files are in /etc/cron*. Each user, can have their own crontab and those get stored in separate files in /var/spool/cron, one per user.
0
 
LVL 1

Author Comment

by:kittlej
ID: 2581702
SO THEN ... the users crontab files get executed when the server boots? or what initiates the users crontab files?
0
 
LVL 40

Expert Comment

by:jlevie
ID: 2582432
The system runs the cron daemon at boot. It scans for crontabs, loads them into memory, and scans each of the crontabs for things to do once a minute. A user's crontab will be scanned and the commands run whether the user is logged in or not (or if root creates the user's crontab, the user doesn't ever need to have logged in).

A variation on cron is the "at" service. This is used to schedule a non-recurring task at a specific time in the future.

The use and operation of cron and at are documented in their respective man pages. You might want to take a look at "man crontab", "man at", and "man cron".
0
 
LVL 1

Author Comment

by:kittlej
ID: 2582600
You da man.  Appreciate the clarification.
0
 
LVL 1

Author Comment

by:kittlej
ID: 2588229
I set it up and it ran as scheduled.. or at least tried to.. It told me in my pine mail "permission denieD".  I added the following line to my crontab

0,30 * * * * /root/dns_update.sh


am I missing something somewhere?


oh. i added that to the root crontab

0
 
LVL 40

Expert Comment

by:jlevie
ID: 2588376
Does /root/dns_update.sh have execute bits set (rwxr-xr-x)? Is the first line on the file "#!/bin/sh"?
0
 
LVL 1

Author Comment

by:kittlej
ID: 2588448
yes to the /bin/sh but no on execute rights.  Who do I need to give execute rights to (I normally just sh dns_update.sh) so that this works? (Can you please tell me the chmod statement to use - im a beginning linux admin who is still a little wet under the ears)
0
 
LVL 40

Expert Comment

by:jlevie
ID: 2588547
I'd see it as a system administration utility. As such I'd make it owned root, group root. I'd give root read/write/execute and everyone else read/execute. You'd do that like:

root> chown root:root /root/dns_update.sh
root> chmod 755 /root/dns_update.sh

The man pages for chown, chgrp, & chmod will tell you a lot more about what you can do with those commands (e.g., "man chown").
0
 
LVL 1

Author Comment

by:kittlej
ID: 2588591
consider it done. Lets see if that works. I'll know in 30 minutes :)
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Remove a folder in Linux 9 103
Choosing CentOS 16 79
Penetration Testing home based work 3 73
awk variable in printf 1 22
Daily system administration tasks often require administrators to connect remote systems. But allowing these remote systems to accept passwords makes these systems vulnerable to the risk of brute-force password guessing attacks. Furthermore there ar…
I am a long time windows user and for me it is normal to have spaces in directory and file names. Changing to Linux I found myself frustrated when I moved my windows data over to my new Linux computer. The problem occurs when at the command line.…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now