get variable value not working in cron job
Hello All,
I am running script below to get default route CURRENT_GW="$(ip route show | grep default | awk -F' ' '{print $3}')" and run echo ${CURRENT_GW} then it shows correctly.. now I try to put it into a script (test.sh) CURRENT_GW="$(ip route show | grep default | awk -F' ' '{print $3}')" echo "${CURRENT_GW}" >> /tmp/mytest but it shows empty what happen with this?.. could any body please help? thanks a lot in advance REgards Win |
you would need to insert set -xv at the beginning of the script and save all the stdout and stderr of it (and check it).
so in the cronjob you can do something like this: * * * test.sh >/tmp/test.stdout 2>/tmp/test.stderr You will surely find the reason. I think ip/grep/awk could not be found, you need to use them with full path, but I'm not really sure about that. |
Generally, the $PATH setting inside cron is minimal to say the least. Best practice is to either
1. use full paths to ALL cmds & files used 2. start by setting up the correct PATH value before doing anything. Ensure you are in the right dir as well; cron does not login in the normal sense |
Thanks all
Its works now by adding full path of them |
All times are GMT -5. The time now is 11:17 PM. |