0

I'm trying to find any solution to this problem but for some reason I can't manage to make this work properly. The only thing I need is to run a .sh file located in the /home/pi folder.

I did it like this: 1. open terminal 2. sudo crontab -e 3. selected 2 (for /etc/nano) 4. I added at the end of the line: "@reboot /home/pi/Autorun.sh" 5. I created a file (/home/pi/Autorun.sh) and entered the following code:

#Mounts shared folder
sudo mount //<IP-Address>/<folderpath> /home/pi/shared -o username=<Username>,password=<Password>
  1. I added the execution rights with:
sudo chmod +x /home/pi/Autorun.sh
  1. reboot
  2. I check if the folder is mounted. Result = It's not.
  3. Running the script manually to check if it was the script which was not working. Result = Script works perfectly fine.
  4. Getting really disappointed and doing more research to find out where the problem is.

So now that I finally reached a very high level of disappointment I don't know what to try else then just throwing it out of the windows. Is anyone able to tell me how to fix the problem?

To give you some more details. I've downloaded the most recent version of Raspbian today the 04/18 version and installed it on the Raspberry Pi 3. The only things installed are a thightvncserver and xrdp. I've changed the keyboardlayout to german and expanded the filesystem already.

Solution

Here is the Solution for my problem.

@reboot sleep 30 && /home/pi/Autorun.sh

10
  • 1
    Why not put this mount into /etc/fstab?
    – stevieb
    May 1, 2018 at 16:47
  • 3
    of course, these days, it's far better to use systemd - see askubuntu.com/questions/919054/… - you then have fine control over when in the boot sequence your script will run May 1, 2018 at 23:37
  • 2
    What do you mean with "because that folder doesn't even exist". What folder? //<IP-Address>/<folderpath> or /home/pi/shared? Why do you try to mount a folder that doesn't exist? That will never work.
    – Ingo
    May 3, 2018 at 8:17
  • 1
    Is //<IP-Address>/<folderpath> a windows share? Have you tried fstab? Cronjob is not ideal for static auto mount!
    – Fabian
    May 3, 2018 at 21:20
  • 2
    @ingo I know I'm stupid but not as stupid enough to try to mount something that doesn't exist to a folder which also doesn't exist. No I meaned the folder /etc/fstab does not exist on the current version of Raspbian.
    – VarmintLP
    May 8, 2018 at 11:19

2 Answers 2

2

In crontab, you can setup logging by changing your crontab line so it reads:

@reboot /home/pi/Autorun.sh > /home/pi/AutorunLog.log 2>&1

Then, after crontab will save any output(and errors) to the file /home/pi/AutorunLog.log.

Check after boot to see if there are any errors in this file.

Also, you could try running sudo chmod a+x /home/pi/Autorun.sh (notice the added a)to give everything execution permission.

Lastly, try adding a delay(to make sure an internet connection is established) and text output(to make sure your script is running) to your script, like this:

sleep 10   #delay 10 seconds
echo "Mounting shared folder..."   #I'm not good at sh files, change this if it's not proper syntax...(it works, though.)
sudo mount //<IP-Address>/<folderpath> /home/pi/shared -o username=<Username>,password=<Password>
echo "mounted file."
2
  • thank you already for your help with the logging. It gives me an error message Network in unreachable which must refer to the fact that the Network might not be reached at that moment. So I just need to figure out how to run the script after a few seconds. ´sleep 30 && ´ should solve that problem. Will give a definet update later
    – VarmintLP
    May 8, 2018 at 11:38
  • thank you very much it helped. I only had to add sleep 30 && to the cronjob and it just immediatly worked.
    – VarmintLP
    May 8, 2018 at 11:50
1

Try this in your crontab file:

@reboot sudo mount //<reachable IP addr for SMB share>/<folder> ~/mntPassport<or, a LOCAL folder on your RPi> -o username=guest,password=,vers=1.0

I've found that the mount command has gotten all buggered up in stretch; I think because of some fuzziness at RPi.org

If all your shell file does is mount the drive, this will do it. If there are other tasks in your shell script, run it after you've mounted the drive as follows:

@reboot /bin/bash ~/Autorun.sh > ~/cronjoblog 2>&1

If it doesn't execute successfully, you'll get the stderr output in the file cronjoblog

Your Answer

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

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