Archive for July, 2009

So im making a web interface for troubleshooting mpls links for some customers, Im writing the entire thing in bash, and things were going pretty well till yesterday. ( i started on saturday). You see the first page currently has the name one customer currently with a small input form next to and a troubleshoot button next to it, Now for a Mpls vpn customer there are various ways to provide last mile connectivity, im not talking about physical connectivity but the logical PE-CE connectivity, anyways after a few basic steps of automated telnet i will end up on the last mile PE and from there i want to do a source destination ping using vrf , somewhat like this

ping vrf CUSTOMER 20.20.20.2 source 20.20.20.1 repeat 3

or i use a source interface to ping , which is pretty much the same as source ip, now 20.20.20.2 is  a variable which we get when somebody inputs it into the webpage. so actually when i send the commands the ip and interface are basically variables sent across. Which actually works fine. the issue comes up when the last mile connectivity has been temporarly given on a gre tunnel , Now in this case i need to breakdance with cat/grep/sed and get the source and destination ip of the tunnel and then send across those variables to check if that connectivity exists. I know its anal, if the tunnel ip’s dont ping then 99% the tunnel destination from the tunnel source won’t ping, but i wanted to follow proper steps in this automated troubleshooting system i was building. so the command sent across is

ping $destination source $source repeat 3

But it did’nt work, since i was pushing all output to a txt file ,  i could see that command being run on the router was

ping $destination

thats it ! , now since im no programmer, it took me some time to understand whats going on, i figured there’s a new line character being added to the $destination variable which i take after certain cat /grep/cut commands done on the output file.  so i added this to the if else command after reading about the tr -d ‘\n’ command somewhere on the internet

$dest=$(echo $dest | tr -d ‘\n’)

Still didnt work, couldnt figure it out, but then i remembered that there is also a carriage return character \r , what if that also gets added in the variable,  so next step was

$dest=$(echo $dest | tr -d ‘\r\n’)

and this time it worked, perfectly fine.

I feel like i will be never able to understand programming completely, because such kind of problems take me two days, but once i get the solution i dont care, im happy and i move forward. scripting/programming for network troubleshooting, is much more rewarding that plain network troubleshooting.

twitter client in bash

| July 24th, 2009

So continuing with my silly scripts here’s another one to update your status on twitter, drop it in your /usr/bin and then type bwitter and then your update and then enter, thats it. of course edit your username and password for it to work . ctrl-c closes the client. im using in xterm and typing in a lot of useless updates

#!/bin/bash

#Author::deadwait

#name::bwitter

echo type in your update
read update
curl -u username:password -d status=”$update” http://twitter.com/statuses/update.xml | grep ZZ

bwitter

silly silly script

| July 15th, 2009

I can be very lazy i guess, while reading beginning perl, available here http://www.perl.org/books/beginning-perl/   i got tired of opening a new file and typing in /usr/bin/perl and then the name, and needing it to chmod +x everytime , so i write a script to do the same for me,

so all i do is type newperl month and a file with month.plx and the necessary shebang and filename and author name is created . ofcourse i dropped it in /usr/bin for it to work anywhere. below is the script. just change the author value to your name

#!/bin/sh
#newperl.sh
author=deadwait
if [ -z $1 ]
then
echo “You have not mentioned a filename”
exit $E_NOARGS
fi
echo “building file $1.plx”
echo “#!/usr/bin/perl” > $PWD/$1.plx
echo “#$1.plx”>>$PWD/$1.plx
echo “#Author - $author” >> $PWD/$1.plx
chmod +x $1.plx
echo “Done “