ANSWER # 1:
In looking at your script, I see a potential issue in the use of
sudo. You may get away with this in Raspbian, but you won't in many other distributions (distros). This is due to the fact that a
sudo typically demands authentication, and if you're running this at startup, you won't see the prompt.
The meaning of your comments in the script are not clear to me; e.g. "#I can't see this" - huh???
Also - the location of your script:
/home/monitor.sh?!?! I don't think you should put a script in
/home! Put it in
rc.local file you have:
You've got a shebang in your script:
#!/bin/bash that specifies
bash. I don't believe you need it again in front of your script name.
You've specified the location of your script in
/home/press.sh Really? Is that where it is? or, is it in
ANSWER # 2:
I don't think placing your startup script in
rc.local is your best move. I'm not saying it can't be made to work, but it may be more difficult than it need be. This page from the "official" documentation says (more or less) the same thing.
rc.local usage is now being deprecated in all Linux distributions in favor of
systemd - a more rational, reliable and predictable approach. If you're just starting in Linux, I don't feel you'll be handicapped if you never learn to use
rc.local. Here are some good references on
systemd: 1, 2, 3.
Don't be intimidated by all of this documentation - learning is a process, so proceed at your own pace. But learning comes from doing more than reading, so I'd encourage you to read a little, try a little, read a little more, etc, etc.
ANSWER # 3:
In the meantime, there is a third alternative to starting your script at boot time:
cron. It is much easier to use than
systemd, and you should be able to get your script running with very little research. I will assume that you are running as user
pi, and that you can get away with using
sudo in a script without authentication. Here's the approach in a nutshell:
- From the command line as user
pi, enter the following:
You may be prompted at this point to choose an editor. I'd recommend sticking with an editor named
nano. If you don't wish to use
nano, choose an editor, and designate it in the
export line above.
When your (pi's)
crontab is opened, add the following line to the bottom of the file:
@reboot (/bin/sleep 30; /home/pi/press.sh >> /home/pi/cronjoblog 2>&1)
Let's break this down:
crond to run this job at boot time
/bin/sleep 30 => waits 30 seconds before launching
press.sh; gives the system time to gather all resources needed (networking, etc)
/home/pi/press.sh => launches your script
>> /home/pi/cronjoblog 2>&1 redirects all output (incl
2)) to a file - so you can see what happened!
Try this. If it doesn't work, edit your question to include some details & we'll help you troubleshoot.
ANSWER # 4:
As a new Linux & RPi user, one of the first things you should practice is using the documentation. However, this is a bit of an art because:
- documentation and software aren't always in sync,
- because different Linux distros do things differently,
- and because, well - some people are a bit sloppy when it comes to documentation.
But the only way to overcome this is through experience. Everyone needs help from time to time - don't hesitate to ask for it. BUT: Make an effort to help yourself FIRST.
I feel the first stop in documentation is the system manuals; e.g.
man crontab (from the command line, btw) would be a reasonable first step in this case. You can even check out
man man to learn about the system manuals! You may not get all of your questions answered there, but you'll be able to ask more intelligent questions!