Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does crontab take command line arguments? [closed]

I have written a code which moves .trc files from source directive to backup directive. Now I have taken time (how much time older), source path and backup path as command line arguments for this file. Now when I invoke the script from sh, it works fine. But in crontab it is not working, which left me wondering if crontab allows passing command line arguments or not. My sh command is :

sh trace_bkp.sh 2 /home/adhikarisubir/test/basic_unix /home/adhikarisubir/test_bkp

where 2 defines 2 minutes older files, next one is soruce path and the last one is target path. I set the same in crontab as:

*/5 * * * * sh /home/adhikarisubir/test/basic_unix/trace_bkp.sh 2 /home/adhikarisubir/test/basic_unix /home/adhikarisubir/test_bkp
like image 314
Mistu4u Avatar asked Dec 21 '14 20:12

Mistu4u


1 Answers

Yes, crotab lines can get arguments as the man page says so.

Most likely something goes wrong while calling that command that resides in the change of environment from your console to the not-a-console cron environment.

Usually its best to add logging functions to your cron line to get the output of whats happening.

*/5 * * * * sh /home/adhikarisubir/test/basic_unix/trace_bkp.sh 2 /home/adhikarisubir/test/basic_unix /home/adhikarisubir/test_bkp >> /home/adhikarisubir/test/basic_unix/cron.log 2>&1

Then read that log and you will see how it goes wrong.

like image 58
Angelo Fuchs Avatar answered Oct 29 '22 10:10

Angelo Fuchs