msgbartop
A cronological documentation test project, nothing serious, really!
msgbarbottom

02 Dec 2011 Grab several screenshots from specified window in linux

This was a short bash script I wrote to help document some startup problems on a server.
The script was grabbing screen dumps from iDRAC during boot on a RHEL6 server, but it can be used on other distributions as well since the console command xwd is common.

#!/bin/bash
# Description:
# Grab screenshot of a specified X-window and wait X-seconds

# Use xwininfo to find the Window id to the window you are going to
# grab screenshots from.
xwininfo="0x4c0001a"

# filename for output
outfile="outfile-"

# seconds sleep between grabs
sleeping=2

padding="000" # put as many padding zeros as you want on filename
for ((i=0; i<1000; i+=1))
do
        # Perform the actual screenshot grab
        xwd -id $xwininfo -out $outfile-${padding:${#i}}$i.xwd

        # Convert the xwd file to a better image format like PNG
        convert $outfile-${padding:${#i}}$i.xwd $outfile-${padding:${#i}}$i.png

        # Delete the converted XWD-file
        rm -f $outfile-${padding:${#i}}$i.xwd

        # wait
        sleep $sleeping
done

Stop the script after you have grabbed enough screenshots.

I ended up with several files named outfile-000.png outfile-001.png ...
Deleted those files that were not needed and sent the images a documentation of the booting process.

Tags: , , , ,

Posted by

10 Sep 2010 Randomize filenames

This is a simple bash script to create random filenames of all jpg-files (*.jpg) in a folder using the linux commands mv, sha1sum and cut.

#!/bin/bash
# Randomize filenames

for fname in *.jpg;
do
        mv "$fname" $(echo "$fname" | \
                sha1sum | \
                cut -f1 -d ' ' | \
                cut -b 1-5).jpg
done

The jpg-files can have names like

08df4.jpg
1e788.jpg
315e6.jpg
41e19.jpg
5f7d0.jpg
7471e.jpg

Tags: , , ,

Posted by

23 Jan 2009 Copy files using tar

This is a oneliner to copy files from current directory to another target directory using tar, preserving file attributes, dates etc.

#!/bin/sh

fromdir=/path/from
todir=/path/to/target

echo "cd $fromdir; tar cf - . | (cd $todir; tar xpf -)"

cd $fromdir; tar cf - . | (cd $todir; tar xpf -)

Tags: , ,

Posted by

21 Jan 2009 IP address change notifier script

This is a simple bash script that is run by crontab every 5 minutes on a linux box.
It e-mails me the new address when a change of IP address is detected.

The script (ipchangemail.sh)

#!/bin/bash 

# Check if IP-address has changed. If a change has occured, mail me the new address
# Add the following line to crontab if you would like it to be run every 5 minutes:
# */5 * * * * ./ipchangemail.sh

# The network interface I want to monitor
NET_INTERFACE=eth0

# File to keep the latest IP address
IP_FILE=myip.txt

# Mail to this address when a change occur
MAILTO=mail@example.com

# Read the previous IP address from file
source $IP_FILE

CURRENT_IP=`/sbin/ifconfig $NET_INTERFACE | sed -n "/inet addr:.*255.255.25[0-5].[0-9]/{s/.*inet addr://; s/ .*//; p}"`

if [ "$CURRENT_IP" != "$OLD_IP" ]
then
        # Send email about address change
        `echo "New IP address detected: $CURRENT_IP" | mail -s "New IP address" $MAILTO`

        # Write new address to file
        `echo "OLD_IP=$CURRENT_IP" > $IP_FILE`
fi

The script can be downloaded here.

Tags: , , ,

Posted by

24 Oct 2008 Rename file name suffix to uppercase or lowercase

This is a little oneliner to rename a files suffix from/to uppercase/lowercase.

Rename a jpg suffix to JPG in the current folder

# find -name "*.jpg" | while read a; do mv "$a" "${a%%.jpg}.JPG" ; done

The work JPG can be replaced by any other word :)

Tags: , , ,

Posted by