Automate shutdown during thunderstorm warning script

Forum rules
Before you post please read this

Automate shutdown during thunderstorm warning script

Postby Habitual on Mon Aug 01, 2011 1:20 pm

Inspired by viewtopic.php?f=90&t=78069 I set out to help another member come up with a "Severe Thunderstorm shutdown script".
Rather than re-invent the wheel, I decided that conkyForecast can help us achieve the desired result.
Here are the instructions:

Install and configure conkyForecast.I have Version: 2.20 installed and this works just fine.
Although you can install a later version. You do NOT need to install conky.

Step 1: Install conkyForecast
Code: Select all
sudo add-apt-repository ppa:conky-companions/ppa
sudo apt-get update
sudo apt-get install -y conkyforecast
cp /usr/share/conkyforecast/conkyForecast.config ~/.conkyForecast.config


Step 2: Register at http://www.weather.com/services/xmloap.html
Register and get your XOAP* codes. They will be emailed to you.
You will need these to use the conkyForecast script and the values you receive from this registration will need to be entered into your ~/.conkyForecast.config file.
The fields are
XOAP_LICENCE_KEY= and
XOAP_PARTNER_ID=

Step 3: Edit the sudoers file (add your username to the "allow" list for the halt command)
Code: Select all
sudo visudo

I inserted the command just like this in the file here:
Code: Select all
# Allow members of group sudo to execute any command
# (Note that later entries override this, so you might need to move
# it further down)
%sudo ALL=(ALL) ALL
jj ALL=NOPASSWD: /sbin/halt

substitute jj for your actual username
save and exit the visudo comand.

Step 4: Create this script:
Code: Select all
#!/bin/bash
# Author: Habitual
# Date: Mon 01 Aug 2011 01:11:15 PM EDT
# Requirements: conkyForecast

forecast=`echo $(/usr/share/conkyforecast/conkyForecast.py --location=USWI0244 --d CT)`
if [ "$forecast" = "Severe Thunderstorm*" ] ; then
sudo halt
else
exit 0
fi

Save and exit. > Terminal >
Code: Select all
chmod 700 /path/to/script.sh

NOTE: Your "USWI0244" code will be different depending on your Registration details at http://www.weather.com/services/xmloap.html

Step 5: Create a cron AS YOU (to execute the script you created in Step 4)
This cron will run every minute of every day
terminal >
crontab -e
*/1 * * * * /path/to/script.sh

NOTES:
Your "USWI0244" code will be different depending on your Registration details at http://www.weather.com/services/xmloap.html
You do NOT need to install conky.
The conkyForecast script instructions
Sudoers - Ubuntu Documentation

Later, if cron gets "too noisy" about blah blah blah,
just change "*/1 * * * * /path/to/script.sh" to "*/1 * * * * /path/to/script.sh >/dev/null 2>&1"
in your crontab (crontab -e)

I might have missed something, but this will get you most of the way there.

Enjoy.
What's a landing but a take off in reverse?
My DorkBlog
User avatar
Habitual
Level 8
Level 8
 
Posts: 2136
Joined: Sun Nov 21, 2010 8:31 pm
Location: Undecided

Linux Mint is funded by ads and donations.
 

Return to Scripts & Bash

Who is online

Users browsing this forum: No registered users and 2 guests