System Administration
cancel
Showing results for 
Search instead for 
Did you mean: 

unable to execute a script from cron, but possible from CLI

jerish sunny
Occasional Advisor

unable to execute a script from cron, but possible from CLI

I am using the attached shell script. when i execute it from CLI it is working fine. But when i set it as cron it is not executing correctly and giving result as 'thread value not found for process. process might be stopped'
11 REPLIES
Michal Kapalka (mikap)
Honored Contributor

Re: unable to execute a script from cron, but possible from CLI

hi,

could you provide the line from crontab ???

most of this error is there is no full path to the script or shell defined .....

mikap
Torsten.
Acclaimed Contributor

Re: unable to execute a script from cron, but possible from CLI

You should always use full pathes to binaries!

Not

"application"

but

/usr/sbin/application

for example.

Hope this helps!
Regards
Torsten.

__________________________________________________
There are only 10 types of people in the world -
those who understand binary, and those who don't.

__________________________________________________
No support by private messages. Please ask the forum!

If you feel this was helpful please click the KUDOS! thumb below!   
jerish sunny
Occasional Advisor

Re: unable to execute a script from cron, but possible from CLI

0,5,10,15,20,25,30,35,40,45,50,55 * * * * /var/opt/TnDM/threadscript/ThreadCount.sh > /var/opt/TnDM/threadscript/debug.txt 2>&1

This is the crontab link
jerish sunny
Occasional Advisor

Re: unable to execute a script from cron, but possible from CLI

my understanding is that it is not able to write the value into the file $LOG_FILE.
in this line /opt/perf/bin/glance -j 1 -f $LOG_FILE -iterations 1 adviser_only > /dev/null
Michal Kapalka (mikap)
Honored Contributor

Re: unable to execute a script from cron, but possible from CLI

hi,

i tink you should define shell before the

/bin/sh ( for example ) /var/opt/TnDM/threadscript/ThreadCount.sh

mikap
jerish sunny
Occasional Advisor

Re: unable to execute a script from cron, but possible from CLI

i tried adding /usr/bin/sh but no difference in output
Torsten.
Acclaimed Contributor

Re: unable to execute a script from cron, but possible from CLI

I'm sure you will find something like "not found" in your debug.txt, because you use awk etc. without path.

Hope this helps!
Regards
Torsten.

__________________________________________________
There are only 10 types of people in the world -
those who understand binary, and those who don't.

__________________________________________________
No support by private messages. Please ask the forum!

If you feel this was helpful please click the KUDOS! thumb below!   
piyush mathiya
Trusted Contributor

Re: unable to execute a script from cron, but possible from CLI

Hi Sunny,

There is a problem in glance command, I also faced the same problem long back. Whenever you execute the script manually, you can be. but while executing through cron, you can't. I am sure this is because of glance command only...


Other problem may be because of profile file, you execute .profile file with the absolute path in the top of the script as while login into the server, the profile will get executed which used to set all environment variable for you. but while its in cronjob, you need to execute it manually...

like: "./~home/.profile"

Regards,
Piyush Mathiya
Torsten.
Acclaimed Contributor

Re: unable to execute a script from cron, but possible from CLI

# whereis echo
echo: /usr/bin/echo /usr/share/man/man1.Z/echo.1 /usr/share/man/man3.Z/echo.3x
# whereis awk
awk: /sbin/awk /usr/bin/awk /usr/share/man/man1.Z/awk.1



What does your debug file tell you?

Hope this helps!
Regards
Torsten.

__________________________________________________
There are only 10 types of people in the world -
those who understand binary, and those who don't.

__________________________________________________
No support by private messages. Please ask the forum!

If you feel this was helpful please click the KUDOS! thumb below!   
jerish sunny
Occasional Advisor

Re: unable to execute a script from cron, but possible from CLI

the issue is in this line of the script
/opt/perf/bin/glance -j 1 -f $LOG_FILE -iterations 1 adviser_only > /dev/null
the command is not able to write in to the file. the file permission is 777 for the log_file.
Dennis Handly
Acclaimed Contributor

Re: unable to execute a script from cron, but possible from shell

>the issue is in this line of the script
>/opt/perf/bin/glance -j 1 -f $LOG_FILE -iterations 1 adviser_only > /dev/null
>the command is not able to write in to the file. the file permission is 777 for the log_file.

What is the value of LOG_FILE? (Use "ll $LOG_FILE" in your script to check the permissions.)
You may not want to send the output to /dev/null, there may be error messages there.