Archive for May, 2007

Remove content from gzips

Problem You need to remove content from zip files.Effectively unzip, remove the pattern and re-zip. Solution A collection of shell commands, to perform the unzip, swap and rezip. Example * First to find zips with those patterns in (substitute pattA and B with your patterns, on each of the commands below): for na in *gz [...]

Cut and paste a zip file? You bet!

Problem You have a shell open on two UNIX boxes, but scp, ftp, etc, etc is locked down?Well they left Perl!!! Solution I recognise this could be messy for massive files – but it works beautifully on binaries, images, etc.I am demo’ing it here on tar gzipped output. It produces some errors, but still recreates [...]

Optical dump file – od

Problem Whenever you cat a file, it shows nothing!Or it destroys your terminal. … or when you diff to files – the look identical – but it reports them as not. Solution You probably have control characters in the file, or no newline at the end of the file.The example shows how to run an [...]

Find secrets – undocumented feature

Problem You want to find a pattern in a files, but have the file name and pattern printed.If you run find . -type f -exec grep -i “pattern” {} \; it will only show the pattern turning up – i.e not the file name as well.If you run find . -type f -exec grep -il [...]

Synchronize directories between firewalled hosts

Problem You have an admin host (ADMIN), which can see two servers (hostA and hostB) behind firewalls.You are not allowed to scp/rdist, etc from hostA or B to ADMIN. Nor are you allowed to scp/rdist, etc between hostA and B.ADMIN can scp, etc though to both hosts. Now in this real life example, updates are [...]

UNIX chat shell code

Problem As most UNIX bods know, with fairly recent audit lock downs – talkd has been disabled.But you want to chat remotely with someone, i.e. another techie bod! Solution Now where is the fun in that! Don’t know about you, but quite often I’ve needed to talk to other people remotely and don’t want to [...]

extract specific line number from file using sed

Problem You want to extract a specific line number from a file.Or a range of numbers from a file. Solution Once you have your line number – see grep, we can extract lines around the pattern.To do this sed (stream editor) can be used to print just desired lines – see the example which says [...]

Debugging Sendmail

Problem Issues with sendmail, tacking on another domain name, etc.You want to manually test you mail host, from the command line. Solution Whilst debugging sendmail issues, came across this great test.You can run this from the command line. See example. Example telnet mailrelay.domain 25…. answer from mail relay …..helo unix hostnamemail from: root@unix hostnamercpt to: [...]

unix sort

Problem You want to perform a sort:… But ignore leading blanks;… Perform numerical sort;… Offset it to the third column;… Reverse it; Solution As always with UNIX we supply the arguments, with letters.See the example tag. Example 8 flags to the UNIX sort command.1) -b # ignores leading blanks.2) -f # ignore case3) -n # [...]

LDAP to SQL Perl code

Problem Whilst working on the automatic production of web statistics – came across the following problem: “How do I get relational data from an Hierarchical structure?” Solution It didn’t take long to realize – I’d have to use PHP to talk to LDAP, pull off records & upload into a series of tables, using the [...]