Skip to main content

Posts

Showing posts from July, 2014

I made a GIF!

Debian package (deb) archive extract

Had to extract multiple Debian packages recently (*.deb).  The packages are compressed with "ar" a Unix utility that maintains groups of files as a single archive file.  The ar command, like cpio, is less commonly used and even less friendly.  To extract only the Debian package data, excluding metadata), run: # for DEB in `ls *.deb`; do ar p $DEB data.tar.gz | tar -xzf - ; done or use the Debian package utility... # for DEB in `ls *.deb`; do dpkg-deb -x $DEB ./ ; done

Handling shell script command line arguments with getopt and case

Below is a short BASH scripting example how to use getopt and case together and provide better script command line argument handling than simple if-then-else.  It accepts out of order arguments, multiple methods for the same argument (short and long), and ignores unrecognized arguments. The script itself writes a ISO formatted date and time stamp to a file.  The default options for the number of iterations (count), the interval between iterations (sleep) and the output  file (write) can all be specified from the command line when running the script. #!/bin/bash usage () { echo -e "Usage: tick.sh [-c #] [-s #] [ -w FILE ]" echo -e "\t\t -c, --count= \t count for iterations to run (integer, default infinite)" echo -e "\t\t -s, --sleep= \t sleep between iterations (integer, default 5)" echo -e "\t\t -w, --write= \t write output to file (file system path, default ./tick-ISODATETIME.log)" echo -e &q