First of all I'm not sure whether I should post it here or under the Ubuntu-specific forum but I thought this is probably a more generic question.
I have a Raspberry Pi 3 with Raspbian Jessie, I wrote a script to send a push to my Pushbullet account to tell me everytime it starts.
First I made a bash script, tried to get it to work for several hours. It worked if I executed the script manually, but nothing happened on reboot. So I wrote the same script but in Ruby instead, which gave me the same result; it worked on manual execution but not with cron on reboot.
I got it to work by adding a sleep command for 10 seconds before executing the script. However, I would like to know why it is not working without sleep. Could it be that crontab executes my script before my RaspberryPi 3 has acquired internet access?
This is my script in BASH
#!/bin/bash
current_time=$(date "+%Y-%m-%d %H:%M:%S")
STATUS=$(curl --header 'Access-Token: '<ACCESS TOKEN>' --header 'Content-Type: application/json' --data-binary '{"body":"RaspberryPi 3 started at '"$current_time"'","title":"RaspberryPi 3 started","type":"note"}' --request POST https://api.pushbullet.com/v2/pushes)
echo $STATUS >> log.log
exit 0
The same script in Ruby with Washbullet gem
require 'washbullet'
client = Washbullet::Client.new('<ACCESS TOKEN>')
timenow = Time.now.strftime("%Y/%m/%d %H:%M")
client.push_note(
receiver: :device,
params: {
title: "RPi3 started",
body: "RaspberryPi 3 started at #{timenow}"
}
)
Edited cron with crontab -e looks like this:
@reboot /home/pi/bin/pushbullet.sh
or
@reboot ruby /home/pi/bin/pushbullet.rb
These cron only works if i prepend with "sleep 10;" i.e:
@reboot sleep 10; /home/pi/bin/pushbullet.sh
Thankful for any help,
Mattias