Jon Holato

Twitter: A Thursday flight home possibly on time!?!? No way, I don't believe it...

My First Linux Shell Script

Last week I wrote about my Ubuntu installation. At the end of that post I promised some Linux-related posts in the future, and here is my first one.

In my opinion one of the things about Linux that makes it so powerful is the shell. And as powerful as the shell can be, it becomes even more powerful when you create a shell script to execute a multitude of commands. Nobody wants to type ten commands in a row in order to achieve a desired result. Further, nobody wants to type the same ten commands in a row every single day. Enter the shell script.

My first shell script started out as a bit of experimenting but has evolved into quite a useful utility. The end result is a script that automatically backs up the development area of partybody.com at a specified time each night, stores a copy locally on the server, and emails a copy to the relevant administrators.

Let’s take a look at the code (some values have been changed for security reasons):

1 #!/bin/bash
2
3 # “scriptname” - copies all contents of a directory into time stamped tar.gz file in /path/to/backup/file
4
5 TD=$(date +%T-%d_%m_%Y)
6 FILE=”/home/user/web/cms/backup-$TD.tar.gz”
7 DIR=”/home/user/web/dev/”
8
9 # Create the gzipped archive file
10 tar -zcvf $FILE $DIR
11
12 # Send successful backup notification email
13 DEST=”/web/cms”
14 FILENAME=”backup-$TD.tar.gz”
15
16 echo “Automated backup ran successfully at $TD and created file: $FILENAME in FTP location: $DEST.” | mutt -s “Daily Automated Backup Complete” -a $FILE -c cc_email@yoursite.com to_email@yoursite.com
17

To get an idea of what’s going on here let’s examine this code line-by-line.

Line 1 is simply telling the script to use the BASH shell environment. Certain shell environments allow for different scripting capabilities than other shell environments, so it’s necessary to declare which one you’re using on the first line of your script. Note: BASH is the default for most Linux distributions.

Line 3 is a comment. The # character at the beginning of the line tells the shell to ignore all content on that particular line. In this case we’re just using the comment to identify the name of the script and a description of what it is intending to perform.

Line 5 creates our first variable, TD, and gives it the value of $(date +%T-%d_%m_%Y). In this instance we are accessing the built-in date function of the BASH shell and pulling out some values like time, day, month and year in order to create a time stamp.

Line 6 creates a variable called FILE and gives is the value of the backup file to be created. In other words, we’re specifying the filename we want to create and the location where we want to put it.

Line 7 creates a variable called DIR and gives it the value of the directory that we want to backup.

Line 9 is a comment declaring the action that we want to take next, in this case, creating the actual gzipped file.

Line 10 creates the archive file and gzips it taking the $DIR variable as input and the creating the $FILE variable as output.

Line 12 is another comment declaring the final action the script will take, sending the email to relevant administrators.

Lines 13 and 14 are variables that contain values to include as descriptors in the notification email, and have no effect on the execution of the script.

Line 16 echo’s the notification message into the email as the body content. The program Mutt is used to send the email. It accepts the piped input from echo and we specify a subject using the -s flag, an attachment using the -a flag, and a cc address using the -c flag. All that together sends an email to the “to” and “cc” email addresses with the subject of “Daily Automated Backup Complete” and attachment of the $FILE (”/home/user/web/cms/backup-$TD.tar.gz”) the script created.

And that’s it. Only 16 lines to backup any directory (including sub-directories), store a copy on your server, and email to whomever you wish.

There is still one problem with this script, though. As it stands it must be manually executed in order to run, and who wants to have to ssh into their server every time they want to run a backup. Therefore, we must auto-schedule the script using cron.

Cron is a time-based scheduling service driven by a crontab, a configuration file that specifies shell commands to run periodically on a schedule. Basically, we just need to add a line to this crontab file telling the shell to execute our backup script at a time of our choosing.

In this case, I added the following line to my crontab file to execute the script every day at 3 a.m.:

0 3 * * * /path/to/script/scriptname

Also, one final note, be sure to make your script executable or else it will not run. We can do this by using chmod +x as follows:

chmod +x /path/to/script/scriptname

That’s all for now. You should be able to adapt this code into a backup script of your own. Feel free to ask any questions in the comments section below.

Ubuntu 7.10 Gutsy Gibbon A Joy Once Installed

Ubuntu Linux LogoTonight I made the switch from Fedora to the latest version of Ubuntu, 7.10, dubbed “Gutsy Gibbon.” I have long been a Fedora user over Ubuntu for the simple fact that the Fedora worked better “out-of-the-iso” in terms of supporting my hardware — an old Sony Vaio VGN-S480P. However, given some recent issues with configuring the wireless adapter, coupled with the fact that I had installed an older version of Ubuntu a few years ago and wireless worked instantly, I decided to give it a go.

I downloaded the Ubuntu ISO and burned the image to a blank CD using Alex Feinman’s ISO Recorder. Everything up until this point worked like a charm and I booted up the Ubuntu Live CD to the desktop.

Older Ubuntu Live CDs had failed to even reach the desktop on this old Vaio, so already I was making much more progress than in the past. Once on the desktop, I was able to connect to my wireless network and I got a warm, fuzzy feeling inside that this would be the one. Then things took a turn south.

After testing the wireless I double-clicked the “Install” icon on the desktop to put Ubuntu on the hard drive for good. Navigating through the on-screen menus and selecting my preferences was no problem, it’s once the actual process started that problems arose.

Without getting into too much detail, basically the install froze during the installation at 5% and wouldn’t budge. To make a long story short, the problem was with the ntfs-3g driver during the ext3 formatting step. After a rather extensive investigation into the Ubuntu support archives and The Google, I discovered a few solutions which somehow, some way fixed the issue. I’m not sure exactly which command got the installer to stop hiccuping and complete the installation, but the two I used were:

killall -9 <ntfs-3g process>

rm -rf *

Maybe I needed only one, maybe both, I have no idea. But I do know that now it works, and I encourage anyone having similar problems to use these commands as a starting point for your research into a fix.

Once I got past that the rest of the install was a breeze. The computer booted up no problem and has been running like an absolute gem for a few hours now.

The GUI Add/Remove Software application is simply awesome, and made getting Flash, MP3 support, and many other items a breeze.

Now that Gutsy Gibbon is up and running you can expect some Linux-related posts in the future, I just wanted to check in with you all and say a few words about my installation troubleshooting experience.

To end with, here is a screen shot of my current Ubuntu desktop:

Ubuntu Desktop

Debian Or Ubuntu: Which Linux Distribution Do You Prefer?

According to a search run on Linux.org, there 218 currently maintained Linux distributions. Two of the more popular ones that have widespread adoption are Debian and Ubuntu. But how does a person choose one over the over? While there are similarities between all Linux distributions there are also stark differences.

Well, for those on the fence between Debian and Ubuntu, perhaps this may help you in making your decision:

Debian Linux girlUbuntu Linux Girl

Personally I’m an Ubuntu man, but we all have our different tastes when it comes to Linux. :)

UPDATE: The original Debian girl photo has been removed at the request of someone whose opinion I can respect. This post was in no way meant to inflict damage of any sort on anyone. If it has done so inadvertently, my apologies.

That being said, to the women who so ignorantly attempted to bash me, realize that by judging me with this post you’re committing the same act that you’re criticizing me for: misrepresentation.

Why I Really Prefer Mac Over PC

I’ve been using a PC for around 15 years, with my first experiences dating all the way back to the time of Windows 3.1. I’ve gone through all the stages of being a PC user, from beginner to power user, and have used a PC in many capacities — educational, home, and professional. Thus, in all my experiences, I have learned the PC inside and out.

A little over two months ago I purchased my first Mac, the Macbook that I am typing on this very moment. While Apple loves to run dozens of commercials outlining the many potential reasons to switch from PC to Mac, the biggest one I had at the time was curiosity — I had always wanted a Mac.

I wanted to ignore the hype and just get one because I wanted to, for the same reason we all started on computers back in the day — to explore something new. I believe I was successful in going into the world of Mac with an open mind, not expecting to answer any pre-conceived hypothesis. But what I have found along the way, however, is that Macs truly are better than PCs. Not for any single cheap shot taken against Windows in an Apple commercial, although some of those stereotypes are true, but mainly for one central reason: Macs provide a better overall computing experience.

From the moment I first powered up my Macbook I knew there was something special about it. The installation was remarkably simple in comparison to Windows or even Linux. Once it was installed, I already had all the programs I needed, there was no need to browse through download.com looking for small applications and utilities needed to work with certain files on a daily basis.

When I click on something, it opens, promptly and without a problem. So many times when I’m on Windows I click on something and have to wait 10-20 seconds for it to open. On my Mac, the computer does what I tell it, when I tell it to. Building on that further, the computer is not only able to do what I ask but is able to sustain itself and continue to perform commands. On Windows, I find that programs I’m using freeze constantly, and I’m forced to open the task manager to quit them — that in and of itself only works half the time, and the other half I need to hold down the power button and cold boot the PC. My Mac has had a program freeze on me twice. Both times only the program (Safari) froze, and I was still able to use other programs, and no reboot has been required.

The stability of Mac is far superior to PC. One of the first things I do after installing Windows is download Ad Aware. I have to run it about once a week or else my PC runs down to a grinding halt. And Lord help me if one of the spywares gets on my PC, it totally takes it over and it is pop-up city. This has never happened on my Mac.

When I close the lid on my PC laptop and put it into sleep mode, it takes about 30-45 seconds to finish; on my Macbook it is about 2-3 seconds. Also, when I open the lid back up to resume from sleep mode, my PC laptop takes a good 30-45 seconds, my Mac takes 2-3 seconds. Using a Mac is just so easy, quick and efficient. Even the keyboard feels incredible to type on when compared to any PC laptop I have ever used (Sony, IBM, HP, etc.).

You may see some of the reasons I’ve listed here as petty, or something I’m just being uptight about. But the bottom line is that all computers essentially do the same things for us, so it does in fact come down to all the extra little things. I have been as objective as possible in my comparisons of the two, I still use a PC all day every day at work and enjoy it. But the bottom line is that if you want a better, easier computing experience, you should really go with Mac.

Gaim Becomes Pidgin

Pidgin AvatarThis isn’t exactly breaking news as it happened about 2 weeks ago — and I’m surprised I never saw this anywhere — but Gaim, the open-source instant-messaging client, has not only released a new version but has re-branded itself as Pidgin. For those unfamiliar with Gaim Pidgin, it is an IM client for Windows, Linux, BSD, and other Unixes that allows you to talk to friends on AIM, ICQ, Jabber/XMPP, MSN Messenger, Yahoo!, Bonjour, Gadu-Gadu, IRC, Novell GroupWise Messenger, QQ, Lotus Sametime, SILC, SIMPLE, and Zephyr all at the same time.

I don’t have all of the details, but from what I gather on their Web site they were having legal issues with AOL over trademark naming issues.

This release owes a special thanks to a bunch of people, but I especially want to acknowledge The Software Freedom Law Center, which has represented Pidgin in its negotiations with AOL and helped us form Instant Messaging Freedom Inc. … Now that our legal worries are behind us and the huge undertaking of 2.0.0 is complete, we’re all looking forward to continuing to actively develop Pidgin, Finch, and libpurple, and returning to our regular release cycle.

I’ve been a big fan of Gaim for many years since I started using Linux, as it was and probably continues to be the best Linux IM client in my opinion. As I just re-formatted the Windows PC I’m on right now, I needed to install an IM client. I figured hey let me throw Gaim on here seeing as AIM is slow as a dog nowadays, and to my surprise Gaim is now Pidgin. So the end result was installing Pidgin which so far is operating very nicely.

Let’s close this one out with some screen shots of Pidgin I captured during installation and first operation:

Pidgin Screen Shot

Pidgin Screen Shot

Pidgin Screen Shot

Pidgin Screen Shot

Pidgin Screen Shot

Pidgin Screen Shot

Pidgin Screen Shot

Pidgin Screen Shot

Pidgin Screen Shot

Pidgin Screen Shot

Geek Stats

Lately as I’ve been surfing around the blogosphere I’ve seen a lot of blogs where the author writes down a bunch of their stats with respect to geek stuff (computer, OS, etc.) Having always thought this was a pretty cool thing to do, I have added a section to my about page that details my geeks stats. However, seeing as very few of you seem to realize that there is an about page (or don’t care enough to click through to it), I am posting them here for your perusal.

So without further adieu, here are my geek stats:

  • Computers: 3 — 2 laptops (MacBook and Sony Vaio), 1 desktop PC
  • OS: Mac OS X, Fedora, Windows XP
  • Browser: Firefox, Safari
  • IM Client: iChat, Trillian, Gaim
  • E-mail: Gmail
  • Programming Language: PHP
  • Text Editor: Emacs
  • IDE: PHP Designer Pro 2005
  • RSS: Google Reader
  • Gaming Console: Xbox 360, Wii

To anyone who reads through that and knows what all of those are, I applaud you, and there should be more people like us. :)

Please feel free to contribute your own geek stats below.

Linux is Female, Penguins Everywhere Jumping With Glee

Novell has developed a series of ads playing off the whole “I’m a mac, I’m a PC” parodies by Apple in which they portray Linux as a young woman who sort of puts the Mac and PC boys in their places.

Take a look:

Sys-Con Announces Top 150 i-Technology Heroes

Sys-con has released their top 150 i-technology heroes who, according to their editors, columnists, commentators and readers, are responsible for the conception, building, maintenance and advancement of the internet, as well as modern computing as we know it. There are some real geniuses on this list, and while it’s too exhaustive for me to republish it here, I will name a few of the more popular ones. However, chances are only Brian and I will enjoy this post. :)

Here are some of the more recognizable mentions:

Tim Berners-Lee - Father of the World Wide Web
Sergey Brin - Co-founder of Google
Bill Gates - Chief Software Architect of Microsoft
Steve Jobs - CEO of Apple
Bob Metcalfe - Inventor of the Ethernet
Tim O’Reilly - Publisher, open source advocate
Dennis Ritchie - Creator of C and co-inventor of Unix
Dave Sifry - CEO of Technorati
Richard Stallman - Founder of GNU Project
Bjarne Stroustrup - Designer and original implementor of C++
Ken Thompson - Co-inventor of Unix
Linus Torvalds - Creator of Linux Kernel
Guido Van Rossum - Author of Python
Larry Wall - Author of Perl
Steve Wozniak - Co-founder of Apple
Jerry Yang - Co-founder of Yahoo!

I’m a Mac, and I’m a PC, but I’m Linux

Stumbled across this hilarious photo this morning which is horribly stereotypical, but I couldn’t resist posting it because it really is so true:

Mac vs PC vs Linux

To continue with this parody a bit more before ending this post, I’m going to quote a Digg user who wrote a would-be script for one of those Mac vs PC commercials that Apple puts out. However, in this case the PC guy has just switched from Windows Vista to Ubuntu, a popular Linux distribution.

Although the PC guy does talk about putting ‘Vista’ on his hardware. So they could do a add where he puts Ubuntu on. But I don’t think apple would want a script like this

“Hi I’m a Mac”
“and I am a PC!!!!”

“Wha.. Why are you so happy PC?”

“Noooo more Vista, gone! Out of here!!”

“Sooo umm, are you back to XP?”

“Nope, Ubuntu!”

“Err Ban Too?”

“Ubuntu. No surgery, no pain. Just a few questions about my name such and it was all working”

“That’s great, soooo what about your work, your photo’s, your music?”

“All taken care of! And none of that “Accept or Deny” gumbo either, security without the feeling of your teeth being pulled out”

“Ubuntu?”

“Ubuntu.”

*apple logo fades in*

PC guy “You know, this smug feeling, it feels pretty good..”

To some of you this might not make any sense and you may be sitting there with a blank look on your face, but to fellow computer geeks this is hilarious. :)

Fedora Core 6 Installation

Part one of my computer work at home is nearly complete. Last week I made the decision to remove Windows Vista from my laptop. I have the full retail version from Microsoft’s Technet, not a beta, but it just simply is not working out. But before I can get rid if it , I have gigabytes of data to backup. Thus my laptop’s weekend was constricted to backing up data (yes I just referenced my laptop in the 3rd person). However, playing around with my laptop got up my interest in playing around with my home desktop computer.

Currently my home PC is a Pentium III 800mhz, with 256 MB of RAM. I know, I know, horrible by today’s standards. However, this was a hand-me-down system from a friend and when I got it the system didn’t even turn on. I had to pop in some memory, a hard drive, and a PCI wireless ethernet device.. For simplicity I installed Windows XP at the time.

Now, working on my laptop got me interested in an old hobby: Linux. Again I originally installed Windows XP for simplicity, because I highly doubted that any flavor of Linux would support my PCI ethernet card out of the box.

I chose Fedora Core 6, a long-time favorite of mine. Many people swear over their children by Ubuntu but personally I’ve always had the best experiences with Fedora. The installation went pretty seamless. There was only one hiccup, where the installer said that the xcdroast package was missing or corrupt but after a few keystrokes of hitting the “retry” button it started working again; a slight issue reading the installation cd most likely. The total process took about an hour and a half I’d guesstimate, which is long for a Linux install, but also remember my horrible PC specs (I also chose to install a bunch of extras, such as French and Polish language support).

When the system was finished doing its thing I booted into Linux and was very delighted with the UI and simplicity of Fedora. It certainly has come a very long way from when I used to use RedHat 7.1. Unfortunately I was right and my PCI ethernet device did not work out of the box, so currently I have no internet access under Linux. After some brief research last night it appears as though I will be able to get it to work as long as I have pciutlis and ndiswrapper installed, at which point I should be able to load the windows driver and get it to work.

Once this is setup my computer work will be halfway complete, although I must say this is definitely the more difficult part, as the laptop work consists of inserting a restoration cd and copying and pasting data. I will keep you updated with my progress on getting the wireless to work, and I highly recommend it to anyone looking to venture into Linux.

Continue Next page