bash - Can't read file content to variable via cronjob -
my program try read content of file in variable.
root@pi:/tmp> cat /bin/dnsupdate #!/bin/sh set -xv ip="$(cat /tmp/ip)" echo $ip exit 0 when run program in shell, works perfectly.
root@pi:/tmp> dnsupdate ip="$(cat /tmp/ip)" +/bin/dnsupdate:5> ip=+/bin/dnsupdate:5> cat /tmp/ip +/bin/dnsupdate:5> ip=92.192.52.164 echo $ip +/bin/dnsupdate:6> echo 92.192.52.164 92.192.52.164 exit 0 +/bin/dnsupdate:7> exit 0 now adding cronjob , logging script output.
root@pi:/tmp> crontab -l #m h d m w cmd * * * * * dnsupdate >>/tmp/dns 2>>/tmp/dns root@pi:/tmp> cat dns ip="$(cat /tmp/ip)" +/bin/dnsupdate:5> ip=+/bin/dnsupdate:5> cat /tmp/ip +/bin/dnsupdate:5> ip='' echo $ip +/bin/dnsupdate:6> echo exit 0 +/bin/dnsupdate:7> exit 0 also tried #!/bin/zsh shebang since default shell zsh , stuff ip=$(</tmp/ip) still no luck. why there no content in variable when script runs via cron?
Comments
Post a Comment