LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-19-2009, 11:33 AM   #1
Raghu140
LQ Newbie
 
Registered: Oct 2009
Posts: 20

Rep: Reputation: 0
Question Problem In Scheduling with Crontab on RHEL 4


Hi,

I am Scheduling a Shell Script using Crontab. But its not working.

The Scripts actually deletes files after 12:00 PM at night that has been
created during day time.

Shell Scripts is :-

File name- delete_old.sh

#! /bin/bash

cd /home/52222Setup/Check

day=`date | cut -d" " -f3`

for var in `ls -lh | awk '{print $6 " " $9 " " $7}' |grep -v " "$day | cut -d " " -f 2`

do

if [ "$var" == "delete_old.sh" ]

then

echo $var Not Deleted

else

if [ "$var" == "dt.sh" ]

then

echo $var



else

echo $var

rm -f $var

fi

fi

done


I have scheduled it using following command in crontab

@daily /home/52222Setup/Check/delete_old.sh >dev/null &

or

*/1 * * * * /home/52222Setup/Check/delete_old.sh >dev/null &


But it is not deleting files. I have noticed that crontab calls the scripts
but it does not delete the file. Nothing is printed in spool mails as well.

When i run this script manually, it works fine.

Please help.

Regards,

Raghuvendra Kumar
 
Old 10-19-2009, 02:05 PM   #2
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 6,577
Blog Entries: 14

Rep: Reputation: 969Reputation: 969Reputation: 969Reputation: 969Reputation: 969Reputation: 969Reputation: 969Reputation: 969
Have a look at:
http://www.linuxquestions.org/questi...3/#post2869197

What is stated there for "grep" would also apply to "awk" and other commands you're using.
 
Old 10-22-2009, 05:58 AM   #3
Raghu140
LQ Newbie
 
Registered: Oct 2009
Posts: 20

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by jlightner View Post
Have a look at:
http://www.linuxquestions.org/questi...3/#post2869197

What is stated there for "grep" would also apply to "awk" and other commands you're using.
Thanks for your help. It worked. As per you suggestion i just added in my script,

PATH=/bin
 
Old 10-22-2009, 08:13 PM   #4
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,240

Rep: Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324
I'd also point out there's no need to put the process in the background when running from cron.
Also, why run it every minute? There's a lot of load on the system creating a whole new process env each time. Use a daemon instead if you really need to process every minute.

Last edited by chrism01; 10-22-2009 at 08:14 PM.
 
Old 10-23-2009, 03:34 AM   #5
Raghu140
LQ Newbie
 
Registered: Oct 2009
Posts: 20

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by chrism01 View Post
I'd also point out there's no need to put the process in the background when running from cron.
Also, why run it every minute? There's a lot of load on the system creating a whole new process env each time. Use a daemon instead if you really need to process every minute.

Thanks for your advice. I will do that.
 
  


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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
threads scheduling problem pupillo Programming 16 07-23-2009 02:10 PM
process scheduling problem.. nick021 General 3 12-13-2007 03:41 PM
LXer: Scheduling Backup Jobs using at and crontab LXer Syndicated Linux News 0 04-22-2006 02:24 AM
scheduling problem using 'at' medmedia Linux - Software 7 12-05-2005 05:10 AM
linux scheduling problem lordofring Programming 2 08-30-2005 10:08 AM


All times are GMT -5. The time now is 03:12 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration