LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
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 07-14-2004, 02:37 AM   #1
sanjith11
Member
 
Registered: Oct 2003
Distribution: redhat
Posts: 63

Rep: Reputation: 15
cron job


hello,

How can i set a cron job which runs every 5th minute from monday to friday and which stops during 7 pm to 7 am.


regards
SaN
 
Old 07-14-2004, 03:19 AM   #2
p8080
LQ Newbie
 
Registered: Oct 2003
Location: Wolverhampton
Distribution: Suse
Posts: 26

Rep: Reputation: 15
you need to put the line :
0,5,10,15,20,25,30,35,40,45,50,55 7,8,9,10,11,12,13,14,15,16,17,18,19 * * 1,2,3,4,5 /command
into your crontab file.
 
Old 07-14-2004, 03:22 AM   #3
fluppi
Member
 
Registered: Oct 2003
Location: Switzerland (Europe)
Distribution: OpenSuSE, RedHat, Knoppix, IRIX + MacOSX
Posts: 198

Rep: Reputation: 31
By edit your crontab:
crontab -e
(Warning: vi-mode, you can leave without changes by ESC :q!)

# Minute0-59 Hour0-23 Day1-31 Mont1-12 Weekday0-7 Command
/5 7-19 * * 1-5 ls >> /tmp/ls.txt


This will run every 5 Minutes an "ls" and append the output at the end of /tmp/ls.txt , but not all can understand "/5", then use "5,10,15,..."
Check is the owner of the crontab (=the user you edited with) has the permissions to do that.

Hth
Fluppi
 
Old 07-14-2004, 05:49 AM   #4
sanjith11
Member
 
Registered: Oct 2003
Distribution: redhat
Posts: 63

Original Poster
Rep: Reputation: 15
My script dosent work when i run it as a cron job.
this works when run from the shell.

what might be the reason it is soo.

the script jus redirects a commands output to a file .it the serches the file for a pattern usin grep and execute some commands if the pattern is found.



cd /take/to/the/directory
. ./test.1>test_out
. ./test.2>>test_out
grep -q "somethin" test_out
s1=$?
if [ $s1 -eq 0 ]
then
echo
#echo "test.1---------successful"
else
mailx -s "obj Down" x@w.com<test_out
fi

grep -q "somethin_agen" test_out
s2=$?
if [ $s2 -eq 0 ]
then
echo
#echo "test.2---------successful"
else
mailx -s "obj 2 don" x@w.com<test_out
fi

*test.1 and test.2 are properly working scripts

Last edited by sanjith11; 07-14-2004 at 06:34 AM.
 
Old 07-14-2004, 09:43 AM   #5
fluppi
Member
 
Registered: Oct 2003
Location: Switzerland (Europe)
Distribution: OpenSuSE, RedHat, Knoppix, IRIX + MacOSX
Posts: 198

Rep: Reputation: 31
How do you call it in the crontab ( /take/to/the/directory/test.1> test_out ) ?

It's better to use crontab just to call other scripts, without any parameters (it may work, but not on all plattforms).
You can direct the output of a script in itself by "exec >> /var/xyz.log".
 
Old 07-14-2004, 01:06 PM   #6
Blinker_Fluid
Member
 
Registered: Jul 2003
Location: Clinging to my guns and religion.
Posts: 683

Rep: Reputation: 63
Quote:
Originally posted by sanjith11
My script dosent work when i run it as a cron job.
this works when run from the shell.

what might be the reason it is soo.

the script jus redirects a commands output to a file .it the serches the file for a pattern usin grep and execute some commands if the pattern is found.



cd /take/to/the/directory
. ./test.1>test_out
. ./test.2>>test_out
grep -q "somethin" test_out
s1=$?
if [ $s1 -eq 0 ]
then
echo
#echo "test.1---------successful"
else
mailx -s "obj Down" x@w.com<test_out
fi

grep -q "somethin_agen" test_out
s2=$?
if [ $s2 -eq 0 ]
then
echo
#echo "test.2---------successful"
else
mailx -s "obj 2 don" x@w.com<test_out
fi

*test.1 and test.2 are properly working scripts
I would say it's because you aren't using complete path names. Also check the test.1 and test.2 and make sure they have full pathnames.
I would change the scripts to something like this:

###########################################
/take/to/the/directory/test.1 > /take/to/the/directory/test_out
/take/to/the/directory/test.2 >> /take/to/the/directory/test_out
grep -q "somethin" /take/to/the/directory/test_out
s1=$?
if [ $s1 -eq 0 ]
then
echo
#echo "test.1---------successful"
else
mailx -s "obj Down" x@w.com< /take/to/the/directory/test_out
fi

grep -q "somethin_agen" /take/to/the/directory/test_out
s2=$?
if [ $s2 -eq 0 ]
then
echo
#echo "test.2---------successful"
else
mailx -s "obj 2 don" x@w.com< /take/to/the/directory/test_out
fi
###########################################
 
  


Reply



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
Cron Job petenyce Linux - Newbie 5 10-11-2005 04:03 PM
cron job working2hard Programming 6 07-28-2004 09:12 PM
cron job ? johnyy Linux - Software 3 12-10-2003 06:00 PM
Cron Job imanahmadi Linux - Newbie 1 07-03-2003 11:39 PM
cron job? luap Linux - Software 2 03-16-2003 08:48 AM

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

All times are GMT -5. The time now is 12:30 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