Operating System - HP-UX
1834150 Members
2980 Online
110064 Solutions
New Discussion

Re: script runs as standalone but does not work in cron

 
Hunki
Super Advisor

script runs as standalone but does not work in cron

Here is the message from the mail. The script is attached.

Your "cron" job on msb-12
(/export/home/it/ARCH )

produced the following output:

stty: : No such device or address
xargs: Could not exec command: No such file or directory
xargs: Could not exec command: No such file or directory
xargs: Could not exec command: No such file or directory
xargs: Could not exec command: No such file or directory
xargs: Could not exec command: No such file or directory
xargs: Could not exec command: No such file or directory
xargs: Could not exec command: No such file or directory
xargs: Could not exec command: No such file or directory
xargs: Could not exec command: No such file or directory
xargs: Could not exec command: No such file or directory
xargs: Could not exec command: No such file or directory
xargs: Could not exec command: No such file or directory
xargs: Could not exec command: No such file or directory
xargs: Could not exec command: No such file or directory
xargs: Could not exec command: No such file or directory
xargs: Could not exec command: No such file or directory
xargs: Could not exec command: No such file or directory
xargs: Could not exec command: No such file or directory
xargs: Could not exec command: No such file or directory
xargs: Could not exec command: No such file or directory
xargs: Could not exec command: No such file or directory
xargs: Could not exec command: No such file or directory
xargs: Could not exec command: No such file or directory
xargs: Could not exec command: No such file or directory
6 REPLIES 6
Torsten.
Acclaimed Contributor

Re: script runs as standalone but does not work in cron

Hi,

rule number 1 for scripting:
use full pathnames!

How to get?
Whereis ...

>whereis xargs
xargs: /usr/bin/xargs

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!   
Jeff_Traigle
Honored Contributor

Re: script runs as standalone but does not work in cron

gzip is located in /usr/contrib/bin, which is not in the barebones PATH that exists in the cron environment. Either reference the command as /usr/contrib/bin/gzip or define PATH=${PATH}:/usr/contrib/bin at the start of your script.
--
Jeff Traigle
Ivan Ferreira
Honored Contributor

Re: script runs as standalone but does not work in cron

Use the full path to commans after xargs, for example:

xargs /bin/rm -fr
Por que hacerlo dificil si es posible hacerlo facil? - Why do it the hard way, when you can do it the easy way?
A. Clay Stephenson
Acclaimed Contributor

Re: script runs as standalone but does not work in cron

The first thing that I would do is get rid of the attempt at sourcing .profile. I know you are doing it to set environment variables but there is a much better way. Your .profile has commands that expect stdin to be a tty device (e.g. a terminal) and you ain't under cron. You thus have to surround all such commands with
if [[ -t 0 ]]
then
stty ...
tabs ...
tset ...
fi
or the equivalent so that .profile works as intended when stdin is not a tty device.

The better way is to create a file (e.g. /usr/local/bin/myenv.sh) and use it to set and export any needed variables and then both your .profile and your cron'ed script should source this file. It's also a good place to set and export additional PATH values so that full path names are not needed.

If it ain't broke, I can fix that.
hpuxrox
Respected Contributor

Re: script runs as standalone but does not work in cron

Scripts run from cron do not have any system wide environment variables; such as PATH. The variables needed must be explicitly defined within your script. However, you can use the absolute path name to each of the executables executed within your cronjob, but I find it easier to echo $PATH from the shell I am testing the script in and include this within the script. ie,

# echo $PATH
/usr/sbin:/usr/ccs/bin

#! /bin/sh
export PATH=/usr/sbin:/usr/ccs/bin

Dennis Handly
Acclaimed Contributor

Re: script runs as standalone but does not work in cron

This wasn't mentioned but your redirection of output maybe in the wrong order:
$ find ... 2>&1 > /dev/null

If you want to send both to /dev/null:
$ ... > /dev/null 2>&1

You sent stderr to stdout and tossed stdout.