Commands to call script work from command line but not from Cron entry

My first post evidently did not materialize so I posted it again:

Runnning a cron job every 5 mins to send data files to a state facility.
My original cron entry at worked fine:

01,06,11,16,21,26,31,36,41,46,51,56 * * * * /home/sftpuser/stateinoc-from-appname.ksh

Somewhere I have a problem picking up all the files so I wanted to capture all output from the script into a log file so I did this:

01,06,11,16,21,26,31,36,41,46,51,56 * * * * MYDT=`date +%m%d%Y%H%M`;/home/sftpuser/appname-from-appname.ksh 2>&1 |/usr/bin/tee -a /tmpmsql/import/appname/statesinoc/StateInoc.$MYDT.log

I am not sure if the entrie cron is failing or if just the log file isd not getting created. When I do it from the command line, the log file gets created and filled with my verbose output from the script.

Is there something special to do with my syntax in the cron entry ?

Thread: Commands to call script work from command line but not from Cron entry Edit Post

---------- Post updated at 04:46 PM ---------- Previous update was at 04:38 PM ----------

I don't know why I had the "tee" in there. Probably used it while I was testing. I have since taken it out:

01,06,11,16,21,26,31,36,41,46,51,56 * * * * MYDT=`date +%m%d%Y%H%M`;/home/sftpuser/flshots-from-cerner.ksh 2>&1>/tmpmsql/import/appname/statesinoc/StateInoc.$MYDT.log

Usually 2-3 stumbling blocks get new cron users:

  1. There is no tty, no /dev/tty, no controlling terminal. You can create one in several ways, like ssh -tt and expect, but usually one does not want terminal output from a cron job.
  2. You have to build the environment manually, and if you were not careful writing your ~/.profile, it may want a tty. Without the usual PATH, LD_LIBRARY_PATH, etc. many apps fail.
  3. Execuatble scripts should be set up according to man exec to run under the right interpreter. Cron will call scripts using sh, and if you lack exec permissions or first line is not:
    text #!/full/path/to/interpreter [ <optional-one-argument> ]
    then you are in trouble.

I often test run cron script lines using something like:

$ echo '<your-command-line>' | ssh localhost sh

(no terminal, called from sh).