shell scripting problem
HI i have written this simple script to delete files and keep a log i have put this script in crond job
#!/bin/bash echo "deleting file which are 30 day old" echo "-----------------------------------" >> ~/mylog date >> ~/mylog echo "-----------------------------------" >> ~/mylog find /home/francis/test/* -mtime +30 -exec rm -rfv {} \; >>~/mylog the script check the test directory in /home/francis if it encounters a file which is a 30 days old it must delete that file and place the file deleted in mylogs as a log report the script works fine i manually i have two problems first when the script ram the first time it generated the log of the files it deleted but the next day when i came it deleted the file but no log was generated secondly i run the script every day at 9 am this is the entry made in crond file * 9 * * * ~path to file but it seems to run every minute i even triedseperating the fields by tabs still the same |
Please use thread titles that describe the problem---"help needed" tells us nothing.
1. Deleted what file? mylog? You are using redirection to append to mylog, but it is not obvious to me what will be the output of the find command. If you do find and then "-exec rm {}", then what output would be generated to send to mylog? 2. A quick glance at the man pages and this: http://en.wikipedia.org/wiki/Cron suggests that you need "0" in the minutes column (I think * means "any" minute.) Look at the examples in the wikipedia article. |
What were the symptoms/evidence for "the next day when i came it deleted the file but no log was generated"? If the file had been deleted when you looked, how are you _sure_ it existed?
When you write "no log was generated" do you mean no further log file entries were generated or no log file was generated (implying the old one had been removed). I figure it's rm's -v option that is generating info for the log. |
i have created a set of files with the required timestamp of one months so i sure the file is there, when i check the folder according to tha day the file is deleted but the deleted file log is not placed in the file mylog. the file is there but it doesnt mwntion which file it has deleted
|
good information about shell scripting
|
It works on my system.
|
1 Attachment(s)
ya it works the first time , i have put the script in a cron job
the script does the job but it doesnt leave a log report of the file generated if u can update the script on and sent me would be nice i am attaching my script here |
LQ is here to help you, not to give you a handout.
Have you checked the mail for the user that the cron job is being run for? If a cron job generates output, it is mailed to the user on the local system. You may also find some useful information to help get this working by searching LQ. Many people have had difficulty running scripts from cron. |
All times are GMT -5. The time now is 11:08 AM. |