Wednesday, 10 July 2013

New version of update-dnsomatic

I've had a change request for update-dnsomatic! A fairly sensible one, as it happens, to force updates even if the IP address hasn't changed.

There is a new parameter, force, in the config file to set the value in days, eg:

force=7

will force an update if /etc/update-dnsomatic/myip is older than seven days. The default value is 7.

You can download the new version (0.2.1) here.

Wednesday, 12 June 2013

Drop-in replacement for @big_ben_clock

Yesterday, @big_ben_clock announced it was going off-line for a while which was a shame as I like the hourly timestamp in my twitter stream.

I thought that I'd offer an identical service using my hardly-used @pwntter twitter account until such time as @big_ben_clock comes back on-line.

Code:  There's two bash scripts, one to generate the BONGs and one to tweet them using TTYtter.


#!/bin/sh
#bong
#bong n hours of the time (12 hour clock) mimicking @big_ben_clock

I=$(date +'%l')

for (( i=1; i <= $I; i++ ))
do
     echo -n "BONG "
done


#!/bin/sh
#bigben
#tweet bigben bongs while @big_ben_clock is down
TWEET=$(bong)
/usr/bin/ttytter -keyf="/home/prawn/.ttytterkeypwntter" -ssl=1 -norc -hold=5 -status="$TWEET"

Simply use cron to fire off the bigben script on the hour.

Wednesday, 16 January 2013

update-dnsomatic and dig

I have been using update-dnsomatic on my home server for some years now and it has worked well. Yesterday, I noticed that an update had 'worked' but the DNS entry had not propagated for some reason or other.

As a result of this, I have written a quick script that compares my public IP with a dig query which sends me a DM via twitter to let me know when they are different.

Files below: digip, cihip (Can I Haz IP), dmpr4wn

You need dnsutils (for dig) and a working copy of TTYtter for this to work.

Simply run digip every half hour or so and any discrepancy will be notified via twitter direct message.

Code:

#!/bin/sh
# digip
DIG=$(dig prawn.mooo.com | grep ^prawn.mooo.com | awk '{ print $5 }')
CIH=$(cihip)

if [ "$CIH" == "" ]
then
        echo "Public IP address is blank. Exiting."
        exit 1
fi

if [ "$DIG" == "" ]
then
        echo "DNS IP address is blank. Exiting."
        exit 2
fi


if [ "$DIG" != "$CIH" ]
then
       echo "Dig IP $DIG does not match public IP $CIH"
dmpr4wn "Dig IP $DIG does not match public IP $CIH"
else
echo "Dig IP $DIG matches public IP $CIH ok"
fi

###########################


#!/bin/sh
#cihip Can I haz IP
wget -qO - http://myip.dnsomatic.com/
echo

##########################

#!/bin/sh
#dmpr4wn
TWEET="/dm pr4wn"
ttytter -status="$TWEET $1" -hold

Sunday, 13 January 2013

Tweeting uptime

I thought I'd write a quick bash script to tweet uptimes for my machines using TTYtter.

It's a simple enough script which I intend to run once a week (so as not to pollute followers timelines).

So, here it is:

#!/bin/sh
#twuptime.sh
TWEET="Uptime for $(hostname) is $(date '+%d/%m/%Y') $(uptime)" 
ttytter -status="$TWEET"

Wednesday, 5 December 2012

ttytter daemon with systemd

Now that Arch Linux has made a permanent move to systemd, I thought I should write up a guide on how to start a ttytter daemon to allow you to log your timeline into a MySQL database using the pwntter extension. Of course, these instructions will work on any such system that utilises systemd.

Service configuration file


Create a file /etc/conf.d/ttytterd and put what ever arguments this instance of TTYtter needs to run as a daemon

# Settings for the TTYtter daemon.
TTYTTERDARGS="-keyf=/root/.ttytterkey -rc=/root/.pwntterrc -exts=/usr/local/bin/pwntter.pl -daemon -hold -backload=500"


Service file

 

Create a file /usr/lib/systemd/system/ttytterd.service

[Unit] 
Description=A TTYtter daemon
Requires=mysqld.service
After=mysqld.service

[Service] 
Type=oneshot 
RemainAfterExit=yes 
# Change the arguments in the file below to suit
EnvironmentFile=/etc/conf.d/ttytterd
ExecStart=/usr/bin/ttytter $TTYTTERDARGS 

[Install] 
WantedBy=multi-user.target 


Finally 

 

Enable and start the service.

systemctl enable ttytterd.service
systemctl start ttytterd.service


Further reading


ttytter documentation

pwntter documentation

Arch Linux systemd documentation

My stats page - warning, it's my home server and is as reliable as I am.




Not much to see, but here it is running automagically

Friday, 19 October 2012

cihip bash script

Just a quickie, I wrote a bash version of my Can I Haz IP script which does little more than display your public IP address by returning content from http://myip.dnsomatic.com. I use it more often than I imagined, so I thought I'd put a copy up here.

#!/bin/sh
#cihip Can I Haz IP?
IP=$(curl -sS http://myip.dnsomatic.com/)
echo $IP

Thursday, 26 April 2012

Your last tweets as mail .sig

Just a quick note. I was enjoying a bit of banter with some TTYtter users (Spanish division) the other day, when the subject of using cowsay with tweets came up. This led on to suggestions of updating one's mail sig with one's latest tweet.

So, here's my take on it using my pwntter database. It does little more that look for my last tweet that is not a reply (starting with @) or an RT (starting with RT) and writing a to a .sig file.

#!/bin/sh

SIGDIR=$HOME/.sig
SIGFILE=$SIGDIR/tweet.sig

if [ ! -e $SIGDIR ]; then

  mkdir -p $SIGDIR

fi

TWEET=`mysql -u pwntter -ppwntter -B -h localhost pwntter << EOF
  SELECT DATE_FORMAT(created_at, '%d-%m-%Y at %H:%i') AS cdate, text
  FROM tweets
  WHERE screen_name = 'pr4wn' AND text NOT RLIKE '^@|^RT\b'
  ORDER BY id DESC LIMIT 1
EOF`

echo -e "\nLast tweet by me [@pr4wn] on ${TWEET:11:19}\n" | tee $SIGFILE
cowsay -w -W 50 ${TWEET:31} | tee -a $SIGFILE



Sample output


Last tweet by me [@pr4wn] on 26-04-2012 at 07:47

 __________________________________________________
/ BLOG: TTYtter related again. Writing your latest \
| pearls of wisdom on twitter to a .sig file.      |
\ http://t.co/VuUvQ1SO                             /
 --------------------------------------------------
        \   ^__^
         \  (OO)\_______
            (__)\       )\/\
                ||----w |
                ||     ||

Simply run in crontab as frequently as you think sensible.