The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
cron tab setting Kbharat20 SUN Solaris 1 05-16-2008 08:48 PM
cron job setting jaydeep_sadaria Shell Programming and Scripting 2 11-21-2007 06:07 AM
Listing and setting up cron jobs NycUnxer UNIX for Dummies Questions & Answers 3 11-08-2007 05:45 PM
Setting environment variables within cron jobs!! atheek SUN Solaris 1 10-09-2006 04:26 AM
Cron not retaining TERM setting steelrose UNIX for Dummies Questions & Answers 2 10-14-2005 11:01 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 03-30-2008
Registered User
 

Join Date: Mar 2008
Posts: 1
Stumble this Post!
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 08:01 AM. Reason: added code tags
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 03-31-2008
manas_ranjan's Avatar
Registered User
 

Join Date: Jul 2007
Location: PUNE
Posts: 157
Stumble this Post!
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.
Reply With Quote
  #3 (permalink)  
Old 03-31-2008
Yogesh Sawant's Avatar
Part Time Moderator and Full Time Dad
 

Join Date: Sep 2006
Location: Rossem, Tazenda
Posts: 767
Stumble this Post!
this would help you
Reply With Quote
  #4 (permalink)  
Old 03-31-2008
Registered User
 

Join Date: Mar 2008
Posts: 8
Stumble this Post!
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
Reply With Quote
  #5 (permalink)  
Old 03-31-2008
Tornado's Avatar
Registered User
 

Join Date: Nov 2006
Location: Melbourne
Posts: 240
Stumble this Post!
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
Reply With Quote
  #6 (permalink)  
Old 03-31-2008
Registered User
 

Join Date: Mar 2008
Posts: 2
Stumble this Post!
0 00-23 * * 0-7

Try 0-6 not 0-7?
Reply With Quote
  #7 (permalink)  
Old 03-31-2008
era era is offline
Herder of Useless Cats
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,650
Stumble this Post!
Help with wget
Help Inserting data in mysql table

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.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Tags
cron, wget

Thread Tools
Display Modes




All times are GMT -7. The time now is 11:44 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0