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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With