0

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.

6
  • 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 Commented Mar 22, 2018 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? Commented Mar 22, 2018 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? Commented Mar 22, 2018 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 Commented Mar 22, 2018 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. Commented Mar 22, 2018 at 19:15

1 Answer 1

1

/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.

PATH=$PATH:/usr/sbin 

or

/usr/sbin/ip ... 
2
  • 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. Commented Mar 22, 2018 at 20:02
  • Sounds like it might be a new question! Commented Mar 22, 2018 at 20:12

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.