According to https://unix.stackexchange.com/a/478636/674, cron modifies the execution environment to execute a job.
When I run
sudo service tor reload
twice 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.00
Is it correct that
sudo service tor reload
will 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.log
every 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 20
between 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.log
As a cron job, why does
sudo service tor reload
fail to change the IP address? How can I make it work?
Thanks.
tim
to 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:20sudo
fails, 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 astim
and then usingsudo
to runservice tor reload
as root anyway. – Stephen Kitt Nov 01 '18 at 14:51sudo
never 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