Posts tagged ·

bash

·...

Prefix command output in a shell with timestamp

no comments

So I was writing this script that logged certain things to a file using a regular redirect. My script was running various commands that outputted a random amount of lines, all in random formats. I wanted to have a timestamp prefixing all of that, similar to what you get in logs written by syslog. I searched around a bit, and ended with this:

Of course if you want a different timestamp, you just change the arguments you pass to strftime. Quite handy!

Shell-script template for cronjobs

no comments

Have you ever had your server drown in processes because a cronjob you wanted to run every minute suddenly never finished, and you ended up having multiple instances of your nice script going at the same time? I have! A quick and easy solution to this problem, was this wrapper-script that I created a while back. Basically, it’s just some pid-file processing before your own code starts, to make sure only to run a single instance of the script at a time. With this you’ll avoid having your scripts pile up again.

The script: cron-shell-script-template.sh
The config: cron-shell-script-template.conf-sample

If you find this script useful, or have some improvements, feel free to drop me a comment below. Thanks!

Update:

The script had a little bug, which caused two instances of the script to be started under some circumstances. The script behind the link above has been updated to correct this.

Update, July 23.:

I’ve removed the PIDDIR-setting from the actual script, and moved it to a separate configuration-file. It’s all generic, the conf-file is expected to be named the same as the script with the last “.ending” replace with “.conf”. The point of this is to be able to e.g. keep the script itself in a repository (like subversion) and keep the config separate so you can update the script from the repository without having local changes to worry about.

Easy batch-conversion of flac to mp3

no comments

After getting a new mp3-player (the iAudio D2 from COWON) I wanted to find a quick and easy way of “tagging” and converting a number of albums that I had in flac-format (or mp3) into mp3 of a certain bitrate. My goal was to just browse through my collection, and touch a file inside a directory if I wanted to convert it. When I was done with the touching, I’d just fire up a small script that did all the work for me, while I was doing something else. Here’s what I came up with.

More: Read the rest of this entry…