Archive for category Linux/Unix

Speed up shell scripting

Once again the book Practical Ruby for System Administration by Ben Hamou taught me some pretty clever Ruby sysadmin scripting tricks.
One of the scripts that the author used was to automatically populate the path to the Ruby interpreter, update the permissions to 755, and open the script in vi, all during the same process.

I took that same concept and enhanced the script to also auto populate the settings if the scripts is written in Bash, Perl, PHP, or Python.

Download rnew.rb

-Copy rnew.rb to somewhere within your system PATH.
cp rnew.rb /usr/local/bin

-This should give the ability to use rnew.rb from anywhere you’re working on.
rnew.rb koolscript.php



-Happy Hacking :-)

watch command line utility for alternative for Mac OS X

I recently purchased the book Practical Ruby for System Administration by Ben Hamou and one of the cool Ruby one-liner command line expressions is one that mimics the watch command.
ruby -e 'system "clear; df -h" while sleep 1'

Just like the author, for quite a while I’ve been kind of annoyed by the fact that Apple doesn’t include this really useful command line utility. So inspired by the one-liner script, I hacked a small watch command line alternative for OS X.

Download watch.rb
sudo cp watch.rb /usr/local/bin
wacht.rb ‘UNIX command

Converting a CD to an iso image

Converting a disk to an iso image is easier to do in Linux than in other operating system.
dd bs=2k if=/dev/cdrom of=~/disk_image.iso

SCALE 8x

Being my first Linux conference, overall I had a really good time. Seeing and talking to a lot of famous Open Source figures was pretty kool.

I only managed to see four different talks.
My favorite talk was Jono Bacon’s talk on the evolution of the Free Software/Open Source movement to what now will be fun and rapid development using a new development approach. Essentially, Cononical has developed a Python software development framework called Quickly (reminds me of Ruby on Rails, though I haven’t hacked much on it to even compare its similarities) That makes it real easy to package (.deb only) and publish.

BSD for Linux users:
This talk was mainly focused on the difference and advantages of using the BSD’ s (NetBSD, FreeBSD, OpenBSD) compared to Linux. Now more then I ever, I’m thinking of delaying a DNS BIND server on my local network running on OpenBSD.

Basic Introduction to KDE:
As the name implies, it was definitely, an introduction to KDE 4. Although I prefer using Gnome, the

Python for non programmers:
Also, as the name implies, this was a definite introduction to Python. Although I’m not big on Python, I definitely felt like an advance Python hacker by being on this talk.

Even though I only attended the Saturday event, I really enjoyed SCALE. It definitely felt like a community conference and it didn’t felt corporate what so ever.

mod_ruby and eRuby

I finally had some time to install mod_ruby and eRuby on my server.

Prerequisites:
httpd-devel ruby ruby-devel eruby
yum install httpd-devel ruby ruby-devel eruby

Installing mod_ruby was pretty confusing, as module default compilation is intended for Apache 1.3 (not why this is the case)

If you’re running Apache 2.0 or higher, I managed to successfully compiled mod_ruby as the following:
./configure.rb –with-apr-includes=/usr/include/apr-1
make
make install

After the install, then its a matter of just adding the custom ruby http conf file to httpd conf.d directory.

SAMPLE:

AddType text/html .rhtml
LoadModule ruby_module modules/mod_ruby.so


RubyRequire apache/ruby-run
#RubyRequire apache/ruby-debug

RubyRequire apache/eruby-run
#RubyRequire apache/eruby-debug

# Execute *.rbx files as Ruby scripts

Options ExecCGI
SetHandler ruby-object
RubyHandler Apache::RubyRun.instance
#RubyHandler Apache::RubyDebug.instance

# Handle *.rhtml files as eRuby files

SetHandler ruby-object
RubyHandler Apache::ERubyRun.instance
RubyHandler Apache::ERubyDebug.instance


Now I can embed Ruby code on standard html pages serving and running natively using Apache and eRuby. :-)
Hence, perlninja.pl

References:
http://www.modruby.net/en/
http://www.ptwit.ac.th/seksan/blog/?p=59

I’m LPIC-1 Certified

A month after my initial planning, I finally manage to pass both LPIC-1 exams.

Computer upgrades

I finally upgraded the hard drives on my MacBook, Mac Mini (Server), and my main desktop Mac Mini.

Macbook (Leopard)
For some strange reason, I wasn’t able to clone my existing Leopard system to the new 500 GB as the clone process failed about 10% – 15% completion. So I just backed up all my files and installed Snow Leopard from scratch.

Mac Mini (Leopard)
Unlike with my MacBook, cloning the existing Leopard system to the new hard drive worked flawlessly on my desktop Mac Mini.
After that, upgrading to Snow Leopard worked like a charm.

Mac Mini (CentOS)
Upgrading the RAM on the Mini to 2 GB was simple, the hard drive upgrade was a completely different story. First, I wasn’t able to find any open source program that would allow me to clone to an attach mass storage USB drive. Unless I didn’t read the documentation properly, both CloneZilla and FOG only allow the clone output image to be saved on a network system and not locally, even if its a different hard drive.

Little that I knew. dd was everything I needed to clone the hard drive.
commands I used:

dd if=/dev/sda of=/dev/sdb

After the dd copy was finished, I rebotted to the new hard drive only to find out that /dev/sda5 , /dev/sda6 and /dev/sda7 were not copied properly to the new hard drive. So I had to reboot into rescue mode using the original CentOS install DVD and ran the following commands:
dd if=/dev/sda5 of=/dev/sdb5
dd if=/dev/sda6 of=/dev/sdb6
dd if=/dev/sda7 of=/dev/sdb7

On my second reboot to the new 500 GB hard drive, Linux was able to boot perfectly fine with all my original settings!!! Until… I opened up fdisk only to find out that I wasn’t able to add partition (I had over 400 GB of free space in the drive) because I wasnt able to modify my existing partition table that consisted of 3 primary partions and 1 extended partition that consisted of three logic partitions within it. So I just download the live GParted program and I was able to created the additional 400 GB logical drive from there.

On the third attempt to boot into the new 500 GB hard drive, Linux had to do filesystem check to /dev/sda7 which happened to be my /home partition. The fsck completely wiped out all of the contents that was in my home directory. Which wasn’t a big of a deal since I already had a full backup of all my files.

Conclusion
Overall upgrading the hard drive on a Mac Mini running CentOS was really painful, but I had the feeling that it could have been worse.

CentOS
GParted Live CD

-Alpha01

Goodbye Eclipse and hello vim

Apparently Apple doesn’t think its a good idea to ship vi with syntax highlighting turned on by default, giving how really easy it is to enable.

I simply had to edit the /usr/share/vim/vimrc file. Full instructions are in http://www.geekology.co.za/blog/2009/03/enable-syntax-highlighting-other-options-in-vim-mac-osx-leopard

It’s Official Part III

I’m a sysadmin once again.

I’m Linux Certified!!!

After 5 months of studying, I finally took the CompTIA Linux+ certification exam today. My study consisted of reading two books (Sybex CompTIA Linux+ and Linux+ 2005 in Depth), on-line tutorials, and a web based program called “TestOut Linux+ LabSim” that my school provides.

The exam is by and far the most difficult CompTIA certification exam that I’ve taken. Given that I scored 675 and the minimum passing score is 675! I probably would had gotten a better score if I’d studied sed, awk, and iptables more in depth. If I had taken this exam six months ago I would have failed it miserably. Now that I’m CompTIA Linux+ certfied professional, I’ll be putting the LPIC Level 1 on hold until I know I’m fully prepared for those set of exams.

Cheers!!!