Linux Blog

Asterisk AGI IP Address lookup

Filed under: General Linux — at 12:01 am on Sunday, September 19, 2010

While not exactly a shell script, I figured it would be worthy to post something rather than nothing and technically it is a script none-the-less.
I was experimenting with Asterisk AGI scripts and needed a project. I decided that an IP address lookup would be a good one. Sometimes my dynamic IP changes but my dynamic DNS doesn’t update. With this script, I should be able to dial into my Asterisk machine and get it to tell me the IP address. At least, that’s the plan.

(Read on …)

Coppermine Photo gallery Upload Script

Filed under: Shell Script Sundays — at 9:15 pm on Sunday, May 31, 2009

This week I bring you a script that I helped Kaleb (who has written posts here before) write. Well, I got him started with it, using curl and he rolled with it and finished it up. Here is the script:

# Script to Upload to
# Written by Kaleb Porter May 23 2009
# with help of
# email:
# if you wish to use this code for something else please give me credit
DA=`date '+%d%b%y-%N'`
# If the user does not specify a file or url
if [ -z "$1" ]; then
echo "You did not give a file to upload"
echo "Takeing a screenshot in 3 Seconds..."
sleep 3
scrot $DA.png
FI=`echo "$IMAGE" | grep '^[a-z]*://'`
FIUP=`curl -s -F control=phase_1 -F blaa=continue -F file_upload_array[]=@$IMAGE $URL | grep unique_ID | awk -F\" '{print $6}'`
URLUP=`curl -s -F control=phase_1 -F blaa=continue -F URI_array[]=$IMAGE $URL | grep unique_ID | awk -F\" '{print $6}'`
#Get the title for the image from the user and change all the spaces to "%20"
echo "Enter a title for the image"
read TITLE1
TITLE=`echo $TITLE1 | sed 's/ /\%20/g'`
#Get the Description for the image from the user and change the spaces to "%20"
echo "Enter a discription"
read DES1
DES=`echo $DES1 | sed 's/ /\%20/g'`
#Get the keywords for the image from the user and change the spaces to "%20"
echo "Enter keywords (separated by spaces)"
read KEY1
KEY=`echo $KEY1 | sed 's/ /\%20/g'`
if [ -z "$FI" ]; then
#echo "Choose the NUMBER value for the album  you want"
#curl -s -F control=phase_2 -F unique_ID=$UNIQUE_ID $URL | awk '/name="album"/{disp=1} {if (disp==1) print} /<\/select>/{disp=0}' | grep 'value="[0-9]"' | sed 's/<option//' | sed 's/<\/option>//' | sed 's/>//'
#read AL
curl -o /dev/null -d "control=phase_2&unique_ID=$UNIQUE_ID&album=$AL&title=$TITLE&caption=$DES&keywords=$KEY&blaa=continue" $URL
exit 0
# If the image is from a URL
#echo "Choose the NUMBER value for the album  you want"
#curl -s -F control=phase_2 -F unique_ID=$UNIQUE_ID $URL | awk '/name="album"/{disp=1} {if (disp==1) print} /<\/select>/{disp=0}' | grep 'value="[0-9]"' | sed 's/<option//' | sed 's/<\/option>//' | sed 's/>//'
#read AL
curl -o /dev/null -d "control=phase_2&unique_ID=$UNIQUE_ID&album=$AL&title=$TITLE&caption=$DES&keywords=$KEY&blaa=continue" $URL
exit 0

If there are any questions you can pretty much read the Shell Script Sundays column and figure out everything you need to know. Now that the upload script works, and tries to take a screenshot with scrot, the next step is a check to see if scrot exists, if it doesn’t a check for import, if not an error message.

It really does amaze me at the capabilities of the shell. Especially how mashable it is and how you can combine it with pretty much anything, this script is a great example of combining the power of the shell with the intrawebs. Well, I hoped you learned something, and as always if you have any questions, you know where the comment box is.

– Owen.

Check if SELinux is Enabled

Filed under: Shell Script Sundays — at 10:41 am on Monday, December 8, 2008

This weeks (now late) Shell Script Sundays (posted on Monday) article is a short one on a check to see if SELinux is enabled. While SELinux has some great security enhancements it can present a number of problems in applications and shell scripts alike. There is a simple utility that comes with many Linux distributions called “selinuxenabled”

selinuxenabled exits with a status of 1 if it is not enabled and 0 if it is. Zero normally means false but in this case since it is an exit status it is an exception. So, if you need to do a quick check, you may just run selinuxenabled. You will quickly find that it returns nothing. To figure out the exit status for your quick check, put an ampersand (&) at the end, and it will tell you the exit status. eg:

[ ~]# selinuxenabled &
[1] 28417
[1]+  Exit 1                  selinuxenabled

As we can see from the example above SELinux is disabled.

To use selinuxenabled in your scripts you would use it like any other command. Refer to Shell Scripting 101 for some more information. selinuxenabled can also be used in your scripts to make sure that selinux is enabled, which can be useful if you are trying to do security audits across multiple machines.

Whats in your Feed Reader?

Filed under: General Linux — at 4:18 pm on Friday, November 14, 2008

Hey, today I’m asking the question as to whats in your feed reader. I mostly ask this question because I’m interested in what other people are reading and writing.  Here is a list and commentary of the Linux and tech related feeds that are in my feed reader. I invite you to add your feed to my list, and perhaps walk away with some feeds that you were not aware of. This is not a comprehensive list, I’ve only added the ones that have been updated recently and those that I have commentary about.

The Linux Blog
Feed URL:
Well, who doesn’t subscribe to their own blog? I mean I have to have some one reading my blog right? Seriously though, I’d appreciate it if you subscribed to my RSS feed and occasionally left comments! Announcements (Global)
Feed URL:
For those who don’t know about freshmeat:
“Have you been living under your desk?”
This is a decent feed it provides information about software that has been updated. I use it to get notified when there are updates and to find new projects.

Technorati Linux Related
Feed URL:
This is a very basic feed that grabs blog posts from Technorati. I don’t have this one set to notify me because I’d never have time to work. I just check it from time to time and see whats going on.

Linux Journal
Feed URL:
Any one who’s picked up a magazine knows about The Linux Journal, but may know know that they should subscribe to their RSS feed. I like the magazine and their feed is great too. They post a decent amount of news, reviews and informational content so its worth signing up. Hopefully one day they’ll send me some promotional material or something for being so loyal.

Red Hat Magazine
Feed URL:
Red Hat Magazine, what more is there to say? Its a magazine about Red Hat related technologies. They have great content and a great editorial team. They don’t just post on Red Hat topics either so give it a subscription if you want something different.

Free Software Foundation – FSF Blogs
Feed URL:
FSF enough said right? Well, not exactly. I love the FSF and all they do so I subscribed to their blog. Perhaps I should subscribe to more of their feeds since they do such a good job.

Ubuntu Geek
Feed URL:
Although I’m not the worlds largest Ubuntu fan (I probably fall in-between, but no where near UbuntuHater) I still like to keep up with whats going on in the Ubuntu world. Since a lot of what applies to one Linux distribution applies to another, this is a good one.

Debian Package of the Day
Feed URL:
Debian has the most packages available (I think). So I subscribed to their feed thinking, cool a piece of software a day. Cool right? Well sort of. The title of the feed is some what misleading because I do not get a package of the day every day. Perhaps one a week. But still one a week is better than none a week right?

Mark Shuttle Worth
Feed URL:
Here Be Dragons! Most know as the founder of Ubuntu, but also well accomplished in the cryptography field (read Thawte) First African in space. Always very interesting content. Respect!

Linus’ Blog
Feed URL:
Who has that T-Shirt:
“Linus is My Homeboy?”
Yea, me neither but I do subscribe to his feed just because I can. Although I feel some what voyeuristic since it is some what personal. I think its very intriguing, while others call it stalking.

Feed URL:
I didn’t even know where Bohol was before subscribing to this feed. Subscribing to this feed will give you articles about Linux and other technical topics. But I still don’t know where Bohol is. (just kidding I googled it)

Ian Skerrett
URL: |
Feed URL:
Follower on Twitter Ian Skerrett is the director of something or other really important with the Eclipse foundation. (Marketing) I read his blog from his Twitter link and decided that it would be a useful feed to add to my reader.
Feed URL:
Website that lists a bunch of tips for Linux. Some more useful then others, and some if you are an experienced Linux user perhaps will seem like common knowledge. If you want tips and want them in your RSS feed reader, get them here!
Some Other Feeds

Geekologie – Gadgets, Gizmos, and Awesome
Feed URL:
I’m not sure who pays this guy but its humorous. Borderline safe for work and perhaps the biggest time waster I have in Akregator.

Life Hacker – Excerpts
Feed URL:
Life hacker, hack your life? No not exactly. Tips on how you can improve your life. Topics range from genius to dumb to common knowledge. (such as how to wrap your cords up, which we all know cords are suppose to be plugged in and in a birds nest under your desk) This site is for those like me who want to be more productive and … wait never mind I’m just digging myself a bigger grave. Seriously though Lifehacker does have some good content. Just don’t read the comments.

Feed URL:
Keep up with the latest gadgets that you will never get. Thats pretty much how I view engadget. I like it, but I used to like it more. So I think of it as a legacy feed. Around just because I wouldn’t feel right deleting it.

In Closing
Feel free to suggest feeds to me I’ll more than likely add them. If you are not on the list and just have to be leave a comment. I may have you in my feed reader already. This also is not my whole list. If I had to write a description about every feed do you know how long I’d have been writing this?

SSH Escape

Filed under: General Linux — at 2:27 pm on Tuesday, September 2, 2008

You can get into a special area of SSH that you by using the SSH Escape key sequence.It can be set at the connection time to a custom character but if you didn’t set one it is probably set to the Tilda (~). To open the SSH Escape dialog to manage your connection (I assume you know what you want to do, but your wondering how you use it)

Its simple to use; just hit shift, then the back tick (`) to get the Tilda (~) then type the command you want to use.

For example to pull up the SSH Escape dialog help up you use the question mark (?) so do the following:

[owen@Linux_Blog ~]$ ~?
Supported escape sequences:
~.  - terminate connection
~B  - send a BREAK to the remote system
~C  - open a command line
~R  - Request rekey (SSH protocol 2 only)
~^Z - suspend ssh
~#  - list forwarded connections
~&  - background ssh (when waiting for connections to terminate)
~?  - this message
~~  - send the escape character by typing it twice
(Note that escapes are only recognized immediately after newline.)

For more information on the SSH Escape Sequence check out the SSH Man Page

Post By: Owen From:

Reworking Shell Scripts

Filed under: Shell Script Sundays — at 7:02 am on Sunday, August 24, 2008

To me shell Scripts are all about automation, their primary purpose is to get stuff done. If you have a one liner, snippet or other script you use on a regular basis, have you thought about how you could rework it for it to become more in handy?

Lets take last weeks snippet from this column. It was a simple one liner to reconnect to a host. Now, I knew when I posted this article that it was a helpful snippet of code. Now, how can this script be adapted to be a neat utility that we use on a regular basis? Over the next few week’s we’ll find out.

The first thing that I will note on is that this script or shell snippet is a pain to remember. Does a script save you time if you can’t remember how it works? Is it worth the hassle? Not exactly. So, in order to make this snippet a little better the first thing we are going to do is add something that it needs: parameters. Adding parameters to shell scripts is actually easy, much easier than adding parameters to some other languages that we wont mention. although this script does not use it getopts can be used. I’ve covered how to do this with getopts in other posts. Just do a site search (located at the bottom of the right bar for getopts.)

So, here is the modified script that automatically reconnects to a host by using ping and SSH:

# Sleep Time Default: 15 seconds
# Set a default user up
#usage function
usage () {
echo -e "Usage: $0 host [user] [Sleep Time]"
# display usage if no host is specified
[ -z $1 ] && { usage && exit 1; }
# set the variables
[ $1 ] && { HOST=$1; }
[ $2 ] && { USERNAME=$2; }
[ $3 ] && { STIME=$3; }
# trying:
echo -e "host: $HOST \nuser: $USERNAME \ndelay: $STIME"
while ! ping -W 1 -c 1 $HOST 2>&1 >/dev/null; do true; done && echo "Successful waiting: $STIME secs"; sleep $STIME; ssh $USERNAME@$HOST

Now that you have that done, all you need to do is give the file a name (I called mine ssh_auto) and put it in a folder in your path. Use the filename and parameters defined in the script to connect to the host.

The next shell scripting article I demonstrate how you can further rework shell scripts to better suit your needs.

Logging Sessions to Twitter

Filed under: Linux Software — at 12:01 am on Wednesday, August 20, 2008

If you follow me on Twitter you would know I asked everyone if there was anything that they wanted me to write about. @Ben_Marvin responded and asked about logging the commands you type to Twitter.At first, I thought that this could be done with history, which it probably can be, but does everything you type really have to be echo’ed to Twitter? I don’t think that you’d have many friends, Twitter would probably hate you and you’d most likely hit your maximum requests per hour pretty quickly.The Script command is another option, and this works quite well for this purpose. Read the script man page to find out more about this program. It basically (when ran) takes the I/O from your terminal and logs it to a file. Its a very handy utility.So, how do we get this data into Twitter? First of all, Twitter doesn’t allow very long posts so echoing out the data that the commands you type is not really practical. The best way to do it is to use script to log the session, exit the session and grep for the “]0\;” string for stuff you typed & not the responses.Here is the code:

script; grep ]0\; typescript 

You can then copy and paste it to your favorite Twitter application or pipe it to a scrubbing script to remove the formatting and do the correct HTML stuff, then post it via the http interface. Either way, it can be done even though I don’t think it really should.

Simplify Media: How’d they do that?

Filed under: General Linux — at 4:39 am on Tuesday, August 19, 2008

By now every bodies probably heard about the service which just released an application for the iPhone / iTouch that basically lets you stream your, or your friends music though your phone. Its integrated with iTunes, Winamp and RhythmBox on Linux which is pretty cool. I think this is a neat idea and started thinking: “How’d they do that?”

It seems like it would be pretty difficult to achieve something like this, but in fact the concept is quite simple.

iTunes has a DAAP server built in for multimedia streaming media. What Simplify Media does is connect the stream to their server and then when another client (iPhone app / friend) logs in, if the Simplify Media application is running (on your PC) it lets you know and lets you start streaming it.

I have not analyzed to find out the EXACT method of how it works quite yet but I assume that it either uses Simplify Media’s bandwidth to stream (over https) or creates a reverse connection some how. If any one knows the details I’d be interested to know.

My other thoughts / questions on this are:

Will there be a free DAAP client available for the iPhone / iTouch?
Wouldn’t it be cool if you could record the streams?
How long before Apple pulls this application?
Will AT&T or Simplify Media kick you off, throttle, or even worse charge you for using this service?
If they are using Simplify Media’s bandwidth how are they making money?
How long will it be or will there ever be an open implementation of this?

I can’t really answer any of these questions so, if any one wants to take a stab at answering them go for it!

Automatically reconnecting to a host

Filed under: Shell Script Sundays — at 9:15 pm on Sunday, August 17, 2008

If you follow me on Twitter: then you may know that I regularly update a bunch of Linux PC’s and servers. Now, since I’m sort of lazy and don’t like manually doing anything I don’t have to I thought I’d post the one liner I use to automatically reconnect to a host.

while ! ping -W 1 -c 1 [hostname or IP] 2>&1 >/dev/null; do true; done && sleep 15; ssh [user]@[hostname or IP]

This script uses the ping command to ping the server once (-c 1) with the timeout of 1 second (-W 1) ping a host or IP with a timeout of one second. Once the ping loop is broken (ping returns true) I let it sleep for 15 seconds to enable SSH to come up. Then the inevitable happens. I use SSH to reconnect to the host.

There you have it, a quick way to reconnect to a host without typing the command or pressing the up arrow every time. Enjoy!

cURL Gotcha’s

Filed under: Shell Script Sundays — at 4:31 pm on Sunday, February 17, 2008

I’ve been using cURL for a couple of projects recently and I thought I would just post a couple of the “Gotcha’s”

Feel free to add to the list by leaving a comment.

1) User Agent. Certain websites especially Google like to block the use of curl because some people use curl for abusive reasons. This can be fixed by changing your user agent.

User Agents can be switched with curl by using the -A or –user-agent switch.

To change your user agent to Internet Explorer 7 or IE7 on Vista do the following when requesting a page:

curl -A "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)" [URL]

Should you want to change your user agent to Netscape 4.8 or Opera 9.2 on Vista you can use the following agent strings:

Netscape user agent string

Mozilla/4.8 [en] (Windows NT 6.0; U)

Opera user agent string

Opera/9.20 (Windows NT 6.0; U; en)

2)  Separate post data with ampersands or put spaces in between your -d’s  This one got me once.

3) Don’t try to post and try to use -G for get requests if you want to post data.

-G makes everything that is in -d get put into a get request instead of a post. Use the following format if you want to post and use get requests.

curl -d "post=data&more_post=moredata" urlgoeshere.php?get=getdata

I’ll post more of these as I remember them, again as stated above if something has got you with curl post them here and I’ll add it to the list with a link to your site! Thats all for this week – Owen.

Linux Experts

Filed under: General Linux — at 3:46 pm on Wednesday, January 2, 2008

After researching Bomgar I thought this could be a good home business. So I started researching to see what companies out there offer Linux services. What did I find? Well, not a whole lot of anything really. I mostly found a whole bunch of junk on the web and a lot of pages with “It Works!!!” (apache setup congratulations page) domains. This made me think that the Bomgar solution could work for any one with the Linux skills needed to support customers and the time to invest in marketing such a company. It is something that I am very interested in doing.

Whilst researching this led me to another thought
“What exactly is a Linux Expert anyway?”
I still can’t come up with a way to describe it. There are so many topics that it (in my opinion) is hard to be a true “Linux Expert”. You have to be more than just a jack of all Linux related trades but also a master of communication and project management. Something most “Linux Experts” lack. I tried to come up with a good way to compare it to another field.

I could compare a Linux Expert to a mechanic. I say this because there are many types of mechanics. Some better than others, some are totally non related. Take an aircraft mechanic, this is a whole lot different from an automotive mechanic. I wouldn’t want my car mechanic working on a plane I would be flying on. This would be like having your Linux sales expert configuring your advanced partitions with fdisk. The chances are they might break something along the way. The results may not be as bad as the loss of human lives but you get the point.

In my opinion there are a lot more Linux experts out there than you think. Just like there are a lot of people who are expert mechanics but do not have the title. Every one knows some one who can fix their car because its a popular service. Are Linux experts lacking because there is no demand for Linux support? Or is it because nobody can find the real experts?

You decide & let me know!

Next Page »