?
Solved

Schedule hourly event to execute .sh - Cron?

Posted on 2000-03-03
12
Medium Priority
?
663 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 5
12 Comments
 
LVL 40

Accepted Solution

by:
jlevie earned 400 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Get MySQL database support online, now!

At Percona’s web store you can order your MySQL database support needs in minutes. No hassles, no fuss, just pick and click. Pay online with a credit card.

Question has a verified solution.

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

Over the last ten+ years I have seen Linux configuration tools come and go. In the early days there was the tried-and-true, all-powerful linuxconf that many thought would remain the one and only Linux configuration tool until the end of times. Well,…
The purpose of this article is to demonstrate how we can use conditional statements using Python.
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.
Suggested Courses
Course of the Month12 days, 13 hours left to enroll

777 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