Yeah, so I go through the trouble to write a script, to solve a problem which has already been solved. Still a fun exercise, if not exactly necessary.

Rather than using my script, most of the time I’d probably be using “exiv2″, which, like “exiftags” is packaged for Debian (apt-get it) and is a great little utility that can modify exif and do other useful things, including rename files based on exif date. To rename a file using YYYY-MM-DD_HH-MM-SS.currentname format:

1
exiv2 -r '%Y-%m-%d_%H%M%S_:basename:' rename myfile.jpg

Read the rest of this entry…

Script takes existing jpeg images, extracts exif date, constructs a new file name YYYY-MM-DD_HH-MM-SS.currentname, then sorts into subfolders based on year and month (YYYY-MM).

Read the rest of this entry…

One way to export data from MySQL tables into plain text files would be to use mysqldump, then remove SQL from the dump file. Perhaps an easier way is to pipe SQL SELECT output to a file.

For CSV (comma delimited, enclosing content in quotes):

foo@bar:~$ mysql my_db -e "SELECT * FROM my_table" | sed 's/\t/","/g;s/^/"/;s/$/"/;' > my_db.my_table.csv

Example output:

"column1","column2"
"value1","value2"

Read the rest of this entry…

Let’s say I’m doing something that outputs stuff one item per line to the stdout:

foo@bar:~$ dpkg -l | grep sasl | awk '{print$2}'
1
2
libsasl2-2
libsasl2-modules

Let’s say I want to replace newlines with spaces.

Using “tr” works, but messes up the console:

foo@bar:~$ dpkg -l | grep sasl | awk '{print$2}' | tr '\n' ' '
1
libsasl2-2 libsasl2-modules foo@bar:~$

Using “paste” works as well, and doesn’t mess up the console:

foo@bar:~$ dpkg -l | grep sasl | awk '{print$2}' | paste -sd' '
1
libsasl2-2 libsasl2-modules

Some of my systems are logging this error:

su: pam_env(su:session): Unable to open env file: /etc/default/locale: No such file or directory

I already had the “locales” package installed, to create the file:

dpkg-reconfigure locales

Follow the prompts to choose your locale(s). Result:

cat /etc/default/locale
#  File generated by update-locale
LANG=en_US.UTF-8

Let’s say we’ve got:

$ cat file.txt
1
2
3
4
5
6
7
blah
blah blah
append after me
blah bleh!
append after me
blah blah blah
bleeeh

This will add “new stuff” after every line that says “append after me”:

$ sed -i '/append after me/a new stuff' file.txt

Bingo:

$ cat file.txt
1
2
3
4
5
6
7
8
9
blah
blah blah
append after me
new stuff
blah bleh!
append after me
new stuff
blah blah blah
bleeeh

This is similar to my little shell one liner to verify tar archives. Exit status of 0 means the archive is good, anything else means there’s a problem. Most of the problem archives I encountered had a status of 2, but a few 3′s and 9′s as well — see “man unzip” for explanation of status codes. Using a while loop because some of the archive files names have spaces in them, which trips up the for loop:

find . -name "*.zip" | while read f; do unzip -t "$f" &> /dev/null; err="$?"; echo checking "$f"; echo $err "$f" >> zip-check.list; done

Read the rest of this entry…

Let me preface this post with a rant. In retrospect, I feel that getting this netbook with the Poulsbo chipset / Intel GMA500 video was a mistake since it’s been a major PITA. The little form factor has been more annoying than helpful. Should have gone with a larger laptop with a decent Nvidia or ATI video card. There are reasons for why this chipset is such a bitch to live with and sounds like it’s one of those situations where no one is at fault. Fine, but after dumping quite a few hours on this thing since getting it, I frankly just don’t care. As a mere luser, I need a working computer whose video doesn’t keep breaking on every kernel and OS upgrade so I can live my life.

But, wasted hours aside, I just got it working again. I had the nice 1366×768 resolution previously working with Ubuntu 9.04, but it wouldn’t let me turn on Compiz effects. A few days ago, swayed by promise of seemless iPhone 3GS syncing, I upgraded to Ubuntu 10.04, which broke video. Turns out, GMA500 support is not all there yet with Ubuntu 10.04 Lucid and I forgot to research that before upgrading. So then I do a fresh install of Ubuntu 9.10 Karmic and follow the install steps on the Ubuntu Poulsbo Wiki, only to find this did absolutely nothing. Turns out, it’s missing some critical steps. After scouring the web for a while and trying a bunch of settings, finally arrived at a configuration that works. Got the pretty resolution back and even got extra Compiz effects! This thing is a royal pain in the ass, but sure looks nice when it works. Anyway, here’s the config that’s working for me on Dell Mini 10 (aka Inspiron 1010).

Read the rest of this entry…

The following config will reject a message when more than 10 recipients are in the TO: and/or CC: fields.

/etc/postfix/main.cf:

# restrict based on message header content 
header_checks = pcre:/etc/postfix/header_checks

/etc/postfix/header_checks:

/^To:([^@]*@){10,}/	REJECT Sorry, your message has too many recepients.
/^Cc:([^@]*@){10,}/	REJECT Sorry, your message has too many recepients.

Solution based on a post at linuxquestions.org.

Needed a script for work to recursively spider one of our sites to check for problems and build a content inventory. As a side project, produced a little shell script that just checks links and produces a report by HTTP response code.

Read the rest of this entry…