I'm stuck with the following (simple) problem : I want a script to be executed every 10 minutes. This script calls executable files. I use crontab and ksh on a AIX 5.3 system.

The script makes use of relative paths, but changing the executable path to absolute didn't make any difference. So, after a few tries and this answer, I came up with the following crontab entry (*/10 doesn't work)

rs14:/home/viloin# crontab -l
0,10,20,30,40,50 * * * * cd /home/viloin/cardme/bin && /bin/ksh myScript.ksh

here is the script :


  printf "executed in : %s\n" $(pwd);
  executableFile 2>/dev/null 1>&2;
  exeResult=$?; # expected return value : 90
  printf "%s\n" $exeResult;


Here is the output when I run the command manually :

rs14:/home/viloin/cardme/bin# cd /home/viloin/cardme/bin && /bin/ksh myScript.ksh
executed in : /home/viloin/cardme/bin

And finally the output when crontab runs it for me (from mail) :

 Subject: Output from cron job cd /home/viloin/cardme/bin && /bin/ksh myScript.ksh, viloin@rs14.saprr.local, exit status 0

Cron Environment:
 SHELL = /usr/bin/sh

Your "cron" job executed on rs14.saprr.local on Wed Aug 24 11:50:00 CEST 2016
cd /home/viloin/cardme/bin && /bin/ksh myScript.ksh

produced the following output:

executed in : /home/viloin/cardme/bin

Cron: The previous message is the standard output
      and standard error of one of your cron commands.

My file myScript.ksh has all rights :

rs14:/home/viloin/cardme/bin# ll -al myScript.ksh
-rwxrwxrwx    1 viloin   cardme          174 Aug 24 10:54 myScript.ksh

To make sure that my executableFile is not really exiting with code 127, I used the echo binaries, renamed it and I have the same behavior (Except that it returns 0 instead of 90 when I run the command manually).

What is causing this difference between manually typing the command and asking crontab to do it for me ?

  • Often, it's PATH. What happens if you run env -i myScript.ksh manually? – Ulrich Schwarz Aug 24 '16 at 10:14
  • @Ulrich Schwarz It shows the correct output, no 127 exit code. – Etsitpab Nioliv Aug 24 '16 at 10:17
  • 1
    Is your executableFile something that might reasonably expect to be run interactively and would fail if it's not connected to a terminal? – Ulrich Schwarz Aug 24 '16 at 11:48
  • I don't really understand your question, but i did cp /bin/echo ./executableFile to make sure the program is not returning 127 for any reason. So my executable is echo, nothing more, and calling echo; should return 0 – Etsitpab Nioliv Aug 24 '16 at 11:59
  • change your shell script to provide a full or relative path to the executable: ./executableFile ... -- in interactive use, you either have . or the cardme/bin/directory in your PATH: that will not be true in cron's environment. – glenn jackman Aug 24 '16 at 12:41

change your shell script to provide a full or relative path to the executable:

./executableFile ...

In interactive use, you must either have . or the cardme/bin directory in your PATH: that will not be true in cron's environment.

  • 1
    Thanks again. My executableFile (the original one) used PATH variables, so I changed my crontab entry to 0,10,20,30,40,50 * * * * . $HOME/.profile && cd /home/viloin/cardme/bin && /bin/ksh myScript.ksh This change fixed the previous issue too since my PATH is now correct for cron – Etsitpab Nioliv Aug 24 '16 at 13:24
  • Good job. cron problems almost always are environment-related. – glenn jackman Aug 24 '16 at 13:31
  • you might be able to use */10 instead of 0,10,20,30,40,50 -- check your crontab(5) man page. – glenn jackman Aug 24 '16 at 13:32
  • I can't see any reference to this notation in my man page, and editing crontab accordingly gives me the following error : crontab: error on previous line; unexpected character found in line. It looks like the AIX 5.3 implementation doesn't allow this notation. – Etsitpab Nioliv Aug 24 '16 at 13:47
  • oh, I didn't notice your aix tag – glenn jackman Aug 24 '16 at 13:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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