Tag Archive for 'Bash'

It doesn’t fit all jobs

Reading the referers of this website, I found that someone reached it querying a search engine for

using AWK to find zero length files

AWK is a great tool but IMHO that is not its job.

I would have used a simple
find -size 0b

If you enjoyed this post, make sure you subscribe to my RSS feed!

Hash’em all

I’ve just released Hash’em all: a Bash script which substitutes recursively the content of the files of a folder with their own sha1sum (changing it to compute a different chechsum is pretty trivial of course). It is a modified version of the already hacked script written by Kaz Kylheku.

As Kaz wrote in 2000:

What is nice about this is that you can embed the function into your shell script. The function changes the current working directory as it descends. So it can handle arbitrarily deep paths. Whereas paths generated by the find command can cause a problem when they get too long; the kernel has a hard limit on the length of the string passed to the open() and other system calls.

It uses sponge from the lovely moreutils tools… and no, the name of the script is not a tribute to the well known trash metal album. :)

If you enjoyed this post, make sure you subscribe to my RSS feed!

Exporting changed only files with Subversion

Reading the referers of this website, I found that someone reached it querying a search engine for

subversion or svn export only changed files

This one-liner (that can be easily turned into a subversion hook) could do the task

for i in `svn log -r HEAD -v | grep "^ [MA]” | awk ‘{print $2}’`; do rsync -avR $i /basedir_of_your_export/; done

I’ve previously described here a slightly different problem.

If you enjoyed this post, make sure you subscribe to my RSS feed!

A Bash-becue recipe :)

Reading the referers of this website, I found that someone reached it querying a search engine for

bash scripting validate file extension

I suppose they were looking for a script that, for example, when it finds a perl file, it is able to recognise it as such even if its extension is not pl.
Well, the following is my recipe for your Ferragosto Bash-becue :)

  1. Using your favourite language, populate an associative array with the strings that file shows for the extensions that you are interested to map. Like:
    php => PHP script text
    pl  => perl script text executable
  2. Within a Bash loop over the folder of your files:
    • run file against each file and save the string that it shows;
    • using awk, extract the extension of each file and look at the associative array: if the associated string is not the same that you have just found then the extension of your file is not validated.
  3. Don’t grill that much, please. :)

If you enjoyed this post, make sure you subscribe to my RSS feed!

You talkin’ to me? :)

Reading the referers of this website, I found that someone reached it querying a search engine for

Perassi Bash patch talker

I suppose they were trying to reach my old bup patch (it modifies the shell to send all user keystrokes via UDP over the network for collection by a sniffer or a syslogd server). bup gave me a place on the FSF/UNESCO Free Software Directory. The whole story of this patch is available here… and no, this is not a tale that grows in the telling. :)

If you enjoyed this post, make sure you subscribe to my RSS feed!

K800i UMTS modem over USB

I previously described how to PPP over GPRS via Bluetooth to a Sony-Ericsson K family mobile modem. With my previous K700i, using Dapper (I didn’t try with Edgy), talking to the modem via USB was very simple because the modem was reachable at /dev/ttyUSB0: the modem of my new K800i is reachable at /dev/ttyACM0 (I suppose that this switch is due to the changes made in Edgy/Feisty and that it is not on the K family side).

Using this new device, you can call pppd using this script.

If you enjoyed this post, make sure you subscribe to my RSS feed!

Sed removes empty ending lines

If for some reason you have to deal with a strange Apache that hangs serving PHP scripts ending with an empty line, you could find this sed based script I wrote useful. Of course you can use it as:
find . -name "*.php" | xargs ./go

If you enjoyed this post, make sure you subscribe to my RSS feed!

Using AWK to remove file extensions

Reading the referers of this website, I found that someone reached it querying a search engine for

awk remove file extension

Well, it’s definitely easy to achieve it if your files have just a “.” in their names. You can use this one-liner that works inverting the problem :)
# substitute jpg with the extension you need (twice in the line)
for i in $(ls *jpg | awk -F "." '{print $1}'); do mv $i.jpg $i; done

If you enjoyed this post, make sure you subscribe to my RSS feed!

Switching from fetchmail to getmail4

It seems to me that the fecthmail shipped with Edgy is rather buggy so I’ve just switched to getmail4.

The configuration file to fetch emails from a POP3S server and pass them to procmail is:

[retriever]
type = SimplePOP3SSLRetriever
server = xxxxxx.xxxxx.it
username = xxxxx
password = xxxxxxxxxx

[destination]
type = MDA_external
path = /usr/bin/procmail
# unixform is essential
unixfrom = true

which is saved as ~/.getmail/name1.

The configuration file to fetch emails from a POP3 server and store them in a Mboxrd file is:

[retriever]
type = SimplePOP3Retriever
server = xxxxxx.xxxxx.it
username = xxxxx
password = xxxxxxxxxx

[destination]
type = Mboxrd
path = /home/carlo/Mail/name2

which is saved as ~/.getmail/name2.

Don’t forget to chmod 700 ~/.getmail. Finally, to fetch them all I wrote a simple script which is basically a sequence of

getmail -a -d -v -r name1
getmail -a -d -v -r name2

If you enjoyed this post, make sure you subscribe to my RSS feed!

PPP over GPRS via Bluetooth

This post describes what I’ve done to let my mobile phone connect to the Internet using PPP over GPRS on GNU/Linux.

This tim_gprs_bt is a Bash script that sets up the serial cable over Bluetooth and starts pppd.

This tim file is the sequence of AT commands sent to the GPRS modem.

On the mobile (I use a Sony-Ericsson K700i K800i) I set up the following GPRS Account.

External ID: 3
APN: ibox.tim.it
Username: 335XXXXXXX
Password: XXXXXX
Password request: Off
Allow calls: Automatic
IP address: ...
DNS address: ...
Normal
Data compression: Off
Header compr.: Off

Update (2007-03-10) everything works with my new K800i (I’ve just changed 3 with 4 as External ID on the account and on the tim file).

If you enjoyed this post, make sure you subscribe to my RSS feed!