1

I have an .sh file located at '/home/pi/startup.sh' which I want to have running soon after bootup. I have my crontab with the following information.

# m h dom mon dow user        command
17 *        * * *        root    cd / && run-parts --report /etc/cron.hourly
25 6        * * *        root        test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
47 6        * * 7        root        test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )
52 6        1 * *        root        test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )
0  0        * * *   root        reboot        
@reboot ( /bin/sleep 30; /home/pi/startup.sh > /home/pi/cronjoblog 2>&1)
#

And the .sh is

sudo mount -t cifs -o guest //◘◘◘.◘◘◘.◘◘◘.◘/Public /home/pi/wdmycloud
#
sudo mount -t cifs -o guest //◘◘◘.◘◘◘.◘◘◘.◘/Jared /home/pi/Jared
#
sleep 10
feh -Y -x -q -D 5 -B black -F -Z -z -r /home/pi/wdmycloud/SkyNetPhotos/

What am I doing wrong? The script, should start a picture slide show using picture from the drives. But nothing happened, even hours of letting it sit.

7
  • 1
    What am I doing wrong? Nobody knows because you're not telling us what the problem is. What does not work as expected?
    – Dirk
    Commented Mar 15, 2019 at 20:43
  • The script isn't running when system reboots.
    – user46629
    Commented Mar 15, 2019 at 20:45
  • How do you know the script isn't running?
    – joan
    Commented Mar 15, 2019 at 20:48
  • The script shown is to mount 2 disks from a wireless server that's on the network, and start a slideshow from a folder found on one of the drives.
    – user46629
    Commented Mar 15, 2019 at 20:50
  • How do you know the script is not running? You need to edit your question and include all relevant detail.
    – joan
    Commented Mar 15, 2019 at 20:53

2 Answers 2

1

You should consider putting your mount actions in /etc/fstab instead of an @reboot facility in your crontab.

Beyond that, some potential issues:

  1. Your mount commands look suspect. Try something like:
sudo mount //192.168.1.246/whatever /home/pi/somedir -o username=yours,rw,vers=1.0  

Refer to man mount for details on the options. And note in particular:

Mount options for cifs
       See the options section of the mount.cifs(8) man page (cifs-utils package must be installed). 
  1. You've cleverly added the stderr redirect, but you haven't shared with us what you found when you looked in your /home/pi/cronjoblog file... do you mind doing that?

  2. I'm guessing here, but your shell script may need either a shebang as the first line, or change your crontab line to make it clear you want it to run under the bash shell:

@reboot ( /bin/sleep 30; /bin/bash /home/pi/startup.sh > /home/pi/cronjoblog 2>&1)  
  1. And if none of that works, try using complete path specs in your .sh script; for example:

instead of: sudo mount ... , use /usr/bin/sudo /bin/mount ...

etc.

6
  • 1. I've added the line suggested to the fstab and yet nothing happened
    – user46629
    Commented Mar 18, 2019 at 12:48
  • 2. I've been trying to get this process to spit out a log to the conjoblog, but it still remains empty.
    – user46629
    Commented Mar 18, 2019 at 12:48
  • 2. I don't know what you mean by "shebang" I added it to the begging before "sudo mount" and it just tells me "shebang:not found. Mount error (16).
    – user46629
    Commented Mar 18, 2019 at 12:51
  • @user46629: Please use a search engine. If you Google shebang, you'll get answers like this one
    – Seamus
    Commented Mar 18, 2019 at 14:53
  • I feel really stupid now. And also mind blown about the concept of a shebang.
    – user46629
    Commented Mar 18, 2019 at 15:11
0

I would suggest you run your .sh script manually before putting it through the cronjob. You should also check the permissions for the file. I would just allow all users to execute the file :

sudo chmod a+x /home/pi/startup.sh

For the crontab file i think you can do it in this way :

@reboot sleep 10 && /home/pi/startup.sh
3
  • Script runs perfectly after system has booted up and I execute it via terminal
    – user46629
    Commented Mar 15, 2019 at 21:49
  • Good. Is the permission correctly set ? Try running the cronjob the way I posted. Commented Mar 15, 2019 at 21:50
  • I did the "sudo chmod a+x /home/pi/startup.sh" and nothing happened. I applied the changes to the crontab that you suggested and after 2mins of waiting, nothing.
    – user46629
    Commented Mar 18, 2019 at 12:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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