Friday, October 8, 2010

Expect scritp runs multiple cmds taking as a variable

Hi as part of unit testing i have written a expect script that expects same things but i need to send some list of cmds. For the first time i have written in the sequence of expect, send, sleep and then for the second and go on. But script is very lengthy if i want to see execution flow of cmds i need to scroll down to entire script.
So i find an alternate solution where i kept all my cmds in one varible and split on newline (i used newline, can be changed) and send these cmds one by one using for.
Below script is small example which will explain what i have done. Pretty simple logic and very basic too.
Have a look......

#!/usr/bin/expect -f
set data "ls
pwd
cd ..
ls
pwd
cd ..
pwd
ls
cd /etc
pwd
ls
cd /home/baluenigma
exit"

#Spwan the Cfm1 Util stub
spawn /bin/bash
match_max 100000

foreach line [split $data \n] {
expect "[baluenigma@192.168.2.79 *]#"
send -- "$line\r"
sleep 1
}

Above data is varible which holds all cmds which need to be executed.
Foreach is used to read data varible and split on newline char and line varible takes that value. Now expect cmd expects "[baluenigma@192.168.2.79 *]#" here '*' used because pwd will change when i used cd cmds which are in data variable.

Tuesday, October 5, 2010

Flv to 3gp converter

First of all I was installed ffmpeg on my centos 5.1 using yum.
If you don't have then simply run "yum install ffmpeg*".
Now to convert flv into 3gp, ffmpeg should contain h263 vedio codes generally it has and amrnb audio codes. In my case i don't have this audio code which was downloaded. Compiled and installed without any problem.
Create a file /bin/fl23gp and write below code.
------------------------------------------------------------------------------------------------------------
#!/bin/bash
echo "flv 2 3gb Convertion"
echo ""
if (($# ==0))
then
echo "Usage: flvto3gp [flv files] ..."
exit
fi

while (($# !=0 ))
do
ffmpeg -i $1 -s 176x144 -vcodec h263 -r 25 -b 200 -ab 6.7k -sameq -acodec libopencore_amrnb -ac 1 -ar 8000 ${1//.flv/.3gp}
shift
done
echo "Finished flv-to-3gp convertion"
echo "\" Enjoy \""
echo ""
------------------------------------------------------------------------------------------------------------
Run "chmod 777 /bin/flv23gp" .

"ffmpeg -formats | grep amr" will return what are audio codes preset with amr. Which was mentioned in /bin/flv3mp3 file for -acodec as "libopencore_amrnb" .