Crontab issue


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Crontab issue
# 1  
Old 06-28-2013
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
# 2  
Old 06-28-2013
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 ...
# 3  
Old 06-28-2013
Quote:
Originally Posted by jrymer
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
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?
# 5  
Old 06-28-2013
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 02:37 PM..
# 6  
Old 06-30-2013
give a try without cron .Trigger the script manually on a known directory.Post the results.
# 7  
Old 06-30-2013
Quote:
Originally Posted by Just Ice
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
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Crontab Issue

My colleague who was a sysadmin , has created a cron job script which collects logs and process them. The script works perfectly as per the defined time set by him. it works when we keep the timing as 55 05 * * * , whereas if we try to prepone the cron task is not getting executed. Where... (10 Replies)
Discussion started by: aravindj80
10 Replies

2. Shell Programming and Scripting

Crontab issue

hi, i have schduled a job through crontab, but it is not getting executed. bash-3.2$ crontab -l # Monthly Download (mm hh DD MM format) 35 05 01 04 * /home/ftpsrp/srpftp1/download/ofrdb/scripts/load_ofrdb.sh crr.sh here is the permission of the .sh files -rwxr--r-- 1 ftpsrp srp ... (7 Replies)
Discussion started by: lovelysethii
7 Replies

3. UNIX for Dummies Questions & Answers

Crontab Issue..!!!

Hi, I have a cronjob but it is not getting executed.Is there any ways to check whether crontab is working.I have put crontab -l and checked.It got listed.But it is not working. My Crontab is, * * * * * /ldesk/home/abc/source/compare.sh >/dev/null 2>&1 (1 Reply)
Discussion started by: gayisada
1 Replies

4. AIX

Crontab issue

Hi all, I'm having a problem with a crontab entry execution for a non root user. AIX version 5.3 user@host ~ $ oslevel -r 5300-10 cron status user@host ~ $ ps -ef | grep cron root 377044 1 0 Oct 27 - 0:22 /usr/sbin/cron cron entry for user user@host ~ $... (3 Replies)
Discussion started by: h@foorsa.biz
3 Replies

5. UNIX for Advanced & Expert Users

Crontab issue

We have configured a script to be run at specific time using crontab. # crontab -l 15 11 * * * VM_Count_V4.shas per the crontab entry script should run every day 11.15 a.m Every time when the script is executed i get a mail but when i run it using crontab it doesn't send any mail. However... (1 Reply)
Discussion started by: pinga123
1 Replies

6. Shell Programming and Scripting

Issue with crontab

I have a ksh script which will connect to a database and executes some sql scripts. If i run the ksh script it is working fine. But if i schedule it to run at a perticular time using cron the sql script is not running. The scriptl initially creates a spool file for sql script and then connects and... (12 Replies)
Discussion started by: Sriranga
12 Replies

7. Shell Programming and Scripting

crontab issue

Helo . I have 2.6.13-1.1526_FC4smp here. I am trying to make crontab execute my simple shell script, but noting happens. here is how i am testing this : $ pwd /home/oracle $ ls -l two* ls: two*: No such file or directory $ $ crontab -e crontab: installing new crontab $ $ crontab... (7 Replies)
Discussion started by: tonijel
7 Replies

8. UNIX for Advanced & Expert Users

crontab issue

I am adding a piece of code which adds entry in crontab ((in brown color)) \crontab -l > $tmpfile echo "Removing the cleanProcess entry if it already existed.." grep -v "cleanProcess.sh" $tmpfile > $newtmpfile lcnt=`grep -c "cleanProcess.sh" $tmpfile` echo... (4 Replies)
Discussion started by: crackthehit007
4 Replies

9. HP-UX

crontab issue

Dear Folks, i am new to hp-ux, i have a problem scheduling the crontab, The script is working fine at command prompt, but not working at cron, please find a solution for it , here are the logs and my schedule at cron: log after restarting crontab /var/adm/cron/log ! *** cron started *** ... (11 Replies)
Discussion started by: vaddi
11 Replies

10. UNIX for Dummies Questions & Answers

Crontab Issue

I have a backup script that is suppose to run every night of the week, but it never does, it starts to run. The way I can tell is that the dates on dump_log are changing to when the script runs. If I look in the cron log file is shows ! > root 506342 cr /etc/back_up Fri Aug 5 10:30:00... (2 Replies)
Discussion started by: rickyt00
2 Replies
Login or Register to Ask a Question