I want to run a script on startup that establishes a GRE tunnel. The script works fine if I just run /root/tunnel.sh after rebooting, it runs and establishes the tunnel. Below are the contents of my crontab -e for root user on my machine.

@reboot sleep 15; /root/tunnel.sh

Am I missing something?

I'm running CentOS 7 if that helps.

  • 2
    Start by adding logging like this @reboot sleep 15; /root/tunnel.sh >> /tmp/some.log 2>&1 reading that log will give you a clue – Tagwint Mar 22 '18 at 18:17
  • 2
    does /root/tunnel.sh rely on any shell variables (or activities) performed by your login shell? Is the correct she-bang line at the top of it? – Jeff Schaller Mar 22 '18 at 18:20
  • You're not mentioning what happens when the cronjob runs. Do you get an email with any error messages from the cron daemon? – Kusalananda Mar 22 '18 at 19:00
  • @Tagwint I made it log the action and the log tell me /root/tunnel.sh: line 2: ip: command not found Does this just mean I'm not waiting it long enough or what? Since the commands work fine if I execute the script from the bash terminal or if I paste all the commands from it one by one – Tundral Mar 22 '18 at 19:11
  • @JeffSchaller I didn't have the she-bang on the top of the script but I added it now and did what Tagwint told me to do to log the output of the script. since it outputs what I posted in the above comment I presume it's not a problem with variables or activities done by the shell. – Tundral Mar 22 '18 at 19:15

/root/tunnel.sh: line 2: ip: command not found

Your root login profile (one of ~/.bash_profile, ~/.bash_login, or ~/.profile) is setting $PATH to include /usr/sbin, while your (non-login) script is not setting $PATH to include /usr/sbin.

Either expand $PATH in your script or use full paths to programs that are in /usr/sbin.



/usr/sbin/ip ...
  • I have another @reboot cronjob for a script, but unfortunately that doesn't work either. The script looks like this: #!/bin/sh cd /home/mc/mc/ while true do java -Xms10G -Xmx10G -jar spigot.jar echo done sleep 3 done (sorry for it not being properly formatted the comments don't seem to support the code block formatting) And the log I set up for it just shows: Must be connected to a terminal. – Tundral Mar 22 '18 at 20:02
  • Sounds like it might be a new question! – Jeff Schaller Mar 22 '18 at 20:12

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.