Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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.

function:

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.

share|improve this question

closed as unclear what you're asking by Gilles, slm, jasonwryan, terdon, Anthon Nov 27 '13 at 4:58

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question.If this question can be reworded to fit the rules in the help center, please edit the question.

    
Post the full script and the crontab line. –  Gilles Nov 26 '13 at 23:16

2 Answers 2

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).

share|improve this answer

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.

share|improve this answer

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