Perl scripts, simple yet powerful

Am I a Hacker? is that what I am? (we’ll see to that later). Anyway, every time I need to sort something out quick, I always use Perl.

I consider myself knowledgeable enough to create any sort of scripts when it comes down to it.

One of my early introduction to Perl was when I started to work on Unix workstations, this led me to learn vi which is the best editor if you want to work fast and quick (it is somehow considered more geeky than Emacs, which, to be honest has never been my Favourite), with vi I started to write c-shell scripts, mostly to automate mundane activities such as formatting floppy disks and other things like that, basically these scripts where extensively using switches, sed, awk and other echo commands (if I can recall).

When the web started to emerge, you could indeed use c-shell scripts to create applications for it (you still can), as a matter of fact I probably did, or worked on someone’s c-shell cgi-script. However Perl was always better for that as you had far more power to do things fast. You can condense Perl commands to a one liner if you’re prepared to optimise your code. A few years ago I managed to reduce a whole lot of Perl lines to one, single command, I was dead chuffed.

Anyway in the upcoming blogs I will recall some these scripts and show how these work.

Perl is great for Unix/Linux SysAdm too!

Anyway, I have though about it, I am not a hacker, I know too little about Perl to qualify. Still can write things that help me though. Some of them are actually profitable. So my examples may probably look “lame” for most Perl Experts as I adopt quite a loose attitude to TMTOWTDI.

How to create a bootable WIN7 USB flash disk?

  1. Connect the USB drive On a Win7 Machine
  2. Partition the USB disk drive NTFS, if the disk is large (i.e. 1TB, reduce active partition to say, 6GB, I used gparted on Linux ;-p)
  3. Run DISKPART in command line
  4. LIST DISK
  5. SELECT DISK n (n is the number matching the USB disk obtained above)
  6. CLEAN
  7. CREATE PARTITION PRIMARY
  8. then copy the content of the DVD with XCOPY e:\*.* /s /e /f j: (e: = CD drive, j: = USB drive)

The power of Twitter

Twitter, for me is a new thing that I found quite challenging to understand. Being a Web veteran is sometimes hard to grasp the latest crazes. So I think that the solution from now on is to just use what’s available to its best potential and “go with the flow”.

Not only that but…

I just found out that SEO wise, Twitter can be a very very powerful way to spread something quickly to a vast number of people. Create a web page and not 5 minutes later, a large number of hosts are requesting this new page. That takes SEO to a whole new Level.

Les Etats-Unis veulent que la Suisse applique les sanctions contre l’Iran. – swissinfo

Les Etats-Unis veulent que la Suisse applique les sanctions contre l’Iran. – swissinfo.

Le Gouvernement Americain commence vraiment a me casser les pieds! Il n’y a qu’un seul mot pour le qualifier: une brute!

Le seul lien entre tous les conflits armés du Moyen Orient ces dernières années se sont centrées sur un seul point commun: Le pétrole, donc tout pays potentiel n’entrant pas dans l’idéologie americaine face le risque d’etre sanctionnée et mis a l’ecart. Ceci est scandaleux! Quant alons nous nous reveiller et commencer a leur botter le cul?

Enable Grub multi-boots after re-installing Windows

My current working PC is a Dell Studio 1537 Laptop. This Laptop is configured with two Operating Systems; the first is Windows XP Pro, the second is Linux, more precisely Kubuntu.

Kubuntu is my [favourite] working OS, however the rest of my family “prefer” Windows for “Gaming”, I occasionally need to be able to use Windows in native mode for my work (I am a Webmaster for several Websites) so I need to see how they work using Internet Explorer :-(, mind you I usually use Virtualbox on Kubuntu to achieve this [but it’s a little slow], so I have a Dual boot which is managed by Grub. I have been playing with different versions of Windows on this Computer, the pre-installed OS was Windows Vista, which quite frankly, sucks. So I tried to install Windows XP Pro pretty much straight away. I gave up when I encountered the Blue Screen Of Death (BSOD) and subsequently installed the 90 days Windows 7 Enterprise trial.

This Version worked very well, only to shut down every hour as it was,after all, a trial version. So I had to find a solution to this, I finally decided to retry installing Windows XP Pro as there was no way that I’d re-install that joke of an Operating system called Vista.

The other problem, is that MS Operating System overwrites the MBR (Master Boot Record) and therefore prevents me from having Grub giving me the options of which partition I want to boot from.

So here is walk through of how to:

  1. Backup the MBR (which is always a good idea by the way)
  2. Change the BIOS “Onboard Devices>SATA Operation”
  3. Install Windows XP Pro on the first Partition
  4. Install [almost] all the missing Drivers
  5. Re-install the backed up MBR and reconfigure Grub afterwards

In the past, every time I was re-installing [any] Windows, I never managed to figure out how to overcome the MBR being overwritten, the HowTo’s where very daunting and I always resolved the problem by re-installing the Linux OS afterward due to lack of spare time, as a side note, one of the recommendation I have is that: it is always a good idea to have a home (/home) partition separated from the root (/) partition*.

Linux is more forgiving than Windows (and, shall I say, less monopolistic) by gladly allowing several OS’es living side by side on the same Hardware and thus performs a multi-boot initialisation operation after each fresh install.

The other challenge is that this particular version of Hardware [Studio 1537] is not supported by Dell to run Windows XP Pro. That makes work just a little more difficult.

So here are the steps in more details…

1) Backup the MBR

To backup the MBR of a Disk with Linux is really simple. Open a terminal window and type:

sudo dd if=/dev/sda of=/media/External/sda.mbr count=1

Where /media/External can be an external Hard drive or USB stick etc… It’s best to have this file saved out-with the Hard Disk Drive that will be worked on, just to be on the safe side.

2) Change the BIOS

At boot. press F2 and go to the Onboard Devices>SATA Operation and change AHCI to ATA. Save the configuration then reboot. (this operation is only needed once, subsequent re-installs do not require this step)

3) Install Windows XP Pro on the first Partition

My System has a couple of Partitions:

  • sda1 = Windows + MBR
  • sda5 = Linux / + Grub
  • sda6 = Linux /home
  • sda7 = swap

Obviously Windows must be installed on the first Partition and that’s where the MBR is.

Simply insert the Windows XP Pro installation CD, tell it to use the first Partition (optionally format it as NTFS) and follow the installation instructions. This will install a working version of windows with minimal functions.

4) Install all the missing drivers

Once windows has finished being installed, all the drivers [that have not been already installed, and that’s quite a few] must be installed. This is where it is getting a little tricky. Due to the futile nature of the web, it is like looking for a needle in a haystack in most parts, not to mention the huge amount of websites that try to entice you to install their rogueware.  The first descent source of information regarding the required drivers I have come across is Dell Studio 1535 converted to XP Professional  (this link is now rotten) by “Wickman Studios”. Most of the drivers are available here. For my particular configuration, it’s been trials and errors, as I haven’t kept tab on the different drivers’ executables I tried, it is kind of difficult to be specific.

The last few drivers I needed that Wickman Studio Post did not have were the “unknown” device which I managed to solve with I found on Dell Studio 1537 Windows XP Drivers / Downgrade (this link is now rotten) written by “AZ cloud tech” which is also a good source of information.

I still had issues with the ITECIR Driver which I eventually found on the Lenovo website (this link is now rotten) (the link from the Wickman Studios was throwing a “zip file corrupted” error during install).

The final problem I still have is the 1394 Firewire Network adapter not being recognised, but I have disabled it as I don’t really need it, if you have any idea let me know 🙂

Once I got [almost] everything working, I installed all the Windows Updates and the [free!?] Microsoft Security Essentials (MSE) which is the only thing I will ever recommend to use from Windows, that’s rare coming from me, trust me.

 5) Re-install the MBR and reconfigure Grub

For this part, I wish to thank John S. Denker for his information regarding  How to Reinstall Grub Onto Your MBR which was extremely useful and the first clear and concise Howto I managed to follow and recover my Dual boot system with.

After a few lots of trials and errors I managed to get the Dual boot working. Here’s the final order I used:

  1. Back up the MBR before anything else
  2. Restore the MBR without disturbing the current partition table
  3. Get the system to boot, note: my $partition on point 6 is sda5 but it might be something else for your System, So I am not responsible if your system fails!

In my first atempt to install Windows, I had a fail due to a problem with the sda1 Partition, there was a formatting issue (probably due to the fact I installed winXP without reformatting the old Win7 Partition first), so when I tired to do a Follow up I got a “Stage 1 error”  this problem got fixed when I did a full NTFS format prior to installing Windows XP again.

I also played with Using Grub Command Directly as before the re-install I was faced with the grub> command prompt at boot :-(, so just for the record, my root device is /dev/sda5. In addition as I had grub 2 installed, the correct command went from root (hd0,<tab> to:

set root='(hd0,<tab>

which in full is (don’t ask! It’s for the Record):

set root='(hd0,msdos6)'

Subsequently, the next command looks like:

linux /boot/vmlinuz-... root=/dev/sda5

Well, that’s it in a nutshell, I hopefully will not need to perform any of this again, as I made an disk image of sda1 with partimage and dd which is safely stored on an external USB Hard Disk Drive, I also have a complete backup of all the web pages, Zip archives and exectuables mentionned in this post just in case. One knows the elusive nature of the Web these days… So I hope this was worthwhile and may prove useful to someone else, in which case, good luck and let me know how you did.

*That way I can format / without losing all my stuff and simply mount my home Partition as /home after my install. This is also very useful when doing an upgrade as I know that none of my Data will be overwritten, I also do regular backups, that goes without saying.

MOS Fet Hi-Fi Power Amplifier

Now that my DIY webcam project is nearing to completion, I am planning to work on some (old) new one. Crescendo MEBack in 1985 I build a Hi-Fi Power amplifier, I still have the blue prints and I am keen to rebuild it. These days, with MP3 gizmos, music kind of lost it’s spark, It’s amazing how much presence is felt when you play a good old Vinyl, no wonder it’s coming back into fashion!

Long live Analog!

Webcam System Gallery etc…

Latest Webcam snap

My Webcam system is finally finished, I have  waterproofed the system and it is now located outside above the stable building, allowing a full 370o Pan and 190o Tilt!

Here is the Gallery pages showing snaps with 5 minutes intervals. This setup has been sourced from Mitch Fournier’s Blog and rewritten in Perl executed by a 5 minutes Cron.

The rig is entirely DIY made with wood, screws,13 switches, cables, 2 electric motors, 4 servos, an Arduino Uno connected to a PC via USB loaded with a Python script from principialabs.com, The camera controls can be manually overridden. The camera itself was bought on Ebay as “spare repair (the tape does not load)” connected to an Analog TV card, finally, the web streaming is handled by a piece of Software called Palantir. The whole hardware/software is Open Source. Any Camcorder can be used as the bracket is able to hold any moderately light camera hardware.

The Pan Tilt Kit is controllable via a web page via buttons (see flash animation above) and Ajax Dynamic Content. The web cam has two Zoom speeds and currently one speed Pan and Tilt, however it is capable of two speeds, still to write code to enable that.

The Kit

Here are a few shots of the kit. Bear in mind this is a DIY job with cheap hardware!

The Switching Unit, Servos and all
Camera and Bracket
Details of the Servo managing the Zoom.
Details of the Servo managing the Zoom.
Wires!
Wires!
View from behind the rig
View from behind the rig
The camera: Samsung, but any will do!
The camera: Samsung, but any will do!

Here are two short Videos showing the rig in action:

It’s the end of the year / C’est la fin de l’année.

Ok the TV is crap and I am bored, so I though to post something about 2011. It’s been a rubbish year, I have good hopes for 2012. With the latest about Recession and  other “We are at the top of the ravine, let’s make a big step forward” News, it’s not looking good. However we have friends coming to see us soon from France, so this will be appreciated.

I am also planning to go to Switzerland for a Holiday, I might also go and work there.

Bon, la télé est nulle et je m’encrasse à mort, alors j’ai décidé de poster un message à propos de 2011. C’a été une année horrible. J’ai de l’espoir pour 2012, avec l’Europe, la récession et les nouvelles qui n’arrêtent pas de dire “Nous somment au bord du précipice, maintant faisons un grand pas en avant!”, c’est pas réjouissant. Malgré tout, des amis viennent nous voir de France tres bientôt, ce la me mettra de bonne souche.

Je prévois aussi d’aller passer quelques jours en Suisse, même peut-être retourner travailler, qui sait.