Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 4511

General programming discussion • [SOLVED]bash programming compare operation acting differently in crontab

$
0
0
Hello,

I was writing a script to check if wan ip address changed or not, if changed update the new ip to ddns and letting it run in cron. I saw different behaviors when the script is executed normal and in cron.

To explain the issue better plesae see below code snippet,

Code:

var1="a"var2="a"if [ "$var1" == "$var2" ]; then echo "same" >> /home/pi/test.logelse echo "notsame" >> /home/pi/test.logfi
When this script executed as normal (./script.sh) It will print "same" to /home/pi/test.log. If the script is executed in cron as below,

Code:

*/1 * * * * /home/pi/script.sh
Then it writes "notsame" to /home/pi/test.log .

I tested this in different raspberry pi versions in bash and every where same problem. All running raspbian latest.

Any thoughts?

Statistics: Posted by sim_tcr — Fri Nov 22, 2024 5:13 am — Replies 4 — Views 64



Viewing all articles
Browse latest Browse all 4511

Trending Articles