0

I am in day 5 of my crash course of learning how to use a Raspberry Pi (or any Linux platform) for the first time. I have an .sh named "startup.sh" file located at "/home/pi/". I have tried several different forums and nothing has helped. I just want this .sh to run at startup.

The script I have made, mounts 2 drives from a wireless home server, and once connect it starts a slide show from some pictures on drives using a screensaver method. I needed there to be a delay between connecting to the wifi before mounting the drives, and a few seconds before it starts the slide show (to allow the mounting process to happen). I've tried using the ./superscript in the .bashrc (accessed using sudo nano .bashrc). I've also tried using the crontab by adding "@reboot /home/pi/startup.sh" at the end. Here is what my crontab and script look like. Link

user46629
  • 11
  • 1
  • 6

1 Answers1

1

If your shell script runs from your command line as user pi, but DOESN'T run under cron, the two most likely reasons are:
1. Environment variables are different, typically the PATH: the cron user does not have the same environment as user pi does. You can easily overcome this by using a full path for all executables in your script.
2. Resources required in your script are not yet available when cron starts: cron does not know the status of services when it starts (for example, it doesn't know if the network is up). You can usually overcome this by using a brief sleep before executing your script.

You can help yourself by redirecting stderr for your script to a file. You currently have no visibility of error messages - a bit like driving with blinders on.

Also, make sure your script has an appropriate shebang line at the top so the system will know which interpreter to use.

Here's an example crontab entry that might work for you:

@reboot (/bin/sleep 30; /home/pi/startup.sh > /home/pi/cronjoblog 2>&1)

This will cause cron to sleep for 30 seconds before running your script. If you get any errors, they will be written to the file /home/pi/cronjoblog

Try this. Let us know if it still doesn't work, and we'll try to help you sort that.

Seamus
  • 23,558
  • 5
  • 42
  • 83