Posts

Showing posts with the label perl

Parsing the Multipath

Having worked a little with XIV I have come to like the "xiv_devlist" tool.  "xiv_devlist" lists all the attached disks on the SAN and the number of paths that are currently active.  This is very useful when you want to ensure that all the paths to storage are active. Find latest up-to-date code for this post on my Github profile:  https://github.com/linuxplayground/mpath_devlist It surprised me to find that there are no useful tools to parse the output from Multipath. Here is an example: multipath -ll mpath2 (3600507680191014a3800000000000100) dm-7 IBM,2145 [size=40G][features=1 queue_if_no_path][hwhandler=0][rw] \_ round-robin 0 [prio=100][active] \_ 0:0:1:8 sdaa 65:160 [active][ready] \_ 1:0:1:8 sdbk 67:224 [active][ready] \_ round-robin 0 [prio=20][enabled] ...

chomping isql and date conversion

Today a colleague was working on retrieving data from a Windows SQL Server database from within linux. He needed a bash script that would execute a query against the database and dump the results in comma delimited format. The SQL query he wrote was rather long and so was broken up into new lines and indented to ease editing and readability. This, however, caused a snag in isql. isql is a commandline tool that ships with linux ODBC that can be used to connect to an ODBC DSN and execute sql commands as well as execute batch files in unattended mode. isql parses batch files ( essentially SQL scripts ) in such a way as that each line is treated as a single command. It does not recognise the GO statement or any other command terminator. Our workaround was to chomp the script prior to piping it into isql. So here we go: Here is an example script. #--- mySqlScript.sql --- SELECT TOP 100 * FROM myTable t WHERE t.created_at between '2009-01-01' and '2009-12-31' ...

Rip from WAV to MP3 and add ID3 tags -- All with Perl

Ok - so I know I have said before that I am not much of a perl fan. ( yes it's safe, I am wearing my flame proof suit. ) I will, however, say now; I am coming around. It would seem that I am starting to see the light. I needed to extract some files from a CD I have and convert them to MP3. The CD was not made with extracting to mp3 in mind if you get my drift. It's ok, because the CD is my copy and I want to listen to it on my iPod. Regular extracting on iTunes was not working out for me. So I rolled my chair over to my trusty Linux Box and perl, id3, cdparanoia and lame. First thing I did was use cdparanoia to extract all the tracks. This went swimmingly leaving me with a folder full of files called 01.cdparanoia.wav or something just as useless. The files played ok but I needed to name them all. This particular CD was not listed on Music Brainz so I couldn't do anything fancy with FreeCDDB or whatever they call that now days. * shudder * - I had to manually edit ...

Real simple to connect to MSSQL from Perl

Again, this took me a little while but here I am. Connecting to a database ( SQL SERVER 2008 ) from a Windows Server 2008 VM I own ( thanks TECH ED 2008 ) and Active State Perl. Install Scite cos it's a nice editor and you are away laughing... #!/usr/bin/perl use DBI; my $DSN = 'driver={SQL Server};Server=localhost; database=AdventureWorks;TrustedConnection=Yes'; my $dbh = DBI->connect("dbi:ODBC:$DSN") or die "$DBI::errstr\n"; my $sth = $dbh->prepare('select top 10 * from Sales.vSalesPerson') or die "Couldn't prepare statement: " . $dbh->errstr; $sth->execute(); while( @data = $sth->fetchrow_array()) { foreach(@data) { print "[$_]"; } print "\n\n"; } $sth->finish; $dbh->disconnect; Results: C:\Users\dave\Documents>perl perl1.pl [268][][Stephen][Y][Jiang][][North American Sales Manager][238-555-0197][stephen 0@adventure-works.com][0][2427 Notre Dame Ave.][][Redmond]...

Joining multiple PDF documents with Gostscript.

This really works. I downloaded all the chapters of beginning perl as published here: http://www.perl.org/books/beginning-perl/ To do it in a painless way I first used curl to grab the html. curl http://www.perl.org/books/beginning-perl/ -o bp.txt Then I used grep to grab the hyperlinks to pdf files and piped that into another file. cat bp.txt | grep -o "<a.*pdf"> bp2.txt Then I used sed to clean up a little bit. cat bp2.txt | sed "s/^<a href=\"//g"> bp3.txt Then I used wget to download each pdf. for line in `cat bp3.txt`; do wget $line; done So now I had a whole bunch of pdf files that together make up one book. A quick hunt on google produced this guy. http://www.linux.com/news/software/applications/8229-putting-together-pdf-files And I was away laughing. gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile=beginning-perl.pdf 3145_Intro.pdf 3145_Chap*.pdf 3145_App*.pdf 3145_Index.pdf