Find sdx device/ATAx mappings

When dealing with hardware, you often see messages in the logs about disk issues or warnings.
Messages like:

 
ata9: hard resetting link
ata9: SATA link up 1.5 Gbps (SStatus 113 SControl 310)
ata9.00: configured for UDMA/33
ata9: EH complete
 
 
ata3: SATA max UDMA/133 abar [email protected][......]

Read more

Convert Squid/timestamps to a human readable format

Somebody had the brilliant idea to use Unix timestamps in the Squid log.
I suppose this makes it easy to parse, not so easy to read for us humans though!

This is an elegant and common way of solving this problem:

 
cat /var/log/squid/access.log | perl -p -e 's/^([0-9]*)/"[".localtime($1)."]"/e'[......]

Read more

bash – remove first line with tail and last line with head

You can achieve the same result with other (more powerful) tools, but I like this approach because it's the simplest I can think of.

Let's say you have this text file called test.txt

 
line 1
line 2
line 3
 

Remove the first line

 
tail -n +2 test.txt
line 2
line 3
 

Remove the last l[......]

Read more

sed – match and replace BIND/DNS serial number programmatically

I had to make some modifications to several BIND zone files, sed proved itself invaluable once again!

All the zone files looked something like this:

 
domain.com. IN SOA ns1.domain.com. postmaster.domain.com. (
               2015021001   ; Serial
               600          ; Refresh (10 minu[......]

Read more

Remove all non-ascii characters with perl

Sometimes when creating one-liners, when the source is not "clean", you may end up with non-ascii characters which make the parsing harder.

To get rid of all of it, you can use perl.

 
cat dirty-source.txt|perl -pe 's/[^[:ascii:]]//g' > clean-output.txt
 

The same command can be used on a file[......]

Read more

Converting spreadsheets to text files with ssconvert

ssconvert is a utility shipped with Gnumeric, and it's a command line spreadsheet converter.

Let's say that you have some data in a spreadsheet (eg spreadsheet.ods) and want to be able to easily parse it, and maybe use it in a script.

 
ssconvert -O 'separator=;' spreadsheet.ods parsable-data.tx[......]

Read more