-1

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

maetthew
  • 1
  • 2
  • Running curl without the `--silent` switch (and possibly with increased verbosity) should result in more usefull logging. – HBruijn Sep 28 '16 at 14:57
  • Sorry, I left "--silent" in after I tried something. However there is no change without "--silent", the log is still empty. I updated the post. – maetthew Sep 28 '16 at 15:01
  • The ubuntu specific forum would be better. RPi is not topical heer. – user9517 Sep 28 '16 at 17:12

1 Answers1

1

It could be and probably is a lack of network access, but it's hard to known when your log is likely to be empty the whole time. Add a -v to curl and redirect standard err to standard out (2>&1) and you should have a better idea of what's going on. Also, depending on how cron is sent to mail, you may want to check the users mail spool, or their home directory for dead.letter.

If you want to do this "right" you'll write a oneshot service with dependency on the network being up, rather than relying on cron for this.

84104
  • 12,698
  • 6
  • 43
  • 75
  • Sorry, the "--silent" was left in after I tried something. Without silent the log is still empty. Edited my original post. Hmm never heard of a oneshot service. Will have to look into that. – maetthew Sep 28 '16 at 15:00