Crontab issue | Unix Linux Forums | UNIX for Dummies Questions & Answers

  Go Back    


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

Crontab issue

UNIX for Dummies Questions & Answers


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 06-28-2013
jrymer jrymer is offline
Registered User
 
Join Date: Jul 2012
Last Activity: 28 June 2013, 12:42 PM EDT
Posts: 32
Thanks: 6
Thanked 0 Times in 0 Posts
Crontab issue

Hello,

I have a bash script that finds files older than 31 days and deletes them. I have this file loading into crontab to run everyday. It ran fine the first time i loaded it in, but now when I try to run it manually (bash file.sh) I get errors.

Here is the script

Code:
TIME=" -maxdepth 1 -mtime +31"
DIR="/media/ExternalArchive/"

FIND=$(find ${DIR}${TIME})

rm -r ${FIND}

This is what I am doing to add it to crontab.
"crontab -e"
(load using nano)
"0 0 * * * bash /dir/file"

This should run it every day. The error I get when I try bash file.sh is as follows.
": command not found1:
find: missing argument to `-mtime'
rm: cannot remove `\r\r': No such file or directory"

With the "command not found" error appearing multiple times. Does running it with crontab do something to the file that makes it so I cannot run it normally? Crontab is not working either, the loaded file will not execute.

Thanks
Sponsored Links
    #2  
Old 06-28-2013
Just Ice's Avatar
Just Ice Just Ice is offline Forum Advisor  
Lights on, brain off.
 
Join Date: Mar 2005
Last Activity: 20 September 2013, 10:59 AM EDT
Location: Philadelphia metro
Posts: 958
Thanks: 3
Thanked 66 Times in 59 Posts
you should never run rm from cron without a specific starting directory ...

you may actually have clobbered your operating system by accident ... try running find on the command line by itself and check for errors ... confirm with a simple ls -l on a known directory ...
Sponsored Links
    #3  
Old 06-28-2013
Corona688 Corona688 is offline Forum Staff  
Mead Rotor
 
Join Date: Aug 2005
Last Activity: 17 April 2014, 6:29 PM EDT
Location: Saskatchewan
Posts: 18,531
Thanks: 681
Thanked 3,036 Times in 2,856 Posts
Quote:
Originally Posted by jrymer View Post
rm: cannot remove `\r\r': No such file or directory"
Errors about \r mean "stop editing your scripts in microsoft notepad". Editing your scripts in Windows has filled them with carriage returns.


Code:
tr -d '\r' < wintext > unixtext

    #4  
Old 06-28-2013
jrymer jrymer is offline
Registered User
 
Join Date: Jul 2012
Last Activity: 28 June 2013, 12:42 PM EDT
Posts: 32
Thanks: 6
Thanked 0 Times in 0 Posts
Find with the proper options give me the correct list of files, confirmed by ls -l. Is there another way to rm the files without moving them to a starting directory?
Sponsored Links
    #5  
Old 06-28-2013
Just Ice's Avatar
Just Ice Just Ice is offline Forum Advisor  
Lights on, brain off.
 
Join Date: Mar 2005
Last Activity: 20 September 2013, 10:59 AM EDT
Location: Philadelphia metro
Posts: 958
Thanks: 3
Thanked 66 Times in 59 Posts
see modified script below ... run in cron as /dir/file > /dev/null 2>&1 ... no need to call bash anymore as the script does it automatically ... confirm script runs correctly in a test directory before putting in cron ...

Code:
#! /bin/bash

TIME=" -maxdepth 1 -mtime +31"
DIR="/media/ExternalArchive/"
LOG=/dir/log

if [ -d $DIR ]
then
      cd $DIR
      find . ${TIME} -exec rm -r () \;
else
      echo "$DIR not found. $0 exiting."
fi > $LOG 2>&1

exit 0


Last edited by Just Ice; 06-28-2013 at 01:37 PM..
Sponsored Links
    #6  
Old 06-30-2013
vinil vinil is online now
Registered User
 
Join Date: Dec 2012
Last Activity: 21 April 2014, 3:00 AM EDT
Posts: 36
Thanks: 0
Thanked 0 Times in 0 Posts
give a try without cron .Trigger the script manually on a known directory.Post the results.
Sponsored Links
    #7  
Old 06-30-2013
bakunin bakunin is offline Forum Staff  
Bughunter Extraordinaire
 
Join Date: May 2005
Last Activity: 20 April 2014, 3:47 PM EDT
Location: In the leftmost byte of /dev/kmem
Posts: 3,919
Thanks: 39
Thanked 671 Times in 533 Posts
Quote:
Originally Posted by Just Ice View Post
see modified script below ... run in cron as /dir/file > /dev/null 2>&1
I think this will not work, because there is no attempt made to set any environment, namely no "PATH" variable. This looks like running into Cron Problem Number One.

I hope this helps.

bakunin
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Crontab Issue aravindj80 UNIX for Advanced & Expert Users 10 05-30-2013 02:21 PM
Crontab issue lovelysethii Shell Programming and Scripting 7 04-01-2013 12:14 PM
Crontab issue h@foorsa.biz AIX 3 05-02-2011 03:55 AM
crontab issue mac4rfree Shell Programming and Scripting 2 06-30-2009 05:51 AM
Crontab Issue rickyt00 UNIX for Dummies Questions & Answers 2 08-06-2005 09:31 AM



All times are GMT -4. The time now is 03:06 AM.