The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
root executes a script as another user ravi.sri24 Shell Programming and Scripting 9 02-11-2009 10:43 AM
Script is not working when put in crontab *Jess* Shell Programming and Scripting 2 11-26-2008 02:05 AM
shell script executes program, but waits for a prompt lionatucla Shell Programming and Scripting 7 06-19-2008 04:10 AM
crontab and shell script that executes a sql. radhika Shell Programming and Scripting 6 06-07-2005 12:33 AM
root executes a script as another user tads98 Shell Programming and Scripting 1 05-17-2005 09:54 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 04-12-2009
saha saha is offline
Registered User
  
 

Join Date: Mar 2009
Posts: 16
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 (permalink)  
Old 04-12-2009
sauron's Avatar
sauron sauron is offline
Registered User
  
 

Join Date: Apr 2009
Posts: 33
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 (permalink)  
Old 04-12-2009
saha saha is offline
Registered User
  
 

Join Date: Mar 2009
Posts: 16
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 (permalink)  
Old 04-12-2009
Housni Housni is offline
Registered User
  
 

Join Date: Apr 2009
Location: Sri Lanka
Posts: 22
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 (permalink)  
Old 04-12-2009
saha saha is offline
Registered User
  
 

Join Date: Mar 2009
Posts: 16
i forgot put that 2>&1 in this thread, but actually in cron it exists.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 11:38 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0