setting a cron job


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting setting a cron job
# 1  
Old 03-30-2008
Question setting a cron job

Greetings i am a newbie to this so kindly bear with me. I have a script to get weather information from a site and save that into a database.

Code:
wget Cranfield Weather Forecast
temp = $(cat wx.php | grep -o "Temperature.......")
rm wx.php
mysql -D "weather_wise" -e "insert into weather (date,hour,degrees) values (now(),now(),$temp)";

how would i set up a cron job for this given that i want:
0 00-23 * * 0-7 command ?

Last edited by Yogesh Sawant; 03-31-2008 at 12:01 PM.. Reason: added code tags
# 2  
Old 03-31-2008
what is your condition to run the scripts.....e.g. when at what time the scripts needs to invoke.

before that check whether your cron deamon(crond) is running or not, if running setting up cron will not make an issue, if not then try to invoke that one , then set your cron, with absolute path, will work fine.
# 3  
Old 03-31-2008
this would help you
# 4  
Old 04-01-2008
crons

User defined crons have to be created using the command crontab -e

set your cron accordingly

30 14 * * * <your file (eg.sh weather)>
| | | | |_____ Day of the week(0-6)
| | | |_______ Month (1-12)
| | |_________ Day of the Month (1-31)
| |___________ Hour of the Day (0-23)
|______________ Minutes (0-59)

cron start --start your cron
cron stop --stop your cron
# 5  
Old 04-01-2008
I use this header at the top of the crontab file to make it easier when reading.
Code:
#Minute (0-59),
#|      Hour (0-23),
#|      |       Day of the month (1-31),
#|      |       |       Month of the year (1-12),
#|      |       |       |       Day of the week (0-6 with 0=Sunday).
#|      |       |       |       |       Commands
#|      |       |       |       |       |
#-------------------------------------------------------------------------------------------------------

So your crontab will look something like this:
Code:
# sudo crontab -l
#ident  "@(#)root       1.21    04/03/23 SMI"
#
# The root crontab should be used to perform accounting data collection.
#
#
#Minute (0-59),
#|      Hour (0-23),
#|      |       Day of the month (1-31),
#|      |       |       Month of the year (1-12),
#|      |       |       |       Day of the week (0-6 with 0=Sunday).
#|      |       |       |       |       Commands
#|      |       |       |       |       |
#-------------------------------------------------------------------------------------------------------
10      3       *       *       *       /usr/sbin/logadm
15      3       *       *       0       /usr/lib/fs/nfs/nfsfind
30      3       *       *       *       [ -x /usr/lib/gss/gsscred_clean ] && /usr/lib/gss/gsscred_clean

Tornado
# 6  
Old 04-01-2008
0 00-23 * * 0-7

Try 0-6 not 0-7?
# 7  
Old 04-01-2008
https://www.unix.com/shell-programmin...help-wget.html
https://www.unix.com/shell-programmin...sql-table.html

Is that you, or does it just look a lot like you? Is this a homework assignment where all of you were directed to this site for help?

For what it's worth, those threads have more elegant solutions for getting the temperature from the web site. You should avoid using a temporary file, and you should avoid cat file | grep when just grep file works fine.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Cron job - Need to run Cron every quarter at particular time

Hi, 1) If some job supposed to run on 1st of every month at 7 AM In cron job when we have a blackout on the 1st ( i.e when 1st falls on a sunday ) how can we make the job run the next business day? 2) How can we run a job on 25th of every quarter 7 AM(jan,apr,jul,oct) And if 25th... (5 Replies)
Discussion started by: System Admin 77
5 Replies

2. Shell Programming and Scripting

Commented cron job -- cron monitoring

Hi I have a requirement to write a shell script,that will check the all commented job in cron job.Please help !! (2 Replies)
Discussion started by: netdbaind
2 Replies

3. UNIX for Dummies Questions & Answers

Setting up cron

Hi, The client wants to set up cronjob for trigger alerts to be sent between the hours of 6 AM PST and 12 AM PST . Could you please help me the command to setup cron. scriptname :- triggeralert.ksh Thanks in advance (16 Replies)
Discussion started by: kirankumar
16 Replies

4. Solaris

Cron job running even after cron is removed

Hi , I have removed a cron for particular user , but cron job seems to be running even after the cron entry is removed. The purpose of the cron was to sendmail to user ( it uses mailx utility ) I have restarted cron and sendmail service still user is getting mail alerts from the cron job. And... (4 Replies)
Discussion started by: chidori
4 Replies

5. UNIX for Dummies Questions & Answers

Need help setting up a CRON job

Okay I am not the best at UNIX, so please excuse this if it is a complete ID 10-T error (look at that for a moment...) Logging in via telnet to the server, I want to create a cron job to run various "canned reports" in SAS on a regular basis. No problem, I have the directories, .profile... (14 Replies)
Discussion started by: RussellNonBrand
14 Replies

6. UNIX for Dummies Questions & Answers

Setting up More than One Cron Job

Hello, it is possible to setup two cron jobs to run at different frequencies? I have a cron job which runs from monday -friday every 5 mins .I also want to have one more cron job which runs on a sunday.. It it possible to have? Thanks (5 Replies)
Discussion started by: valluvan
5 Replies

7. Solaris

cron job starts new cron proccess

I run cron in solaris 10 zone. One cron job which syncing files to nfs mounted on container, creates after finishing another cron proccess(/usr/sbin/cron), and after 100 existing cron proccesses next cron job will not start. It's too weird for me, I'm not able to solve this problem. Theoretically... (3 Replies)
Discussion started by: ron76
3 Replies

8. UNIX for Dummies Questions & Answers

CRON usage for CRON job

can anybody explain the usage of CRON for adding a cron job. please provide an example also for better understanding !!! Thanks (1 Reply)
Discussion started by: skyineyes
1 Replies

9. Shell Programming and Scripting

cron job setting

hi all I had one script which i had put in /home/name/xxx.sh directory. I want to put it in cron job list means this script must be run on each day at morning 9 am. Kindly reply me all necessary change with exact path detail. Means where i had to do changes. Thanks in adavance. ... (2 Replies)
Discussion started by: jaydeep_sadaria
2 Replies

10. UNIX for Dummies Questions & Answers

setting up cron job for month end week report

Hi all, Needs your help in scheduling a cron job for the below mentioned requirement. Just let me know if anybody has a similar job running as mentioned below: Month end reports - Report of all items created in a parent table that were created during the week. Presently this report runs... (3 Replies)
Discussion started by: Bhups
3 Replies
Login or Register to Ask a Question