1

On Debian 8 after adding @reboot-line to crontab there are some strange results. All actions are performed by root.

crontab -l shows @reboot /root/startup.sh

startup.sh (+x rights):

#!/bin/bash
dhclient eth0
iptables-restore < /root/ipt
echo test > /tmp/startup.log

After reboot I can see in /var/log/syslog something like (root) CMD (/root/startup.sh) and there is word "test" in /tmp/startup.log. But dhclient and iptables did not work. If I run the script manually all three lines give the result (i.e. ip address is received and iptables are restored).

How do I make it work through cron?

  • 3
    Perhaps it's a matter of timing - shouldn't those kinds of things be done via the network service's pre-up / post-up hooks? – steeldriver Jun 18 '18 at 14:02
  • @steeldriver Indeed, it's most probably a matter of timing. But the main reason why I didn't use those hooks was that the interface is not configured via auto because it entails another problem: boot hangs about 15 secs on LSB job "raise network interfaces". So given this problem, neither cron nor hooks can help in such case? – red0ct Jun 18 '18 at 15:23
  • @reboot means "when cron is started". This may be before the network devices exist. – wurtel Jun 19 '18 at 9:56
  • @wurtel Not quite true about "cron is started", but "when it first starts". Cron looks at the existence of file /var/run/crond.reboot to check if it runs on actual reboot. But the question of the existence of network devices at cron's startup is still relevant, need to deal – red0ct Jun 19 '18 at 12:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.