Solved

Schedule hourly event to execute .sh - Cron?

Posted on 2000-03-03
12
637 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
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 
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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

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-…
Introduction We as admins face situation where we need to redirect websites to another. This may be required as a part of an upgrade keeping the old URL but website should be served from new URL. This document would brief you on different ways ca…
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.

863 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

23 Experts available now in Live!

Get 1:1 Help Now