Script not executing in CRONTAB


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script not executing in CRONTAB
# 1  
Old 11-28-2008
Script not executing in CRONTAB

Hi,

I have written a script for file scan :

#!/bin/sh
find . -name "common.log.diff" > /dev/null 2>&1
if [ $? -eq 1 ]; then
cp common.log common.log.diff
diff common.log common.log.diff > DIFFERENCE.log
cp common.log common.log.diff
grep "ERROR" DIFFERENCE.log
if [ $? -eq 0 ]; then
echo "1" > sitescope.log
else
echo "0" > sitescope.log
fi


else

diff common.log common.log.diff > DIFFERENCE.log
cp common.log common.log.diff
grep "ERROR" DIFFERENCE.log
if [ $? -eq 0 ]; then
echo "1" > sitescope.log
else
echo "0" > sitescope.log
fi
fi


And also I have made an entry in crontab as follow for the auto execution of script.
45,46,47,48,49,50,51,52,53,54,55,56,57,58,59 * * * * /tmp/test/ts.sh


This will execute the script for every mentioned minute of an Hour. (45,46----59)

I have copied following files and script under /tmp/test/

[/tmp/test]: ls -lrt
total 16
-rwxr-xr-x 1 89 Nov 28 00:40 common.log
-rwxr-xr-x 1 508 Nov 28 00:52 ts.sh



As per the script when it run's at first attempt, it will create a file named as common.log.diff.

And it does worked, but only for manual execution. When put in crontab it is not working.

Kindly advice me on this.



Regards
# 2  
Old 11-28-2008
Please use the search forum for cron or crontab issues - this kind of question is asked very often. There is also a good guide here:
https://www.unix.com/answers-frequent...n-crontab.html

Instead of using blue letters you can also use the code tags to also presave spaces etc. when posting code or logs etc.
# 3  
Old 11-28-2008
how do we check the crontab environment ?
# 4  
Old 11-28-2008
It would be nice if you read the article I linked 1st. There is a paragraph with a bold header called:
Quote:
It works from the command line but not in crontab
# 5  
Old 11-28-2008
Hi ,

I have gone through the tutorial and checked the environment difference . The crontab is running in ksh . So, I also changed my script to #!/bin/ksh.

But it did not work . May be I wrong somewhere else. Kindly advice.

Regards
# 6  
Old 11-28-2008
Write the stdout and stderr to some file and post it here.
# 7  
Old 11-28-2008
There are a couple of points to get you moving.
1) The "." in the find statement is relative to the home directory of the account for that crontab user (which is probably not /tmp/test).
On the line before the find, first try changing to the directory from which the script was called.
cd "`dirname $0`"
2) Any output from a cron job goes to the mail account for that crontab user. That's where to look for the reason for a cron failing.
3) There are tidier ways of finding out whether a file has gained one of more lines containg the text "ERROR". Because "diff" shows the context around the difference you may get false matches. Unless you use "grep -q" or redirect the output the results will appear in the mail for that crontab user.
4) Did you use "crontab -e" to edit the crontab ? If not, cron won't know that the file has changed.

First let's get the cron to run.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Executing Oracle script from UNIX Script

Hi, I am new to UNIX and want to execute oracle script from unix script. I have written below script but i am getting below error. #!/bin/bash file="/home/usr/control/control_file1" while read line do #$line=@$line #echo $line sqlplus tiger/scott@DB @$line exit #echo "$line" done... (3 Replies)
Discussion started by: vipin kumar rai
3 Replies

2. UNIX for Dummies Questions & Answers

Script dosent exits after executing the script

Hi i wrote a script which dosent exists after executing any help #!/bin/bash netstat -ptlen | grep 10000 if ; then echo "Hive Thrift server is running" exit 0 else echo "Hive Thrift server is down Trying to Bring up the service" | mail -s "ALERT" team@domain.com `nohup hive... (7 Replies)
Discussion started by: vikatakavi
7 Replies

3. Shell Programming and Scripting

executing one script from other

Script test #! /bin/csh -f echo checking the sset command if( -e /home/user/project/runtest/testdir/ts ) then echo ts script present set cmd = "/home/user/project/runtest/testdir/ts a 1 b 2 c 3" else echo script not present endif echo $cmd echo done script ts #!/bin/csh -f set... (1 Reply)
Discussion started by: animesharma
1 Replies

4. Shell Programming and Scripting

Variables of executed script available in executing script

Hi, I have a script get_DB_var.ksh which do a data base call and get some variables as below: sqlplus -silent $user/$pass@dbname <<END select col1, col2, col3 from table_name where col4=$1; exit; END Now I want to access all these variables i.e.... (9 Replies)
Discussion started by: dips_ag
9 Replies

5. Debian

Problems with Crontab not executing scripts after edit

Hi all I installed Debian and i have a few scripts that outputs what is happening. The wierd part...after fresh install all works ok but after i open or edit Crontab it stops executing the scripts...and scripts runs manually so its not a problem with scripts...what happens is that i usually... (3 Replies)
Discussion started by: ro0t3d
3 Replies

6. UNIX for Advanced & Expert Users

Executing a shell script from windows;script present in unix

I need to execute a shell script kept in unix machine from windows. User id, password area available. For eg. There's a shell script wich moves all the logs kept in my home directory to a directory named LOGS. Now i need to get this done through windows; either using a batch file, or java... (4 Replies)
Discussion started by: rajneesh_kapoor
4 Replies

7. UNIX for Dummies Questions & Answers

probs executing crontab script

Hi everyone In an existing crontab script for the root user, I've added 5 new lines of code, however for some unknown reason, these lines of code were not executed. Here is what I did 30 0 * * * ./usr/people/atlab/jamesgoh/disk_reader/disk_reporter /picnic 30 0 * * *... (6 Replies)
Discussion started by: JamesGoh
6 Replies

8. UNIX for Advanced & Expert Users

Executing in crontab

Hi, if I launche this at commande line It is OK : $ /home/oracle/anaschxt_A01_5_15_25_plemae.sh but if I put it in crontab : Like this : I have this error : /home/oracle/anaschxt_A01_5_15_25_plemae.sh: sqlplus: not find. The script is : +17 ... (2 Replies)
Discussion started by: big123456
2 Replies

9. Shell Programming and Scripting

Problem with executing a script scheduled in crontab

Hi I have written a shell script(in Solaris) in which following logic is there..... i=1 while read control do key=`echo $control | awk -F$DELIMITOR '{ print $1 }'` echo "Key Values" ${key} i=`/usr/bin/expr $i + 1` done < $CONFPATH/$CONFFILE when i execute it at prompt it... (4 Replies)
Discussion started by: Amardeep
4 Replies

10. Shell Programming and Scripting

Overlapping(executing time) jobs in crontab

I do not have the luxery of a server that i can try on, so i had to post my qn here. Say i have two jobs in the cron table, the jobs are scheduled 2 mins apart. Assuming the first jobs does a lot of operations and takes > 2 mins. Will the second job be executed? Will Unix actually have a queue... (3 Replies)
Discussion started by: new2ss
3 Replies
Login or Register to Ask a Question