According to https://unix.stackexchange.com/a/478636/674, cron modifies the execution environment to execute a job.
When I run
sudo service tor reloadtwice directly in bash, it always shows two different IP addresses$ sudo service tor reload; torsocks curl ipinfo.io/ip; sudo service tor reload; torsocks curl ipinfo.io/ip 12.345.678.901 987.654.321.00Is it correct that
sudo service tor reloadwill most likely change tor exit node, and thus change the public IP address?But when I create a cron job in
/etc/cron.d/myjob,* * * * * tim (sudo service tor reload; torsocks curl ipinfo.io/ip; sudo service tor reload; torsocks curl ipinfo.io/ip) > /tmp/cron.logevery time I check
/tmp/cron.log, it always shows two identical IP addresses, although the IP address changes from job to job (when the next scheduled job overwrites the log, it will show two identical IP addresses not identical to the two before overwriting). Same when I insertsleep 20between the two reload:* * * * * tim (sudo service tor reload; torsocks curl ipinfo.io/ip; sleep 20; sudo service tor reload; torsocks curl ipinfo.io/ip) > /tmp/cron.logAs a cron job, why does
sudo service tor reloadfail to change the IP address? How can I make it work?
Thanks.
timto run the cron job, while the cron job contains sudo? Will the sudo command fail because there is no way to provide the root password? – Tim Nov 01 '18 at 04:20sudofails, then the service won’t restart at all. You could try running the job as root withoutsudo, I’m not sure what the benefit is of running astimand then usingsudoto runservice tor reloadas root anyway. – Stephen Kitt Nov 01 '18 at 14:51sudonever asks for a password when run as root — I thought this was configurable, but it doesn’t seem to be. – Stephen Kitt Nov 01 '18 at 15:26sudo service tor reload; torsocks curl ipinfo.io/ip? – Tim Nov 01 '18 at 23:50