LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Problem In Scheduling with Crontab on RHEL 4 (https://www.linuxquestions.org/questions/linux-newbie-8/problem-in-scheduling-with-crontab-on-rhel-4-a-762967/)

Raghu140 10-19-2009 10:33 AM

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

MensaWater 10-19-2009 01:05 PM

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.

Raghu140 10-22-2009 04:58 AM

Quote:

Originally Posted by jlightner (Post 3725147)
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

chrism01 10-22-2009 07:13 PM

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.

Raghu140 10-23-2009 02:34 AM

Quote:

Originally Posted by chrism01 (Post 3729213)
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.


All times are GMT -5. The time now is 03:12 AM.