Operating System - HP-UX
1855600 Members
2211 Online
104112 Solutions
New Discussion

Re: vsifax script in cron

 

vsifax script in cron

hello,

I have written the below script and it works from the command line but has never worked in CRON.

Any ideas????

Thankyou
#################################
## Set up vsifax environment ##
#################################
VFAXDIR="/usr/vsifax/spool"; export VFAXDIR
VFAXBIN="/usr/vsifax/bin"; export VFAXBIN
VFAXMSG="/usr/stx/prog/ops/sjm/vsifax.msg"; export VFAXMSG
MAILTO="operations@ngbailey.co.uk btl.procurement@ngbailey.co.uk"

$VFAXBIN/fxstat -t | grep disabled | wc -l > /tmp/vsifax.err

LOGFILE=`cat /tmp/vsifax.err`

if [ $LOGFILE = 0 ]
then
sleep 1
else
echo "The VSI-Fax System is currently disabled" > $VFAXMSG
echo "To sort out this problem please run (as root):" >> $VFAXMSG
echo "/usr/vsifax/bin/fxshut" >> $VFAXMSG
echo "/usr/vsifax/bin/fxsched" >> $VFAXMSG
echo "/usr/vsifax/bin/fxenable fax1" >> $VFAXMSG
echo " " >> $VFAXMSG
echo "Current Status of the fax system: " >> $VFAXMSG
echo "---------------------------------" >> $VFAXMSG
$VFAXBIN/fxstat -t >> $VFAXMSG
cat $VFAXMSG | elm -s "The VSI-Fax System is currently disabled" $MAILTO
fi

rm /tmp/vsifax.err
8 REPLIES 8
Tom Danzig
Honored Contributor

Re: vsifax script in cron

Perhaps you are using ksh at the command line? cron uses sh (posix shell) by default.

If so, try putting the following line as the fisrt line in the script:

#!/usr/bin/ksh

Also, you should define a PATH in the script. The PATH variable in .profile and /etc/profile is not sourced by cron.
James R. Ferguson
Acclaimed Contributor

Re: vsifax script in cron

Hi:

The most common reason a script which runs from the command line does not run when initiated by 'cron' is the sparse environment that 'cron' jobs inherit. While your use of absolute path names suggests that you are aware of this, check carefully to see if their are other variables normally in your environment that your script needs.

Remember too, that the crontask is not interactive. That is, there is no terminal associated with the process. Any input which is expected from the terminal device (stdin) must therefore be accomodated by other means (redirection, etc.).

Regards!

...JRF...
BradF
Frequent Advisor

Re: vsifax script in cron

I will sometimes put a 'set -x' in the script and redirect stdout and stderr to a log file in the crontab file. This lets you trace what the script is doing and where it has problems.

I.E. 0 12 * * * /path/script_to_run.sh >/tmp/cronscript.log 2>&1

-Brad

Re: vsifax script in cron

Hello Again,

Thanks for the responses! I haven't yet managed to get it to work. I have had a look at /var/adm/cron/log and a * appears in the file before the script. I haven't seen this before? Could anyone tell me what it means?

Thanks.

Re: vsifax script in cron

We also get the following message in root mail from the cron job

sh: Mail: Execute permission denied.

Has anyone seen this before?
Steve Post
Trusted Contributor

Re: vsifax script in cron

I though you had to have a vsifax user that isn't root. If this is the case, perhaps this happens?.....

root runs the job.
the job runs other stuff as user vsifax.
User vsifax tries to use something only root has access to.

If it works by hand and not by cron set up a cronjob to output the environment.

ie.
58 14 * * * env > /tmp/env.incronjob

And run it by hand:
env > /tmp/env.byhand

Then....
diff /tmp/env.incronjob /tmp/env.byhand

Fred Martin_1
Valued Contributor

Re: vsifax script in cron

I have several root-cron scripts that run vsifax commands in them, without trouble. I attached one, so you can have a look at the code. Runs in my root cron fine.

One note, I try to always put the full pathname to all binaries, when writing cron scripts, for reasons mentioned already - the sparse environment.

For those that may want or need it, the script attached is intended to check the status of our fax server once an hour, and email/page me if the thing isn't normal.

I'll not claim it's well written; only that it works.
fmartin@applicatorssales.com
Fred Martin_1
Valued Contributor

Re: vsifax script in cron

I have several root-cron scripts that run vsifax commands in them, without trouble. I attached one, so you can have a look at the code. Runs in my root cron fine.

One note, I try to always put the full pathname to all binaries, when writing cron scripts, for reasons mentioned already - the sparse environment.

For those that may want or need it, the script attached is intended to check the status of our fax server once an hour, and email/page me if the thing isn't normal.

I'll not claim it's well written; only that it works.
fmartin@applicatorssales.com