0

I have a script which will run through crontab everyday from monday to friday at 12:50 am. Below is the code for crontab

50 00 * * 1-5 /u01/app/ecm2fs/deep/FS/kadecut.pl >> /u01/app/ecm2fs/deep/FS/salescut.log

But it is not running. But when i execute it manually it is running. Can anyone tell me what might be the problem?

  • 3
    What is in /u01/app/ecm2fs/deep/FS/salescut.log ? Cron might have different env vars and working directory so your script gets an error. Also add 2>&1 at the end to output errors to the log. – UjinT34 Oct 26 '18 at 05:12
  • This is where i am appending any error in the script – Riju Mukherjee Oct 26 '18 at 05:13
  • i am just printing a hello world through crontab but it is working...... 51 00 * * 1-5 /u01/app/ecm2fs/deep/FS/hello.ksh >> /u01/app/ecm2fs/deep/FS/hello.log – Riju Mukherjee Oct 26 '18 at 05:14
  • Maybe crond is dead? – Red Cricket Oct 26 '18 at 05:14
  • But i tested with some other script like printing hello world, that script is working fine – Riju Mukherjee Oct 26 '18 at 05:15
  • how are you manually running the perl script? Did you try what Ujin suggested? – Red Cricket Oct 26 '18 at 05:17
  • 1
    Add `2>&1` at the end of cron line to output errors to the log. You can also add `BEGIN {print "hello\n"}` at the beginning of the script to output something before script runs into an error. – UjinT34 Oct 26 '18 at 05:21
  • How long is the kadecut.pl script? can you post it? – Red Cricket Oct 26 '18 at 06:28
  • 2
    Possible duplicate of [CronJob not running](https://stackoverflow.com/questions/22743548/cronjob-not-running) – tripleee Oct 26 '18 at 07:33
  • Not enough detail in the question to provide an actual answer, but the answer to "it runs on the command line, but not under cron" is _generally_ that there's a difference in the environment (working directory, the user/group running it, environment variables, etc.) which causes the problem. – Dave Sherohman Oct 26 '18 at 07:46
  • Thank you guys the issue is now resolved – Riju Mukherjee Oct 26 '18 at 08:08

1 Answers1

0

Try to run the script (via crontab) with

/usr/bin/perl /u01/app/ecm2fs/deep/FS/kadecut.pl ...

It might be the shebang line isn't processed properly. Did you run your HelloWorld script as a Perl script or is it the .ksh one? Try to avoid any relative paths in the script, it will most probably break because the environment might be different for another user.

Surrogard
  • 101
  • 1
  • 6