Linux - NewbieThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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
Last edited by fernfrancis; 04-22-2010 at 10:14 AM.
Reason: changing the title
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
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.