Solved

Schedule hourly event to execute .sh - Cron?

Posted on 2000-03-03
12
654 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 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
Industry Leaders: 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
what do I need to host my own web sites? 13 85
Ubuntu don’t allow SU command in terminal 7 121
VPN, Squid-  unable to log https requests 5 107
linux convert text file to PDF 7 69
Using 'screen' for session sharing, The Simple Edition Step 1: user starts session with command: screen Step 2: other user (logged in with same user account) connects with command: screen -x Done. Both users are connected to the same CLI sessio…
Setting up Secure Ubuntu server on VMware 1.      Insert the Ubuntu Server distribution CD or attach the ISO of the CD which is in the “Datastore”. Note that it is important to install the x64 edition on servers, not the X86 editions. 2.      Power on th…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
Suggested Courses

734 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