We are using the below commands to get pagesapce values and I need to check percent of used pagespace. For this I have used the below code, but when running this script it's passing a null value into the function.

MAX=`free -m | grep Swap | gawk '{ print $2 }'`
MIN=`free -m | grep Swap | gawk '{ print $3+300 }'`
DIV=`echo $MIN/$MAX*100|bc -l`
PAGESPACE=`print $(( round(DIV) ))`

I am passing the PAGESPACE as argument in one of my functions.


monPar 0 0 $PAGESPACE 80 90 db1adm "PAGE SPACE" now

If I run this script manually, it gives correct values. The problem is when this script runs in crontab: it passes 0 values into function.


Number one issue with cron jobs not working, check your $PATH.
Try either setting $PATH explicitly in the cron job, or use absolute paths to all the utilities.

Second most likely issue, check your shell. The round(DIV) is not a typical shell arithmetic operator, so it might not be available in the shell cron is using.

Also as a note, you can simplify the PAGESPACE= bit by doing PAGESPACE=$(( round(DIV) )). The backticks are not necessary (well they shouldn't be if the shell follows normal behavior, but I don't know what shell it is).


There are some rules for executing scripts in crontab:

  1. For all commands please use $(which COMMAND) in your script to avoid path problems in crontab.
  2. If you test your script on command line execute it with the same user as the crontab will do.
  3. set up the full path name in the crontab
  4. set up the correct shell in the script as shebang.

If theses hints are not working: generate a log file in your script and log all variables to isolate the problem.

Not the answer you're looking for? Browse other questions tagged or ask your own question.