Home
04 December 2009 @ 11:34 pm

Originally published at Dom's Blog. You can comment here or there.

I often run applications on my laptop fullscreen, as I’ve mentioned before. Aside from a lastline configuration in screen, it is sometimes useful to be notified in a nice obvious manner when my laptop battery is getting low, so I created a bash script to use notify-send to display the percentage remaining on the battery when it is below a certain threshold.

battery indicator

There are two parts to this, the crontab entry which causes the script to be executed each minute, and the script itself, which obtains the value of the remaininng battery percentage, turns it into a bare number, and if it’s lower than a particular amount, it displays it.

Here’s the script code itself:

#!/bin/bash
percentage=$(yacpi -p | awk '{print $4}')
value=$(echo $percentage | sed -e 's/\%//')
if [ $value -lt 35 ] ; then notify-send -i battery "Battery $percentage" ; fi

In order to execute this each minute, edit the crontab with the command crontab -e and create a line with asterisks for each of the initial five fields describing which minute of which hour of which day in which month on which weekday it is to be run, followed by the path to the script; you can display the contents of your crontab with the -l option as shown here:

dominic@ubuntu-eee:~ $ crontab -l
# m h dom mon dow command
* * * * * DISPLAY=:0 /home/dominic/bin/gbattcheck
dominic@ubuntu-eee:~ $ cat bin/gbattcheck

Tags:
 
 
08 November 2009 @ 07:57 pm

Originally published at Dom's Blog. You can comment here or there.

Inspired by pages such as this one and this one, I decided to implement this as a one-liner which I can execute as a script:

while true ; do l2ping -c 4 00:12:D2:BA:B3:12 || gnome-screensaver-command -l ; sleep 10 ; done

Clearly it’s not a daemon, and it probably drains the battery of my phone by pinging it every ten seconds, but it works if I walk to the other end of the apartment. I guess it needs a bit of work, such as implementing my phone’s MAC address as a variable or stored in a file, but it’s nice and simple and demonstrates how it works quite nicely without all the surrounding script.

Tags:
 
 
09 October 2009 @ 03:24 pm

Originally published at Dom's Blog. You can comment here or there.

Rainbow prompt in Gnome Terminal

Since my workstation is called “rainbow”, I decided it needed an appropriate prompt. This is achieved within bash by setting the variable PS1 with lots of control-codes for the colours.

PS1="\[\033[01;32m\]\u\[\033[00m\]@\[\033[01;31m\]r\[\033[00;33m\]a\[\033[01;33m\]i\[\033[01;32m\]n\[\033[01;36m\]b\[\033[01;34m\]o\[\033[01;35m\]w\[\033[00m\] \[\033[06;36m\]\w\[\033[00m\] \$ "

Tags:
 
 
27 September 2009 @ 08:30 pm

Originally published at Dom's Blog. You can comment here or there.

Here is the screen configuration file I use on my laptop, it sets the window title, defines the status line showing how much battery remains and the clock, and a few other useful defaults.


Note: I tend to run the terminal fullscreen, so I can’t see the clock on the menubar

The variable termcapinfo determines the title of a window in which this screen session is viewed.

The three scripts defined as backticks are for the battery percentage remaining, time remaining and current temperature, these are included in the last line of the terminal using the syntax %1` for the first, %2` for the second and so on, the backtick after the number is part of the string.

The status line of screen is described by “hardstatus alwayslastline”, consisting of a list of each screen window and its title, with the current one hilighted cyan, followed by the backtick scripts and the data and time.

The final line increases the default number of lines in screen’s scrollback mode (C-a esc).


# Dom's .screenrc
termcapinfo xterm* hs:ts=\E]0;:fs=\007:ds=\E]0;\007

backtick 1 1 0 $HOME/bin/batt_perc.sh
backtick 2 1 0 $HOME/bin/batt_time.sh
backtick 3 1 0 $HOME/bin/temp.sh

hardstatus alwayslastline "%{= G}%-w%{.C}%n %t%{-}%+w %=%{..y} %1` %2` %3` %{..G} %H %{..c} %d/%m/%Y %0c "
defscrollback 1000
# end of file

The three scripts process the yacpi command’s output using awk:


dominic@ubuntu-eee:~ $ cat bin/batt_perc.sh
yacpi -p | awk '{print $4}'
dominic@ubuntu-eee:~ $ cat bin/batt_time.sh
yacpi -p | awk '{print $7}'
dominic@ubuntu-eee:~ $ cat bin/temp.sh
echo "`yacpi -p | awk '{print $16}'`\0260c"

Tags:
 
 
15 April 2009 @ 10:54 am

Originally published at Dom's Blog. You can comment here or there.

$ ssh root@hostname.example.com
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@    WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!     @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that the RSA host key has just been changed.
The fingerprint for the RSA key sent by the remote host is
f3:a9:fc:81:1e:24:09:94:5a:ed:cf:66:2a:3f:98:94.
Please contact your system administrator.
Add correct host key in /home/username/.ssh/known_hosts to get rid of this message.
Offending key in /home/username/.ssh/known_hosts:117
RSA host key for hostname.example.com has changed and you have requested strict checking.
Host key verification failed.

I regularly connect to systems which get reinstalled frequently and receive the warning above, so this option to the ssh-keygen command is particularly useful:

ssh-keygen -R hostname.example.com

It will remove the entry for that hostname in the file ~/.ssh/known_hosts

Tags: