LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 10-25-2004, 08:23 AM   #1
nitaish
LQ Newbie
 
Registered: Oct 2003
Posts: 17

Rep: Reputation: 0
Setting a cron


Hello,
I want to setup a cron to run a certain command each hour in my server. I am running a Red Hat 7.2 RPM version. Can somebody tell me how to add the cron.

Thanks
Regards
Nitesh N
 
Old 10-25-2004, 08:33 AM   #2
cadj
Member
 
Registered: Aug 2003
Location: Melbourne Australia
Distribution: Debian Stretch
Posts: 374

Rep: Reputation: 32
i have a script that updates my ad blocking host file once a day, i set cron to run this script at 17:30

to set this cron, i use the command

crontab -e

the file is simple to edit, use the following format

min hour day week month command

so if you want to run /bin/myscript at 17:30

30 17 * * * /bin/myscript

im using debian so im not sure how this works on other distros.


another way is to create an executable script in /etc/cron.hourly , the script may look like

#---------
#!/bin/bash
wget http://someonewhocares.org/hosts/hosts
cat hosts >/etc/hosts
#----

after the script is made, make sure you make it executable with

chmod +x myscript

hope ive been of some help
 
Old 11-01-2004, 08:50 AM   #3
nitaish
LQ Newbie
 
Registered: Oct 2003
Posts: 17

Original Poster
Rep: Reputation: 0
setting up a cron

Hi,
Thanks for the help. I think I am able to understand how to setup a cron a bit. But here I am a little confused. What does the following mean ?

#!/bin/bash

In some cron jobs, I have found that instead of #!/bin/bash, there is #!/bin/sh

What is the difference between the two and what should be used while setting up a daily cron ?

Kindly advise.

Thanks
Regards
Nitaish
 
Old 11-01-2004, 07:42 PM   #4
trickykid
LQ Guru
 
Registered: Jan 2001
Posts: 24,149

Rep: Reputation: 270Reputation: 270Reputation: 270
Re: setting up a cron

Quote:
Originally posted by nitaish
Hi,
Thanks for the help. I think I am able to understand how to setup a cron a bit. But here I am a little confused. What does the following mean ?

#!/bin/bash

In some cron jobs, I have found that instead of #!/bin/bash, there is #!/bin/sh

What is the difference between the two and what should be used while setting up a daily cron ?

Kindly advise.

Thanks
Regards
Nitaish
That's the shell it uses to execute the commands. Most or some Linux distros just have sh point to bash. bash is a enhanced version of sh.
 
Old 11-01-2004, 08:16 PM   #5
cadj
Member
 
Registered: Aug 2003
Location: Melbourne Australia
Distribution: Debian Stretch
Posts: 374

Rep: Reputation: 32
its so the system knows how to execute the script, eg at the top of my perl scripts i put

#!/usr/bin/perl

which tels the system to run the script with perl
 
Old 11-03-2004, 01:15 AM   #6
nitaish
LQ Newbie
 
Registered: Oct 2003
Posts: 17

Original Poster
Rep: Reputation: 0
Hi Folks,
Thanks for the help. I have installed qmHandle in the server and have setup a cron which runs daily. It looks something like this

#############

#!/bin/bash

<command>

#############

I want to know if the cron is running properly. Can I write a script which will write the output of the result in a text file when the cron runs successfully? If yes, then how do I write it ? Kindly suggest.

Thanks
Regards
Nitaish
 
Old 11-03-2004, 07:43 AM   #7
cadj
Member
 
Registered: Aug 2003
Location: Melbourne Australia
Distribution: Debian Stretch
Posts: 374

Rep: Reputation: 32
to test mine, i had it running on an hourly basis

write a script "test" and put it in your / dir

#!/bin/bash
echo the cron has worked >/cron.test

and make sure its executable by

chmod +x test

then in your crontab

1 * * * * /test

every one min it should make a file cron.test in your / dir
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Setting a cron task in a script Slith(++1) Programming 3 11-21-2005 04:17 AM
problem in cron job setting gauravdream Linux - General 1 02-23-2004 12:08 AM
Selfhost Domain Service (Setting up a cron job) ASP Linux - Newbie 3 12-02-2003 12:49 AM
need help setting up a cron job !! J.I.L. Linux - Software 1 10-19-2003 08:54 PM
Setting cron by php code? VertiHost Programming 1 10-15-2003 06:41 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 06:48 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration