Solved

Schedule hourly event to execute .sh - Cron?

Posted on 2000-03-03
12
633 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
 
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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
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

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Join & Write a Comment

In this tutorial I will explain how to make squid prevent malwares in five easy steps: Squid is a caching proxy for the Web supporting HTTP, HTTPS, FTP, and more. It reduces bandwidth and improves response times by caching and reusing frequently-…
How many times have you wanted to quickly do the same thing to a list but found yourself typing it again and again? I first figured out a small time saver with the up arrow to recall the last command but that can only get you so far if you have a bi…
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…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.

747 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

11 Experts available now in Live!

Get 1:1 Help Now