Linux Blog

Backup Utility Roundtable

Filed under: General Linux,Linux Software — TheLinuxBlog.com at 12:30 pm on Thursday, September 16, 2010

Did you remember to backup the files…?
All of them?
What do you mean *MOST* of them?
Well, you should have used one of these flippin’ utilities.
Off with his head!
(Read on …)

Reasons Why You Should Jailbreak YOUR iPhone

Filed under: General Linux — TheLinuxBlog.com at 12:10 am on Wednesday, January 28, 2009



I’m pretty sure that most Linux users understand what jailbreaking the iPhone is. For those that don’t in short its a way of breaking the restrictions Apple put on your phone, which allows you to escape the sandbox and do more with the phone.

Sure, jailbreaking may void your warranty (or may not) but why would you want to do it? Well the first and foremost reason is freedom.
Some of the greatest organizations in the open source industry were spawned from the inability to work with a particular device. I think jailbreaking your iPhone is similar to this, while the tools are so easy to use that any one can do it, jailbreaking your iPhone gives you the freedom to do what you want with it and this is what its all about right?

Bash. We all know that Mac OSX is based off of BSD and it just so happens the iPhone is too. By jailbreaking your phone part of the default installation (depending on how you do it) is a terminal with a bash shell. Most Linux users should be right at home here with utilities like apt-get, aptitude and ping.

Perl, Python, Java, PHP. These are some of the languages that you can configure to run on the iPhone. Sure, they may need some tweaking (especially Perl.) But it can be done. Who said iPhone development had to be done in Objective C?

Along with the Bash shell comes the Open SSH package giving you the ability to SSH into your phone, should you choose to install and configure. This can come in very handy for the Linux hacker. The ability to pretty much manipulate your phone however you want is a great reason to jailbreak.

You’ve always wanted to be able to record video right? Well you can, that is if you jailbreak and install an application. While the video quality is not exactly up to par its better than nothing. You could even turn your phone into a robot if you wished.

Also, do it because the Woz says so. Well, actually he didn’t explicitly say to do it, but apparently he does advocate it and “hacked” some chick called Griffin’s phone. So come on, be that “Throbbing brain with a tie” and jailbreak your iPhone.

Getting a Hand With Bash

Filed under: General Linux — TheLinuxBlog.com at 8:27 am on Wednesday, October 1, 2008

If you use the bash shell, or as many know it the terminal on a regular basis then there is a package that you can install that will make your life a whole lot easier. Firstly I’ll tell you a little bit more about it.
When I first started using Linux a friend told me to install this package. I never really understood what it exactly did, but using the terminal was a whole lot easier then using the command prompt in Windows. I couldn’t explain it but things just worked. Features that were missing from Dos were there. There was awesome auto completion that knew what I wanted to type. Over the years I became more accustomed to using Linux and the Bash shell. I upgraded hardware, changed distributions and never really noticed what I was missing out on. The other day I was thinking, wouldn’t it be nice if I could press tab and this would auto complete. Then it hit me, the package my friend had told me to install when I first was starting out. The package happened to be exactly for this purpose. Since I was a novice and he was helping me out I didn’t really have the time to ask about the details of every single package, so here I am now letting you in on a little secret. (Read on …)

Shell Script to get user input

Filed under: Shell Script Sundays — TheLinuxBlog.com at 2:06 am on Sunday, January 27, 2008

Creating a shell script to get input is rather easy. Shell scripts prompting input are generally more user friendly too. In this article I’ll show you how to read input from the bash shell. Take the example below:

#!/bin/bash

echo "Shell Script To Get User Input";

while read inputline
do
what="$inputline"
echo $what;

if [ -z "${what}" ];
then
exit
fi

done

All it does is echo’s the introduction “Shell Script To Get User Input” and then goes right to the bash read input loop. The next line makes a variable so that we can echo it out and also check if its empty with the if [ -z part. If the script is empty we exit, if not we loop around another time.

This is a very basic example but it can easily be modified so that you can use bash to grab user input. If you have any trouble with this script drop me a comment and I’ll be happy to help you out.

For, While and Until Loops in Bash

Filed under: Shell Script Sundays — TheLinuxBlog.com at 3:45 pm on Sunday, August 12, 2007

Normally in a shell script it is desirable to do something repetitive.
I have touched on some loops in other posts but now would like to go over them in a bit more detail. Each of the examples in this post are intended to give an introduction to looping in bash.

For Loops
For loops allow you to repeat a section of code a number of times. Its very similar to other languages syntax but works a little differently. The for loop in bash only allows you to give a fixed list of values to loop over. A good way to remember how a for loop works is “For each of the dishes: clean and dry.”
For Syntax:

for i [in list]
do
statements [use $i]
done

For Example:

for x in 1 2 3
do
echo “Number: $x”
done

echo “Finished!”

This is a very simple script that just counts to 3 and then prints “Finished!”

While and until Loops
In essence while and until are the same in bash. The titles are pretty much self explanatory. A while loop would be explained in real life as “While the sink is still full: wash dishes” and a until loop would be “Until the sink is empty: Wash dishes.”
While and Until Syntax:

until/while [condition] do
statements
done

Example of a While loop:

count=1
while [ $count -lt 10 ]; do
echo $count
let count=$count+1
done
echo “Finished!”

Basically this loop will loop over the code while the count variable is less than 10. If we didn’t put the let statement in the script it would get stuck in the loop causing the user to press CTRL+C to end the script.

Doing the same thing can be done in a until loop except the condition has to be modified to get the same result.
Until example:

count=1
until [ $count -gt 9 ]; do
echo $count
let count=$count+1
done
echo “Finished!”

Now that you’ve figured out how to loop over something its probably a good idea to know how to stop the loop.
All that needs to be done to stop a loop is:

break

Break Example:

for x in 1 2 3 4 5
do
if [ $x = 3 ]; then
echo “Number is 3. Quitting”
break;
fi
echo “Number: $x”
done

This is a very easy to follow example. Its the same as the basic for loop except that if x is 3 it will stop the loop. This example has no real practical purpose. Since its a for loop the number 3 could just have been omitted.

Real World For Loop Example
Looping over all files in /etc and printing all of those that match “grep conf” and putting them in quotes.
The code to do this in a loop is:

for x in $(ls /etc -1|grep conf);
do
echo “$x”
done

The situation for many bash scripts is that there is normally a shorter way to do something. Take the Real World For Loop Example in this tutorial the same results can be achieved with:

x=$(ls /etc |grep conf); echo “$x”\n

This will get the job done but a loop may be better for esthetic purposes or for additional logic.

When Photoshop Fails

Filed under: General Linux,Shell Script Sundays — TheLinuxBlog.com at 9:50 pm on Monday, January 15, 2007

I was recently assigned the task of reducing the quality of over 1000 images. My first instinct was to use photoshop’s batch functions to complete the task. After playing around with it for a little while it became apparent that you cannot save files for web with spaces in. Photoshop had failed me. My next idea was to use a bash script to loop over every file and process the image. This was sure to work. Since I have prior experience with image processing I decided to use ImageMagick to complete the task. The command to adjust the quality is:

convert (FILENAME) -quality 50 (FILENAME)

This command is useless on its own so using a for loop I came up with:

#!/bin/bash
for i in $(ls); do
convert $i -quality 50 $i
done

This script would have worked for me if there were no spaces in the filenames. Because there were it took each filename that had spaces and ran the command on each part of the file name. Unfortunately this was not going to work.

After googling for a while it became apparent that I was not the only person to have the problem of spaces in filenames with for loops. The solution I found was to use the find command and a while loop. Below is working script that successfully completed the task in no time:

#!/bin/bash
find * -iname “*” | \
while read I; do
convert “$I” -quality 50 “$I”
done

This script could be easily modified to take advantage of ImageMagick’s many other functions. For example it could be used to batch resize a folder of images to make thumbnails by changing the command to

convert “$I” -resize 200 “$I”

Or it could be used to overlay text onto an image with the following command:

convert “$I” -gravity southeast -annotate +5+10 “thelinuxblog.com” -fill black “$I”

As shown above ImageMagick is really powerful image editing software which can easily be used with the bash shell to process thousands of images with no trouble.