LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
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 04-22-2010, 08:11 AM   #1
fernfrancis
Member
 
Registered: Feb 2009
Location: Goa(India)-Sharjah(UAE)
Distribution: RHEL,centos,fedora,ubuntu
Posts: 234

Rep: Reputation: 18
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

Last edited by fernfrancis; 04-22-2010 at 10:14 AM. Reason: changing the title
 
Old 04-22-2010, 08:27 AM   #2
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
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.
 
Old 04-22-2010, 10:55 AM   #3
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
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.
 
Old 04-25-2010, 01:02 AM   #4
fernfrancis
Member
 
Registered: Feb 2009
Location: Goa(India)-Sharjah(UAE)
Distribution: RHEL,centos,fedora,ubuntu
Posts: 234

Original Poster
Rep: Reputation: 18
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
 
Old 04-25-2010, 01:07 AM   #5
EmmaMadeleineMcDonald
LQ Newbie
 
Registered: Apr 2010
Posts: 3

Rep: Reputation: 0
good information about shell scripting
 
Old 04-25-2010, 01:27 AM   #6
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
It works on my system.
 
Old 04-25-2010, 03:18 AM   #7
fernfrancis
Member
 
Registered: Feb 2009
Location: Goa(India)-Sharjah(UAE)
Distribution: RHEL,centos,fedora,ubuntu
Posts: 234

Original Poster
Rep: Reputation: 18
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
Attached Files
File Type: txt del.txt (288 Bytes, 8 views)
 
Old 04-25-2010, 06:07 AM   #8
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
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.
 
  


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
I almost got it!help needed! linus72 Slackware - Installation 2 03-09-2009 06:09 PM
Help needed for make file problem : make: *** No rule to make target `flash', needed rameshsatyavaram Linux - Newbie 3 09-11-2008 02:13 AM
help with ip needed Junior_DBA Linux - Newbie 5 09-08-2008 04:52 AM
XGL needed for Beryl is conflicting with OpenGL needed for Cedega chunkeydelight Linux - Desktop 2 07-18-2007 05:50 AM
Errors installing Q, which is needed for Lex, which is needed for PHP Virtuality Linux - Software 1 05-29-2007 04:47 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

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