Tuesday, December 7, 2010

Script for Cronjob to Check for a Full Disk

I found a nice script on the Ubuntu forums (I think) for checking if a Linux system had a full disk and then sending an email if that was the case. I adapted it a little bit to provide more information in the case that /home is full. I'm posting it here in case anyone were to find it useful.

#!/bin/bash
#set -x

TO_ADDR=email@address.com
THRESHOLD_PERCENT=85
OUTPUT_FILE=`/root/cron/tempfile`

df -H | awk '!/^Filesystem|tmpfs|cdrom|AFS/ { gsub(/\%/,"",$5); print $5,$1,$6}' | while read line
do
    eval $(echo "$line" | awk '{print "PERCENT_FULL="$1";DEVICE="$2";MOUNT_POINT="$3}')
    if [ $PERCENT_FULL -ge $THRESHOLD_PERCENT ]; then
        (
        echo -e "On $(hostname), the mount point $MOUNT_POINT is $PERCENT_FULL% full.\n"
        echo "df --human-readable shows:"
        df --human-readable $DEVICE
        if [ "$MOUNT_POINT" == "/home" ]; then
            du --one-file-system --summarize --human-readable ${MOUNT_POINT}/* > $OUTPUT_FILE
            echo -e "\nHere is the disk usage by directory listing, sorted from greatest to least."
            for directory in `du --one-file-system --summarize ${MOUNT_POINT}/*  | sort --reverse --numeric-sort --key=1 | awk '{print $2}'`
            do
                grep "$directory" --word-regexp $OUTPUT_FILE
            done
        fi
        ) | mailx -s "ALERT: $MOUNT_POINT on $(hostname) is $PERCENT_FULL% full" $TO_ADDR
    fi 
done
rm -f $OUTPUT_FILE

Friday, November 12, 2010

Python and Condor

I wanted to see if I could run Python 3.x under Condor as a vanilla job. It seems to work fine. Here's what I did:

1. Built Python and tarred it up:

export PATH=/usr/bin:/usr/sbin:/bin:/sbin
export INSTALL_DIR=/scratch/mick/src/python-3.1.2-x86_64-rhel5
mkdir -p $INSTALL_DIR
wget http://python.org/ftp/python/3.1.2/Python-3.1.2.tar.bz2
tar xjf Python-3.1.2.tar.bz2
cd Python-3.1.2
./configure --prefix=$INSTALL_DIR
make install
cd $INSTALL_DIR/lib/python3.1/lib-dynload
ldd *.so | \
grep '/usr/' | \
gawk '{print $3}' | \
sort -u | \
while read n; do cp $n $INSTALL_DIR/lib; done;
cd `dirname $INSTALL_DIR`
tar czf python-3.1.2-x86_64-rhel5.tar.gz python-3.1.2-x86_64-rhel5

2. Created a wrapper to extract the tarball and run python. I called my wrapper 'python3'

#!/bin/bash

VERSION=python-3.1.2-x86_64-rhel5
export LD_LIBRARY_PATH=./$VERSION/lib

/bin/tar xzf ./$VERSION.tar.gz
exec ./$VERSION/bin/python3 "$@"

3. Submit your job.

universe                = vanilla
executable              = python3
arguments               = hello_world.py
should_transfer_files   = yes
transfer_input_files = hello_world.py, python-3.1.2-x86_64-rhel5.tar.gz
when_to_transfer_output = on_exit
output                  = condor.out.$(CLUSTER).$(PROCESS)
log                     = condor.log.$(CLUSTER).$(PROCESS)
error                   = condor.err.$(CLUSTER).$(PROCESS)
queue

Friday, November 5, 2010

Oh man.

I've wanted to be able to view man page source files, but I had trouble looking up how to do that (the search terms are kind of generic). So, if you'd like to view and/or format raw man page source files, the following is probably sufficient:

nroff -man manpage_source_file.1 | less

Sunday, July 18, 2010

Logitech MX 5500 on Linux in USB mode

So, I didn't want to use the Bluetooth mini receiver, and wanted to use my wireless keyboard and mouse in the USB mode (no OS bluetooth support needed; everything is done in hardware). All I had to do was comment out the lines related to Logitech devices in:
/lib/udev/rules.d/70-hid2hci.rules

After that, I was able to use mx5000-tool to change a few of the LCD screen views. Not to mention, I can remap CAPS LOCK to CTRL and it won't beep each time I press it. Whatever.

Friday, July 9, 2010

manipulating pdfs with pdftk

I've been downloading some PDF articles that I wanted joined together for duplex printing purposes. While Ghostscript can join PDFs quite well, pdftk is a great tool for removing pages that I didn't want to keep (before joining). Linux.com has a good article to get started.

I specifically wanted to remove the last page of each of my documents. To remove the last page, I needed to know how long the document was:

$ pdftk article.pdf dump_data output | grep NumberOfPages
NumberOfPages: 132

Then I can use the "cat" function of pdftk to create a new PDF minus the last page. Then, I can merge all the documents. I should probably write a bash script for this.

Tuesday, June 22, 2010

fix for cups socket printing in Debian GNU/Linux 6.0 testing

I couldn't print to a Dell M5200 printer and found that I was getting a socket error. I was able to telnet to the printer, so it wasn't my network connection... It turns out it was a permissions problem. This bug thread for Ubuntu seems to have more.

https://bugs.launchpad.net/ubuntu/+source/cups/+bug/596611

Thursday, June 17, 2010

slime and sbcl with Debian 6.0 testing

I had some trouble getting slime to work with Debian 6.0 testing using sbcl. This page had the answers. It might not be ideal, but it's working for right now.

Thursday, June 10, 2010

Adding a screensaver to Ubuntu 10.04

I wanted to add a simple screensaver that had a floating SVG of the Condor project's logo. You can download the SVG file here.

  1. sudo cp condor_logo.svg /usr/share/pixmaps
  2. cd  /usr/share/applications/screensavers
  3. sudo cp footlogo-floaters.desktop condor-floaters.desktop

  4. sudo vim condor-floaters.desktop
    [Desktop Entry]
    Name=Floating Condor Logos
    Comment=Bubbles the Condor logo around the screen
    Exec=/usr/lib/gnome-screensaver/gnome-screensaver/floaters /usr/share/pixmaps/condor_logo.svg
    TryExec=/usr/lib/gnome-screensaver/gnome-screensaver/floaters
    StartupNotify=false
    Terminal=false
    Type=Application
    Categories=GNOME;Screensaver;
    OnlyShowIn=GNOME;
    
    
  5. sudo /usr/share/gnome-menus/update-gnome-menus-cache /usr/share/applications > /tmp/desktop.en_US.utf8.cache
  6. diff /usr/share/applications/desktop.en_US.utf8.cache /tmp/desktop.en_US.utf8.cache
  7. Make sure the diff looks like what you expect
  8. sudo cp /tmp/desktop.en_US.utf8.cache /usr/share/applications/desktop.en_US.utf8.cache

Thursday, April 15, 2010

improving blackboard backups with condor

I just saw a fantastic presentation on how to speed up slow Blackboard backups using Condor. I don't use the software personally, but I know it is big at a number of colleges. You can see the presentation here.

Thursday, April 8, 2010

fvwm keybindings using the Windows key

Had I known that the Windows key is simply modifier 4 under FVWM 2, I would have been a lot happier with it. Here is an example:

Key  Q        A  4 RaiseLower

Thursday, March 18, 2010

Strawberry Perl

I just hate Microsoft Windows. But, that's where the man pays me to work. When I had to install Perl, I disregarded ActivePerl in favor of the less corporate Strawberry Perl. It works delightfully!

I used it to convert Hot 108 Jamz WinAmp PLS playlist to an M3U playlist for Windows Media Player (don't ask me why... I forget). I used the scripts from the Linux Lighting Group found here.

Wednesday, March 3, 2010

Fade To Black

I used ImageMagick to create a TGA sequence that faded from black to a logo, and then from the logo back to black. This is the gist of my Python script:


 for i in range(0, 101, 2):
  os.system('composite -dissolve %d logo.tga black.tga %03d.tga' % (i,  (i / 2)))