script not working from crontab, executes individual


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting script not working from crontab, executes individual
# 1  
Old 04-12-2009
script not working from crontab, executes individual

Hi,
This script is working successfully when i executed from shell prompt, but the same script scheduled in crontab its not deleting the files,

#! /bin/bash
DAY_1=`(date --date='4 months ago' '+%Y-%m')`
log=/tmp/cleant
adir=/u01/app/oracle/admin/talon/adump
udir=/u01/app/oracle/admin/talon/udump
bdir=/u01/app/oracle/admin/talon/bdump
export DAY_1
echo "Cleaning trace files start " > $log
date >>$log
echo $DAY_1 >>$log
cd $adir
ls -l | grep -i $DAY_1 | awk '{ print $8}'| xargs rm -f
cd $udir
ls -l |grep -i $DAY_1 | awk '{print $8}'| xargs rm -f
cd $bdir
ls -l |grep -i $DAY_1 | awk '{print $8}'| xargs rm -f
cd
echo "Finished " >>$log

i am trying to remove files 4 months ago which would be in huge number(500000 approx. files). if run
$ . remtrc ( it successfully removes files)
crontab (example)
10 00 1 * * * /home/oracle/remtrc > /tmp/cleantrc.log
but from crontab it not able to remove files.
what i am missing in the script.
# 2  
Old 04-12-2009
hi,
what about permissions?
it is better in crontab to specify the user who gotta do the job:

10 00 1 * * * root /home/oracle/remtrc > /tmp/cleantrc.log

Bye
# 3  
Old 04-12-2009
in cron log file there was no messages displayed, i have other scripts that run, is this because i use 'ls -l ', 'cd' command.
# 4  
Old 04-12-2009
Well, you need to handle the output stream that goes to stderr:

Code:
10 00 1 * * * /home/oracle/remtrc > /tmp/cleantrc.log 2>&1

see: Redirecting to and from the standard file handles
# 5  
Old 04-12-2009
i forgot put that 2>&1 in this thread, but actually in cron it exists.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script not working via crontab

Hi, I have written one script which is connecting to the the database and generating one CSV, it is running fine when i ran it manually though it is throwing any warning but CSV is generating and working fine but same script when i have configured in crontab not working and giving error, kindly... (1 Reply)
Discussion started by: ash1234
1 Replies

2. Shell Programming and Scripting

Script not working via crontab

Hi, I have written one script which is connecting to the the database and generating one CSV, it is running fine when i ran it manually though it is throwing any warning but CSV is generating and working fine but same script when i have configured in crontab not working and giving error, kindly... (6 Replies)
Discussion started by: ash12345
6 Replies

3. Red Hat

Script not working if crontab scheduled

Hi all, I'm working to a script with /bin/bash shebang. The script works perfectly if I run from command line. The script runs under a non root user and inside the commands are set with sudo command in a such a way they can be run under root, for example (first rows of the script):... (5 Replies)
Discussion started by: idro
5 Replies

4. UNIX for Dummies Questions & Answers

Script is not longer working in the crontab

This is the crontab it is supossed to be running everyday but it didnt 5 0 * * * /export/app/CO/opge/scr/Informe_parametros_colombia.ksh >/dev/null 2>&1 Inside the above script connects to a database and extract data to a flat file, manually i run the script at about 2 a.m. and Works OK,... (6 Replies)
Discussion started by: alexcol
6 Replies

5. Shell Programming and Scripting

Script not working in crontab

Hi I have created a script. Which i have configured in cron to make it run in every 2 min. But script is not running. If I checl the cron log at /var/cron/log .it shows its running in every 2 min. Below is the command which i configured in crontab. But I am not able to find the way so that... (9 Replies)
Discussion started by: nandan8a
9 Replies

6. Shell Programming and Scripting

My script stops working when using crontab

I have made a shell script(/bin/sh) that starts a perl script (that I haven't made my self) that's starts a ssh session. The ssh session uses a private/public key to login so no password is needed. The Perl script works perfect. But when I put it in a cronjob (crontab) the ssh connection asks... (6 Replies)
Discussion started by: splinter_cell
6 Replies

7. Shell Programming and Scripting

Expect Script Not working with Crontab

I have the following expect script sitting on a Linux box. === #!/usr/bin/expect -f # # backup.expect # # Expect script to backup a firewall via a SSH session # # set firewall set username set password set prompt set filename match_max 50000 spawn ssh -l... (2 Replies)
Discussion started by: alagondar
2 Replies

8. Shell Programming and Scripting

Running a script in crontab which executes a jar file

Hi, I have a script (.sh file) which has been created through my login. This script executes a jar file. Java is installed through my login and the folder has been given full permission for access. When this script is added by root in crontab, it does not get executed. Could you please... (1 Reply)
Discussion started by: archana.n
1 Replies

9. UNIX for Dummies Questions & Answers

crontab entry executes sporadically

I have a crontab entry that goes out to 12 servers each day and gathers statistics about their dayend processing. The script goes to both HP and AIX servers (which shouldn't make a difference, I don't think). We output the job to a log file. Some weeks, the job will run successfully every day... (2 Replies)
Discussion started by: kweikel
2 Replies

10. Shell Programming and Scripting

crontab and shell script that executes a sql.

Problem: I have a crontab and when it kicks off, xxx.sh shell script is called. Which has a nohup sqlplus session call. Problem is sql does not get executed and a text file is not getting created. Only a empty log file is getting created. Are there any constraints for crontab to open a sql... (6 Replies)
Discussion started by: radhika
6 Replies
Login or Register to Ask a Question