Archive

Archive for the ‘linux’ Category

update and retrieve twitter timeline from linux shell

January 24, 2009 8 comments

you can update your twitter status and follow feeds using linux shell, this is a quick tip for linux lover’s, this is the reason i prefer linux over other operating systems is it’s total usefullnes,

to post your status on twitter type:

curl -s -u username:password -d status="your_status_message goes here" http://twitter.com/statuses/update.xml > /dev/null

replace username, password and message to post with the your own.

to follow feeds from twitter.

curl -s -u username:password http://twitter.com/statuses/friends_timeline.rss | grep title | sed -e 's/]*>//g'

replace username and password with your own. above command will retrieve recent rss entries from your twitter timeline.

one more cool thing you can do with this long command is to enclose it put it in a text file, let’s say “/usr/local/bin/get-twits” and make it exectuable by issuing

chmod a+x /usr/local/bin/get-twits

now open a new terminal windows and type:  watch --interval=60 get-twits

this command will keep your terminal windows updated with recent twitter updates.

enjoy 🙂

Advertisements

cloning harddrives over network

December 30, 2008 6 comments

To clone identical drives in a linux system you can use dd command, dd command makes it really easy.

dd if=/dev/hda of=/dev/hdb

above command will clone hda to hdb (partitions, boot record etc), but what if you have to clone a drive that is not attached to same system?

I found a really interesting way to transfer files over the network simple by using netcat and dd.

  • Boot the machine (where second drive is attached) with a live cd distro like Ubuntu or Knoppix. Setup networking or let the DHCP server assign an ip automatically. My DHCP assigned this machine ip 192.168.0.21
  • run following command on this machine
    nc -l -p 7777 | dd of=/dev/hdb
    (where /dev/hdb is the target drive)
  • Now come to the machine where you have attached the drive to be cloned and issue following command.
    dd if=/dev/hda | nc 192.168.0.21 7777
    (/dev/hda is the drive to be cloned)

It will take time (usually several hours) depending on size of the drive. If you are worried about bandwidth you can pipe through gzip to compress and uncompress the streamed data on source and destination machine respectively, to do this you would run following commands.

On target machine:

nc -l -p 7777 | gzip –dfc | dd of=/dev/hdb

And on source machine.

dd if=/dev/hda | gzip –cf | nc 192.168.0.21 7777

have fun with dd and nc 🙂

Categories: linux, ubuntu Tags: , , ,

asterisk 1.2 with realtime ldap driver

December 28, 2008 13 comments

I have created an auto install script based on http://www.cahilig.org/install-asterisk-12-auto-install-script-centos-4-and-centos-5 to install Asterisk 1.2 with ldap realtime driver support (modified original script to enable realtime ldap support).

This script should work almost with any(Redhat, Centos, Mandrake, Debian, Slackware) Linux distro

Before running this script you must install following packages.

For Centos, Redhat:

yum install openldap-devel gcc kernel-devel bison openssl-devel libtermcap-devel ncurses-devel

For Debian, Ubuntu:

apt-get install libldap2-dev build-essential linux-headers-`uname -r` libncurses5-dev libssl-dev

You can download the script from here, simply run the script to start installation process.

download Asterisk schema for OpenLdap here

Installer and installation process is not tested, if you find any problem please let me know.

#!/bin/sh
#Asterisk Download page
ZAPTEL="http://downloads.digium.com/pub/zaptel/releases/zaptel-1.2.9.tar.gz"
ASTERISK="http://downloads.digium.com/pub/asterisk/releases/asterisk-1.2.30.tar.gz"
ASTERISKADDONS="http://downloads.digium.com/pub/asterisk/releases/asterisk-addons-1.2.9.tar.gz"
RTLDAP="http://free.oxymium.net/Asterisk/res_config_ldap.tgz"
RTLDAPPATCH="http://mustafa.pk.googlepages.com/res_config_ldap.c.patch"
CONFIGPATCH="http://mustafa.pk.googlepages.com/config.c.patch"
MAKEFILEPATCH="http://mustafa.pk.googlepages.com/resmkfile.patch"
#Asterisk Package
ZAPPACKAGE="zaptel-1.2.9.tar.gz"
ASTPACKAGE="asterisk-1.2.30.tar.gz"
ASTADDONSPACKAGE="asterisk-addons-1.2.9.tar.gz"
#Asterisk Folder
ZAPFOLDER="zaptel-1.2.9"
ASTFOLDER="asterisk-1.2.30"
ASTADDONSFOLDER="asterisk-addons-1.2.9"
REALTIMEDIRVER="res_config_ldap.tgz"
if [ -f /etc/redhat-release ] ; then
DISTRO="redhat"
elif [ -f /etc/debian_version ] ; then
DISTRO="debian"
elif [ -f /etc/SUSE-release ] ; then
DISTRO="redhat"
elif [ -f /etc/mandrake-release ] ; then
DISTRO="mandrake"
elif [ -f /etc/slackware-release ] ; then
DISTRO="slackware"
elif [ -f /etc/gentoo-release ] ; then
DISTRO="gentoo"
fi

echo "Downloading and extracting zaptel and asterisk source"
cd /usr/local/src/
if [ ! -e $ZAPPACKAGE ]; then
  wget $ZAPTEL
fi
if [ ! -e $ASTPACKAGE ]; then
  wget $ASTERISK
fi
if [ ! -e $ASTADDONSPACKAGE ]; then
  wget $ASTERISKADDONS
fi
tar -zvxf $ZAPPACKAGE
tar -zvxf $ASTPACKAGE
tar -zvxf $ASTADDONSPACKAGE 

echo "Installing zaptel"
cd $ZAPFOLDER
make clean
make
make install
cd ..

echo "Installing asterisk"
cd $ASTFOLDER
echo "Downloading patches"
wget $CONFIGPATCH
wget $MAKEFILEPATCH
patch -p0<resmkfile.patch
patch -p0<config.c.patch
echo "Downloading Realtime Ldap driver"
cd res
wget $RTLDAP
tar -zxvf $REALTIMEDIRVER
wget $RTLDAPPATCH
patch -p0<res_config_ldap.c.patch
cd ../configs
wget http://mustafa.pk.googlepages.com/extconfig.conf.sample
wget http://mustafa.pk.googlepages.com/res_ldap.conf.sample
cd ..
make clean
make
make install
make samples
cp contrib/init.d/rc.$DISTRO.asterisk /etc/init.d/asterisk
cd ..

echo "Installing asterisk-addons"
cd $ASTADDONSFOLDER
make clean
make
make install

echo "Loading ztdummy driver"
modprobe zaptel
modprobe ztdummy

echo "adding rules to /etc/rc.local"

echo "modprobe zaptel
modprobe ztdummy
" >> /etc/rc.local

echo "Downloading open source g729 codec"
cd /usr/lib/asterisk/modules/
wget http://asterisk.hosting.lv/bin12/codec_g729-ast12-gcc4-glibc-pentium4.so

echo "Running Asterisk"
/etc/init.d/asterisk start

echo "***********************************************************************"
echo "*             INSTALLATION SUCCESSFUL                                 *"
echo "***********************************************************************"
echo "* You can test if Asterisk installed successfully using               *"
echo "* asterisk -ncrvvv and start configuring your dial plan               *"
echo "***********************************************************************"
exit

“kill -9” song by monzy

December 27, 2008 1 comment

really funny rap song about “kill -9” command by Monzy at stanford university.

check it out: audio, video, lyrics

Categories: linux, videos Tags: , ,

encouraging FOSS adoption

December 15, 2008 1 comment

this blog talks about how to get more and more FOSS exposure in schools and organizations.

from A Quantum of FOSS:

I believe it is important for every parent and taxpayer to contact their school district’s superintendent and/or IT department and voice their frustration over the money spent on a fairly useless education tool like MS Office when entirely sufficient free replacements exist. Parents and taxpayers need to make it known that wasting public funds in this way is not appropriate and may very well impact their votes on future funding efforts like bonds and mill levies.

Read full post here.

break the firewall/isp — view blocked websites

December 2, 2008 9 comments

If a website is blocked by your ISP (or even government authorities). it is very likely that you can still gain access to those websites, this post will tell you how to bypass blockage by firewalls/ISPs, in order to achieve this goal we are going to use SSH tunneling to bypass firewalls and ISP’s rules/policies.

Preparation:

  1. windows users: download putty on your desktop.
    ubuntu users:
    no additional software/utility required.
  2. get an ssh account on a remote machine (e.g. an ssh server running at home), if you don’t have a machine running ssh service, you can still get ssh account from many paid and free ssh service providers listed here (a server in another country will help you browsing blocked websites by government agencies :)), I got a free account from rootshell.be and it’s tested.

Establishing the Tunnel:

for windows users I would recommend this video tutorial for tunnel set-up using putty.

Linux/Windows users can achieve this using following simple command.

ssh username@hostname -C -D 7070

where username is the username to connect with remote machine, hostname is ip or hostname of the remote machine, and 7070 is the tunnel port.

let me know if you liked this tip, comments and quries welcomed.

Categories: linux Tags: , , , ,

asterisk realtime with ldap — got it working :)

November 28, 2008 4 comments

When we decided to write an asterisk module for Zivios, we went in several debates either we should keep asterisk’s configurations in plain config files or get benefit of asterisk realtime ldap driver.

if you don’t know much about Zivios’s architecture, check out Zivios Architecture page. In short Zivios keeps all of its configurations(Users/Groups/Config files) in OpenLdap as far as there is a possibility to use Ldap as config back-end.

Finally we decided to test asterisk realtime ldap driver, in first attempt everything worked fine, I was able to retrieve sip/iax peers from ldap tree,store registry updates in ldap, also created few dialplan extensions in ldap and it worked as expected. then all the hell broke loose when i added a pattern (say _5XX) in ldap and asterisk couldn’t find it in ldap, I tried to debug the realtime ldap driver, but nothing helped. lastly I decided to look into the realtime ldap driver’s C code(my C knowledge is worst), put several debug messages all over the file, recompiled and came out with the conclusion that there is something wrong with a function called *realtime_multi_ldap, posted bug report to digium with my logs (Faraz Khan posted a bounty as well, check it out), but all in vain, it felt like digium and nobody else doesn’t give a damn about realtime ldap driver, i decided to forget the realtime thing and keep configuration in plain text file, wrote some handy(helper) perl scripts to add/edit and delete configurations(users/routes/queues/ivrs). Zivios’s web interface communicates with these scripts using a special XML-RPC agent (called emsmagent) running on asterisk box. emsmagent executes these perl scripts and returns output to Zivios.

Last month browsing through digium’s bug tracker I found this *realtime_multi_ldap patch, I decided to give it a try, was not expecting it would work, but interestingly it worked and now I can use patterns in ldap exten entry and it really works :).

I have written a custom ldap schema for realtime ldap, You can also check original schema posted and contributed by suretec (guy who fixed the ldap driver) here. I will soon post a how-to on “setting up asterisk realtime ldap”. I am also going to port Zivios Asterisk module from plain text files to openldap backend soon (much busy in some other interesting projects these days :D)

let me know if you need any help in asterisk and realtime ldap driver setup.