A command in a script not running in Crontab.


 
Thread Tools Search this Thread
# 1  
A command in a script not running in Crontab.

Hi,

I made this script for TRU Unix 5.1 OS based Node.
When the script was run manually all the commands were running properly. But when it was run from Crontab, one command is not running.

This command is not running when the script is running from Crontab:
# /usr/mg2/svi/svicom/svistatjo.x -j 20090702 -f stat_log_temp
(This is a application based command used ti fetch certain statistics of that application depending on the date)

I am using /bin/ksh shell in the script.The crontab I am using is for root user, and the command is also run by root

[ Following are the fixes that I have tried till now, but it has not done any good:

Fix 1:
I tried to find the directory from which the command is executing by the following way:
# cd /usr/mg2/svi/svicom
# which svistatjo.x
Output: /usr/mg2/svi/svicom/svistatjo.x
If the command 'which svistatjo.x' is executed from any other path, no ouput is obtained.
This is the reason the command i gave above was with the full path.

Fix 2:
I used the command this way in the script too, but it is still not runnng through crontab.
#su -c "svistatjo.x -j 20090702 -f stat_log_temp"

Also, Whenever I am running the script from Crontab, an error is coming in mail, something like :
"stty: tcgetattr: Not a typewriter
stty: tcgetattr: Not a typewriter
Not a terminal
Ambiguous output redirect. ", but I am not sure how this error is related to the command.Smilie]

Please suggest modifications so that this command can be run from crontab also.

\\ Thanks in anticipation
# 2  
This looks to me like you are using an environment variable within your script - cron does not set up any kind of environment.
Another possibility is that you may not be explicitly referring to ksh in the #! path at the top of your script, cron executes everything in sh.
That warning of an ambiguous redirect is probably the crux of the issue, but your commandline isn't doing any redirection.

Can you try posting your crontab line, and perhaps your script too?
# 3  
Bug

Thanks for the prompt reply... here is the part of the script(in bold) where the error is occuring.

In crontab entry i have simply given entry like this:
00 2 * * * /path/script_name

Code:
#!/bin/ksh
if cd /usr/Prepaid/Health-check 2>/dev/null;
then
 find /usr/Prepaid/Health-check -name "health_*" -mtime +30 -exec rm "{}" ";" 
else
cd /usr/Prepaid
mkdir Health-check
fi
logd=`date '+%Y%m%d-%H:%M'`
echo "\nAutomated health Check of HP IVR" > /usr/Prepaid/Health-check/health_$logd.log

-----------------------------------------------------------------------------------------------------
echo "\n\n---------------" >> /usr/Prepaid/Health-check/health_$logd.log
echo "SVI Call" >> /usr/Prepaid/Health-check/health_$logd.log
echo "--------------------------------------------------------------------------------" >> /usr/Prepaid/Health-check/health_$logd.log
date=`TZ=aaa00 date +%Y%m%d`
#cd /usr/mg2/svi/svicom >/dev/null 2>&1
/usr/mg2/svi/svicom/svistatjo.x -j $date -f /usr/Prepaid/log_$date.log >/dev/null 2>&1
cd /usr/Prepaid
echo "Type    Inter   Access  Appli   Called  Calling Diag    CnxT    CnxD    Node" >tempmmtstatjo
tail -5 log_$date.log >> tempmmtstatjo 
st=`wc -l tempmmtstatjo | awk '{print $1}'`
if [ $st -gt 2 ]
then
echo "The following is list of upto last five calls: " >> /usr/Prepaid/Health-check/health_$logd.log
cat tempmmtstatjo >> /usr/Prepaid/Health-check/health_$logd.log
tail -1 tempmmtstatjo > tempmmtstatjo1
awk '{print $8}' tempmmtstatjo1 > tempmmtstatjo2
hourc=`awk -F"H" '{print $1}' tempmmtstatjo2`
minc=`awk -F"H" '{print $2}' tempmmtstatjo2`
let timec=$hourc*60+$minc
hourn=`date '+%H'`
minn=`date '+%M'`
let timen=$hourn*60+$minn
let gapt=$timen-$timec
let gaph=`expr $gapt / 60`
let gapm=`expr $gapt % 60`
 if [ $gapt -gt 10 ] && [ $gapt -le 30 ]
 then
 echo "\nMajor Warning: There were no call records in the last $gapt minutes" >> /usr/Prepaid/Health-check/health_$logd.log
 elif [ $gapm -gt 30 ] || [ $gaph -gt 0 ] || [ $gapt -gt 30 ]
 then
 echo "\nCritical Warning: There were no call records in the last $gaph hours $gapm minutes" >> /usr/Prepaid/Health-check/health_$logd.log
 else
 echo "\nThe last call record is of $gapm minutes ago" >> /usr/Prepaid/Health-check/health_$logd.log
 fi
else
echo "Critical Warning:There were no call records found on the server for today. Please check." >> /usr/Prepaid/Health-check/health_$logd.log
fi
rm tempmmtstatjo
rm tempmmtstatjo1
rm tempmmtstatjo2
rm log_$date.log

#---------------------------------------------------------------------------------------
cat /usr/Prepaid/Health-check/health_$logd.log > /usr/Prepaid/Health-check/health-check.log
#---------------------------------------------------------------------------------------



---------- Post updated at 01:29 PM ---------- Previous update was at 11:38 AM ----------

Issue Solved!

Added this line in the script after defining the shell path:

. ${HOME}/.profile


//

Last edited by mystition; 07-02-2009 at 06:49 AM..
 

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #961
Difficulty: Medium
SQL MammyJammer was a computer worm that caused a denial of service on some Internet hosts and dramatically slowed down general Internet traffic in 2003.
True or False?

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

CRONTAB - one python script is not running

Hi! I'm using a RaspberryPi with standard Raspbian. Currently I'm working on some sort of weather station. For now I have three python scripts - one which is updating txt files for website - update1m.py ( it will not be necessary in few next days so I'll delete it) , second one for updating... (4 Replies)
Discussion started by: bartocham
4 Replies

2. Shell Programming and Scripting

Delay in running script from crontab

I am facing an issue where sometimes crontab is running script with some delay. Below is the stmt in script and it is the only stmt in script. echo "running at `date` " >> CRONCHECK.log Below is the cron entry. 0 11 * * * CRONCHECK.sh Below is the time of run each day. running at Fri... (8 Replies)
Discussion started by: Nishant Singh
8 Replies

3. UNIX for Dummies Questions & Answers

crontab not running script

Hi All, I am having the below script to be run from crontab, it it doesnt run. 1 * * * * /home/cobr_ext/test.sh > /home/cobr_ext/temp.txt when i run i manally it runs without any issues. Could please help me as to why doesnt it run the script.:( (7 Replies)
Discussion started by: abhi_123
7 Replies

4. UNIX for Advanced & Expert Users

Particular script not running through crontab

Hi, I have created the below script, set -x # Set the Path of Environment file ENV_FILE_DIR=/opt/app/p1trp1c1/sybase/ecdwqdm/xrbid/QDM_Prod/bin LOG_DIR=/opt/app/p1trp1c1/sybase/ecdwqdm/xrbid/QDM_Prod/log export ENV_FILE_DIR export LOG_DIR # Set Audit Environment . ${ENV_FILE_DIR}/QDM.env... (8 Replies)
Discussion started by: yohasini
8 Replies

5. Shell Programming and Scripting

Crontab not running a script

Hi, I posted this in the Solaris forum but I think this one would be more appropriate. I created a script starting with the following lines: #!/usr/bin/ksh flag=n export flag typeset -i quant=0 (...) When running it I'm getting the following 2 errors: /tmp/tstscript/testfail.ksh:... (9 Replies)
Discussion started by: Cvg
9 Replies

6. Shell Programming and Scripting

Running SQLPLUS Script in CRONTAB

Hi, Can someone please help me here with this one. This is my script: # more tosh.sh #!/usr/bin/ksh clear . /home/oracle/.profile echo "Good morning, world." export ORACLE_HOME=/u01/app/oracle/product/9.0.1 export PATH=$ORACLE_HOME/bin:/usr/local/bin export ORACLE_SID=xxxx ... (11 Replies)
Discussion started by: santoshpayal
11 Replies

7. Shell Programming and Scripting

Problem with crontab running a script

I am trying to use the CRON utility in Fedora 11 & CentOS... I intend to run a script which pops up a warning message every hour and i made the following entry using "CRONTAB -e " * * * * * sh /bin/myscript.sh But this does not seem to be running. Another thing to note is that,... (4 Replies)
Discussion started by: Vabiosis
4 Replies

8. Red Hat

Problems with script running with crontab

Hi, I'm trying the backup a few information commands of my Check Point FW (it's on a SPLAT linux machine). This is the script I wrote: #!/bin/bash cd /var/tmp/ file1=netstat_`/bin/date +%d%m%y`.txt file2=ifconfig_`/bin/date +%d%m%y`.txt file3=cpstatos_`/bin/date +%d%m%y`.txt... (2 Replies)
Discussion started by: nirsh
2 Replies

9. UNIX for Dummies Questions & Answers

Getting error when running script through crontab

Hi all, I wrote small script for Solaris and when I am running it through command prompt its ok, but when I trying to run it using crontab, i am getting error like: ld.so.1: dbloader: fatal: libACE.so: open failed: No such file or directory /tmp/file.sh: line 5: 8304 Killed ... (4 Replies)
Discussion started by: nypreH
4 Replies

10. Shell Programming and Scripting

issue with running script with crontab

I am facing a strange issue while running a script(eg A) from the crontab entry the script calls one more script(eg B) within it now when i run the script A manually(with nohup) it also executes the script B (embedded inside it) as expected. but when i run the script A from the crontab entry... (7 Replies)
Discussion started by: mad_man12
7 Replies

Featured Tech Videos