2

I have a problem with a script not working when executed via crontab. I've already searched for similar problems, but none of the usual solutions seem to work. I'm using a RPi3 with raspbian stretch to run a seafile server with mysql and nginx.

The script is quite simple, it enables (outgoing) internet access (adding some IP6Table rules), starts a curl request to update my IPv6 address (DNS service) and disables (outgoing) Internet access again (deleting IP6Table rules again). Obviously, I deleted the correct login data in the code below but in my copy, it's there. (sleep 2s only for testing purposes):

#!/bin/bash
bash /root/scripts/enable_internet_access.sh
sleep 2s
echo "Starting curl request"
/usr/bin/curl -v "https://Host-ID:PW@v6.members.feste-ip.net/nic/update?hostname=Host-URL" > /root/scripts/curllog
echo "curl done"
sleep 2s
bash /root/scripts/disable_internet_access.sh

I'm calling it with a simple (root) crontab entry, added via sudo crontab -e command:

*/30 * * * * /root/scripts/updateip.sh > updiplog

I've made sure that the crontab file has an empty line as its last line.

Now if I'm looking at the logfiles, updiplog often only contains "Starting curl request" but not "curl done", although it seems to run completely since outgoing internet access is forbidden, which indicates it runs the last script. Also, the curllog is empty. However, when started manually, everything works fine and curllog contains the correct response (usually ip still valid/no change and the ip itself).

Usual solutions seem to be:

  • using full path for curl, which I've done
  • considering changed environment variables (especially path), but this shouldn't be an issue here?
  • ensuring that crontab ends with an empty line
  • setting correct user rights. All scripts have 755 rights with owner root:root.

I'm rather new to linux / raspberry, so maybe I'm missing something obvious here?

  • Hi Chris, and welcome to the Raspberry Pi stackexchange Q&A! The question you have is actually not specific to the RasPi, but to Linux in general. Take a look over in the Unix & Linux stackexchange (unix.stackexchange.com/questions/344861/…). I think you might find what you need there much more quickly. Good luck in your quest! – MrChips Nov 29 '17 at 8:36
  • 2
    You say you have given full paths but you haven't. updiplog is relative to the current working directory, wherever that might be. Have you also given the full paths within the .sh files you are using? – joan Nov 29 '17 at 10:42
  • I suspect @joan is right, above. You could probably get better information by logging both the standard output AND the standard error from your script. The way to do this is to redirect standard error to standard output, and it's so common in Unix that it can be done in a few characters. My similar cron jobs look like this: 13 0 * * * /home/tai/bin/tokeep.sh > /home/tai/log/tokeep.log 2>&1 If that's unclear in the formatting, just add 2>&1 to the end of the line so your log gets error messages too. Good luck! – Tai Viinikka Nov 29 '17 at 14:56

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.