Skip to main content

Predictable failure - Tweeting with Python Part 2

·320 words·2 mins
tech debian iot linux python raspberry-pi raspbian technology twitter twython
James Pettigrove
Author
James Pettigrove
Cloud Engineer with a focus on Microsoft Azure
Table of Contents
Tweeting with Python - This article is part of a series.
Part 2: This Article

Part 1 of the series saw us signing up to Twitter and getting access to the API to send tweets, setting up Twython and developing out shutdown script. Now we will make our script executable and run it.

Run the Python script
#

With the script saved (CTRL+X then Y in Nano to exit and save) we first have to make it executable:

sudo chmod 700 TweetShutdown.py

With the script file executable by the file owner we can run it using:

python TweetShutdown.py

And if everything was done correctly, you will get something similar to this:

 

Alright, good start so far. But, we don’t want to be notified just when the Pi gets shutdown, we want to know if its going to restart and we want to know if it successfully started back up again.

The working guts of the script won’t have to change, so lets go ahead and make a couple of copies to perform the restart and startup verification respectively:

cp TweetShutdown.py TweetReboot.py
cp TweetShutdown.py TweetStartup.py

and let’s not forget to make them executable as before:

sudo chmod 700 TweetReboot.py
sudo chmod 700 TweetStartup.py

Next, go ahead and open up the two new script files and edit the following line to adjust the message that will be tweeted accordingly

tweet = "@DXPetti I'm going down #GALMPI "
Be mindful to keep the space at the end before the final quotation mark to separate the message and the date and time stamp.

So now we have 3 Python scripts, executable by the owner that will tweet out a time stamped message indicating a shutdown, restart and startup…

…but they currently have to be manually executed, which isn’t very helpful to our goal in having a hands off monitoring system. We will make use of the run levels system of Linux in the next part to have these scripts executed when the system is shutdown, restarted and started up.

Tweeting with Python - This article is part of a series.
Part 2: This Article

Related

Predictable failure - Tweeting with Python Part 1
·867 words·5 mins
tech bitcoin cryptocurrency debian iot linux python raspberry-pi raspbian technology twitter twython
As explained in a previous series of mine, I run a small Bitcoin mining operation on my Raspberry Pi.
Mining Bitcoins with Raspberry Pi - Part 3
·405 words·2 mins
tech bitcoin cgminer cryptocurrency debian iot linux raspberry-pi raspbian technology
Continuing on from the good work we have achieved thus far in Part 1 & Part 2, we are going to complete our Bitcoin Mining journey by making our Raspberry Pi start mining as soon as it is powered on.
Mining Bitcoins with Raspberry Pi - Part 2
·396 words·2 mins
tech bitcoin cgminer cryptocurrency debian iot linux raspberry-pi raspbian technology
In a previous post, we covered how to setup your Raspberry Pi with cgminer along with some USB ASIC mining hardware.