Feb
25

*** Introduction –

All you know about the haproxy, that its the one of the good opensource load balancing software and to check the fun stats of haproxy here we using ‘socat’ – Multipurpose relay (SOcket CAT)


* What is socat?

Socat  is  a  command  line based utility that establishes two bidirectional byte streams and transfers data between them. Because the streams can be constructed from a large set of different types of data sinks and sources (see address  types),  and  because  lots  of address options may be applied to the streams, socat can be used for many different purposes. (see more info at ‘man socat’ 🙂 or at http://www.dest-unreach.org/socat/)
* How to use ‘socat’ with haproxy stat

Step 1) Download ‘socat’ from http://www.dest-unreach.org/socat/download/  latest version ~ “socat-2.0.0-b3.tar.gz”

ravi@arun:~$ wget http://www.dest-unreach.org/socat/download/socat-1.7.1.2.tar.gz

ravi@arun:~$ tar xvzf socat-1.7.1.2.tar.gz

ravi@arun:~$ cd socat-1.7.1.2

NOTE ~ No need to install the ‘fipsld’ package if you got the below msg after running the ‘make’ just following steps for

compiling socat….

FIPSLD_CC=gcc fipsld -O -D_GNU_SOURCE -Wall -Wno-parentheses  -DHAVE_CONFIG_H -I.  -I.   -c -o socat.o socat.c
/bin/sh: fipsld: command not found
make: *** [socat.o] Error 127

ravi@arun:~$ ./configure –disable-fips
ravi@arun:~$ make

To install it login as root
ravi@arun:~$ su –

ravi@arun:~# make install

Step 2) Now you need to add stats socket PATH in Haproxy configuration and restart haproxy as per shown in following example,

where I have added it under in ‘global’ setting –

ravi@arun:~# more /etc/haproxy/myhaproxy.cfg

#———–Start of haproxy Config file————–
global
log 127.0.0.1   local0
log 127.0.0.1   local1 notice
#log loghost    local0 info
maxconn 25000
#debug
#quiet
user ravi
group ravi
stats socket    /tmp/haproxy
defaults
option          contstats
timeout         connect 5s
timeout         client 25s
timeout         server 25s
maxconn         100

listen ravitestbed      0.0.0.0:80 ##ravi.com IP
mode            tcp
balance         roundrobin
server          web1 192.168.19.117
server          web2 192.168.19.122

listen stats
bind            0.0.0.0:8081
mode            http
#stats          uri /stat  #Comment this if you need to specify diff stat path for viewing stat page
stats enable
stats auth admin:admin ##Auth user pass

#———–End of haproxy Config file————–

Step 3) Used /tmp/haproxy. Now you can send the commands to get stats from HAProxy –

Now time to use socat

ravi@arun:~# echo “”  | socat unix-connect:/tmp/haproxy stdio
Unknown command. Please enter one of the following commands only :
show info   : report information about the running process
show stat   : report counters for each proxy and server
show errors : report last request and response errors for each proxy
show sess   : report the list of current sessions

This will dump (possibly huge) info about all know sessions.

ravi@arun:~$ echo “show sess” | socat unix-connect:/tmp/haproxy stdio
0x9ee3520: proto=tcpv4 src=192.168.19.117:4721 fe=ravitestbed be=ravitestbed srv=arun as=0 ts=08 age=4s calls=3
rq[f=009202h,l=0,an=00h,rx=20s,wx=,ax=] rp[f=009202h,l=0,an=00h,rx=20s,wx=,ax=] s0=[7,8h,fd=1,ex=] s1=[7,8h,fd=2,ex=] exp=20s
0x9eeb8e8: proto=tcpv4 src=192.168.19.117:4723 fe=ravitestbed be=ravitestbed srv=arun as=0 ts=08 age=4s calls=3
rq[f=009000h,l=0,an=00h,rx=20s,wx=,ax=] rp[f=009202h,l=0,an=00h,rx=20s,wx=,ax=] s0=[7,8h,fd=8,ex=] s1=[7,8h,fd=9,ex=] exp=20s
0x9ef3d08: proto=tcpv4 src=192.168.19.117:4725 fe=ravitestbed be=ravitestbed srv=arun as=0 ts=08 age=4s calls=3
rq[f=009000h,l=0,an=00h,rx=20s,wx=,ax=] rp[f=009202h,l=0,an=00h,rx=20s,wx=,ax=] s0=[7,8h,fd=12,ex=] s1=[7,8h,fd=13,ex=]
exp=20s
0x9f04548: proto=unix_stream as=2 ts=09 age=0s calls=2 rq[f=00e042h,l=10,an=20h,rx=10s,wx=,ax=]

rp[f=048060h,l=716,an=00h,rx=,wx=10s,ax=] s0=[7,0h,fd=3,ex=] s1=[0,0h,fd=-1,ex=] exp=9s

This will give you information about the running HAProxy process such as pid, uptime and etc.

ravi@arun:~$ echo “show info” | socat unix-connect:/tmp/haproxy stdio
Name: HAProxy
Version: 1.3.23
Release_date: 2010/01/28
Nbproc: 1
Process_num: 1
Pid: 11829
Uptime: 0d 0h42m53s
Uptime_sec: 2573
Memmax_MB: 0
Ulimit-n: 50013
Maxsock: 50013
Maxconn: 25000
Maxpipes: 0
CurrConns: 1
PipesUsed: 0
PipesFree: 0
Tasks: 1
Run_queue: 1
node: ravi.world
description:

This will give you stats on all of your backends and frontends, some of the same stuff you see on the stats page enabled by the stats uri configuration. As an added bonus it’s all in CSV.

ravi@arun:~$ echo “show stat” | socat unix-connect:/tmp/haproxy stdio
#
pxname,svname,qcur,qmax,scur,smax,slim,stot,bin,bout,dreq,dresp,ereq,econ,eresp,wretr,wredis,status,weight,act,bck,chkfail,ch
kdown,lastchg,downtime,qlimit,pid,iid,sid,throttle,lbtot,tracked,type,rate,rate_lim,rate_max,
ravitestbed,FRONTEND,,,0,5,100,30,32582,50616,0,0,0,,,,,OPEN,,,,,,,,,1,1,0,,,,0,0,0,5,
ravitestbed,trupti,0,0,0,2,,15,7020,22722,,0,,0,0,0,0,no check,1,1,0,,,,,,1,1,1,,15,,2,0,,2,
ravitestbed,arun,0,0,0,5,,15,25562,27894,,0,,0,0,0,0,no check,1,1,0,,,,,,1,1,2,,15,,2,0,,3,
ravitestbed,BACKEND,0,0,0,5,100,30,32582,50616,0,0,,0,0,0,0,UP,2,2,0,,0,2710,0,,1,1,0,,30,,1,0,,5,
stats,FRONTEND,,,0,1,100,21,9605,152357,0,0,0,,,,,OPEN,,,,,,,,,1,2,0,,,,0,0,0,9,
stats,BACKEND,0,0,0,1,100,5,9605,152357,0,0,,5,0,0,0,UP,0,0,0,,0,2710,0,,1,2,0,,0,,1,0,,4,

show errors will give you a capture of last error on each backend/frontend.

ravi@arun:~$ echo “show errors” | socat unix-connect:/tmp/haproxy stdio

Reffer:
http://www.dest-unreach.org/socat/
http://haproxy.1wt.eu/download/1.3/doc/configuration.txt

Thanks to Joe (http://www.joeandmotorboat.com)

Thank you,
Ravi

(0) Comments    Read More   
Dec
31
Posted on 31-12-2009
Filed Under (Linux commands, Shell scripting) by Arun Bagul

Introduction ~

—————————————–
Program (1) ~ array.sh
—————————————–

#!/bin/bash
echo “==============”
declare -a myarr[0]=”Arun”
declare -a myarr1
myarr1=(arun bagul bangalore mumbai raju santhosh)
myarr[1]=”Bagul”

echo “my name is ${myarr[0]} ${myarr[1]}”
echo “————————–”
echo “${myarr1[*]}”
echo ${myarr1[2]}
echo ${myarr1[@]}
echo “————————–”
echo “Total no of elements in array – ${#myarr1[*]}”
echo “Total no of elements in array – ${#myarr1[@]}”
echo “Size of word ‘${myarr1[2]}’ is – ${#myarr1[2]}”
echo ${#myarr1[1]}
echo ${#myarr1[0]}

echo “————————–”

#how to delete element in array
unset myarr[1]
echo “myarr is – ${myarr[*]}”

#how to assign element in array
myarr[1]=”- System Engineer!”
echo “myarr is – ${myarr[*]}”

echo ${myarr}

————————————————————————
Program (2) ~ command_line_arguments.sh
————————————————————————

#!/bin/bash

echo “Script/command name => $0”
echo “arg1 => $1”
echo “arg2 => $2”
echo “arg3 => $3”
echo “Total No of argument = $#”

echo “Script PID is => $$”
echo “Status of previous command – $?”

name=$myname
echo “Name – $name”

read n

————————————————-
Program (3) ~ default_value.sh
————————————————-

#!/bin/bash

#start=’123′
#start=${1:-$start}

start=${1:-‘123’}

echo “Value of ‘start’ variable is ==> $start”

—————————————————
Program (4) ~ echo_example.sh
—————————————————

#!/bin/bash

name=”Arun”

echo -e “My Name is $name_arun and \n”
echo -e “My Name is ${name}_arun and \n”

echo -e ‘My Name is $name and \n’

—————————————–
Program (5) ~ elif.sh
—————————————–

#! /bin/bash

if [ $1 -eq $2 ];then
echo “good”
elif [ $2 -eq $3 ];then
echo “Fine”
elif [ $1 -eq $3 ];then
echo “OK”
else
echo “NO”
fi

————————————————————
Program (6) ~ for_loop_example-1.sh
————————————————————

#!/bin/bash

i=1
while [ $i -le 512 ]
do
temp=$i
echo “What is => $i | $temp”
i=$(expr $i + 32)
for (( j=$temp; $j<=$i; j++ ))
do
echo -n ” $j”
done
done

———————————————————–
Program (7) ~ for_loop_example-2.sh
———————————————————–

#!/bin/bash
#for val in $(ls -1 /tmp)
sum=0
#for val in {1..5}
#for val in {$1..$2}
for((val=$1;$val<=$2;val++))
do
#echo “$val”
sum=$(expr $sum + $val )
#sum=`expr $sum + $val`
done

echo “$0 # Sum of $1 to $2 => $sum”

————————————————————
Program (8) ~ for_loop_example-3.sh
————————————————————

#!/bin/bash

for i in {1..9}
do
echo $i
done

—————————————–
Program (9) ~ function.sh
—————————————–

#!/bin/bash

function my_function()
{
name=”Arun Bagul”
echo “‘my_function’ body ~ $name”
return 1;
}
##########

myfunc()
{
echo “Another way of defining the function”
}

##########################

echo “Starting function program”
echo “——————————”

#calling function here
my_function
##
myfunc

echo -e “\n end of program”

—————————————————————————————
Program (10) ~ how_to_pass_argument_to_function.sh
—————————————————————————————

#!/bin/bash

function my_function()
{
echo “Total number of argument ~ $#”
echo “Arg1 => $1”
echo “Arg2 => $2”
echo “Arg3 => $3”
return 0;
}
##########

echo “Starting function program”
echo “——————————”

#calling function here
my_function arun bagul 1234

————————————————————————-
Program (11) ~ how_to_take_hidden_input.sh
————————————————————————-

#!/bin/bash

echo -n “Enter User Name :”
read username
echo -n “Enter Password :”
read -s mypwd

echo -e “\nI am $username and my password is – $mypwd”

——————————————————————————
Program (12) ~ how_to_take_input_from_user.sh
—————————————————————————–

#!/bin/bash

echo -ne “Enter the Name:- ”
read name
echo -n -e “Enter the Number:- ”
read num

echo “——————————”

add=$(expr $num + 10)

echo “Name is ~ $name”
echo “Number is ~ $add”

—————————————–
Program (13) ~ ifthen.sh
—————————————–

#!/bin/bash

if [ “arun” == “arun” ];then
echo “true!”
else
echo “false”
fi

echo “———————————-”

if [ 2 == 2 ];then
echo “true!”
else
echo “false”
fi

echo “———————————-”

if [ “arun” = “arun” ];then
echo “true!”
else
echo “false”
fi

echo “———————————-”

if [ 2 -eq 2 ];then
echo “true!”
else
echo “false”
fi

——————————————————
Program (14) ~ non-interactive.sh
——————————————————

#!/usr/bin/expect -f
spawn ssh arun@192.168.0.1
expect “password:”
sleep 1
send “pwd\r”
interact

—————————————————————-
Program (15) ~ read_file_line_by_line.sh
—————————————————————-

#!/bin/bash

file_name=”/etc/hosts”

while read myvar
do
echo “Line => $myvar”
done < $file_name

echo “#################################################”

for myvar1 in $(cat $file_name)
do
echo “Line => $myvar1”
done

——————————————————
Program (16) ~ reverse-number.sh
——————————————————

#!/bin/bash

declare -a date_array
num=$1
i=$(expr $(echo $num | wc -c) – 1 )

while [ $num -gt 10 ]
do
temp=$( expr $num % 10 )
num=$( expr $num / 10);
echo “Digit($i) => $temp”
date_array[$i]=”${temp}”
i=$(expr $i – 1)
done
echo “Digit($i) => $num”
date_array[$i]=”${num}”

echo ${date_array[*]}

——————————————————–
Program (17) ~ string-operation.sh
——————————————————–

#! /bin/bash

echo “Arun Bagul:-”
string=”/root/arun/bagul/image.gif”
echo “string=> $string”
echo “String=> ${string##/*/}”
echo “String=> ${string#/*/}”

echo “String=> ${string%.*}”
echo “String=> ${string%%.*}”
#str=”/home/y/conf/arunbagul/daily_market_0.conf”
str=”${str##/*conf/}”
echo “String=> ${str%/*}”

#done

mystr=”keyword_summary_exact_arunsb”
echo $mystr
echo ${mystr%_*}

echo “$*”

—————————————–
Program (18) ~ switch.sh
—————————————–

#!/bin/bash

echo ” Switch program | arg1 => $1″
echo ” ——————————-”
case $1 in

123)
echo “Case is 123”
;;

arun)
echo “Case is ‘arun'”
;;

pri*)

echo “Case is ‘pri*'”
;;

*)
echo ” * Usage: $0 ”
echo ” Default case (nothing is matched)”
exit 0;
;;
esac

—————————————————————–
Program (19) ~ while_loop_example-1.sh
——————————————————————

#!/bin/bash

mywait=wait

while [ “${mywait}” = “wait” ]
do
echo “arun”
done

——————————————————————-
Program (20) ~ while_loop_example-2.sh
——————————————————————–

#! /bin/bash

## on command line -> i=0 && while [ $i -le 10 ] ; do echo $i; i=$(expr $i + 1); done

i=0
while [ $i -le 10 ]
do
echo $i
i=$(expr $i + 1)
done

——————————————————————–

* Please download PDF file http://www.slideshare.net/arunbagul/bash-learning-by-examples/

Regards,
Arun

(1) Comment    Read More   
Nov
26

Introduction –

nrg2iso is handy tool to convert Nero Image to ISO image

* How to install nrg2iso on Ubuntu Linux –

root@arun:~# apt-get  install   nrg2iso
root@arun:~/oracle-setup# nrg2iso -h
Nrg2Iso v0.4 by G. Kokanosky
released under the GNU GPL v2 or later

Usage :
nrg2iso image.nrg   image.iso

–version    display version number
–help       display this notice

root@arun:~/oracle-setup#

* How to use it ? –

root@arun:~/oracle-setup# ls
ora92linux.nrg
root@arun:~/oracle-setup#

root@arun:~/oracle-setup# nrg2iso ora92linux.nrg  ora92linux.iso
|==============================>[100%]
ora92linux.iso written : 680659100 bytes
root@arun:~/oracle-setup#

root@arun:~/oracle-setup# ls *.iso
ora92linux.iso
root@arun:~/oracle-setup#

* Now ISO image is ready, we can mount ISO image to extract the data as shown below….
root@arun:~/oracle-setup# mount -o loop  ora92linux.iso   /tmp/mount-iso/
root@arun:~/oracle-setup#

root@arun:~/oracle-setup# cd  /tmp/mount-iso/
root@arun:/tmp/mount-iso# ls
doc  index.htm  install  lgto  response  runInstaller  stage
root@arun:/tmp/mount-iso#

root@arun:/tmp/mount-iso# ls
doc  index.htm  install  lgto  response  runInstaller  stage

* Enjoy!! – you can copy the extracted data where ever you want!!

root@arun:/tmp/mount-iso# cp -fr * /root/oracle-setup/oracle-1/
root@arun:/tmp/mount-iso#

root@arun:~/oracle-setup# mount
/root/oracle-setup/ora92linux2.iso  on  /tmp/mount-iso type iso9660 (rw,loop=/dev/loop0)
root@arun:~/oracle-setup#

* Un-mount to ISO image –

root@arun:/tmp/mount-iso# cd  /
root@arun:/# umount /tmp/mount-iso/
root@arun:/#

Thank you,

Arun Bagul

(2) Comments    Read More   
Oct
10
Posted on 10-10-2008
Filed Under (Linux commands, UNIX/Linux) by Arun Bagul

Introduction –

An ISO 9660 is file system for CD-ROM media. Which is published (defined) by the International Organization for Standardization (ISO). ISO image is an archive file (disk image) of an optical disc (like CD) using a conventional ISO 9660 format that is widely supported by many OS and software.

1] How copy  data from ISO image –

I just downloaded opensolaris ISO  image. and wanted copy data from iso image.

step 1) I downloaded the image in /opensolaris  directory

root@arun:/opensolaris# ls -l
total 700768
-rw-r–r– 1 root root 716881920 2008-08-26 06:21 opensolaris-200805.iso
root@arun:/opensolaris#

step 2) mount the ISO image  as  shown below –

root@arun:/opensolaris# mount -o  loop  /opensolaris/opensolaris-200805.iso   /mnt/
root@arun:/opensolaris#

* Check mount point…

root@arun:/mnt# mount  | grep iso
/opensolaris/opensolaris-200805.iso on /mnt type iso9660 (rw,loop=/dev/loop0)
root@arun:/mnt#

step 3) Go to  mounted directory ie /mnt (in my case) –

root@arun:/opensolaris# cd /mnt/
root@arun:/mnt# ls
bin     boot  bootcd_microroot  COPYRIGHT  dev  devices  jack  LICENSE  mnt  platform  proc
reconfigure  root  solarismisc.zlib  solaris.zlib  system  tmp
root@arun:/mnt#

2] How to create ISO image –

a) using dd command  we can create iso image of CD

dd if=/dev/cdrom  of=/tmp/mycdimgage.iso

b) using mkisofs command we can create iso image of our data in any directories

** mkisofs command –

    -R, -rock                               Generate Rock Ridge directory information
    -o FILE, -output FILE             Set output ISO file name
    -l, -full-iso9660-filenames    Allow full 31 character filenames for ISO9660 names
    -max-iso9660-filenames      Allow 37 character filenames for ISO9660 names (violates ISO9660)
    -input-charset CHARSET      Local input character for file name conversion
    -output-charset CHARSET   Output character set for file name conversion

    root@arun:~# mkisofs  -input-charset utf-8  -R -o  /tmp/mycdimage.iso  /mnt/
    1.43% done, estimate finish Sun Oct 10 17:53:05 2008
    2.86% done, estimate finish Sun Oct 10 17:52:30 2008

    ….
    98.56% done, estimate finish Sun Oct 10 17:52:25 2008
    Total translation table size: 0
    Total rockridge attributes bytes: 22651
    Total directory bytes: 159744
    Path table size(bytes): 1024
    Max brk space used 21000
    350039 extents written (683 MB)
    root@arun:~#

    * checking the Size of ISO image of /mnt directory

    root@arun:~# du -sh /tmp/mycdimage.iso
    685M    /tmp/mycdimage.iso
    root@arun:~#

    3] How Burn (copy) ISO image to CD –

    cdrecord is the command line tool to burn or write  iso image file to CD

    ** cdrecord command –

      -v                       Verbose i.e show info while burning the disk
      -dev=0,0,0        Device number
      -multi                 Start multi session disk
      -data                  This option required for HP and Sony CD Writer only.
      -scanbus            scan the SCSI and IDE buses and exit
      -dummy             do everything with laser turned off
      -eject                  Ejects the CD when Done
      -speed=12                  Writing speed (12x )
      -msinfo                        retrieve multi-session info for genisoimage
      timeout=                     set the default SCSI command timeout to
      /tmp/mycdimage.iso   Name of iso image  which to be burned

      * How  to  get Device number ?

      root@arun:~# cdrecord -scanbus
      scsibus3:
      3,0,0   300) ‘MATSHITA’ ‘UJDA775 DVD/CDRW’ ‘1.00’ Removable CD-ROM
      ….
      root@arun:~#

      root@arun:~# cdrecord -dev=3,0,0 -multi -data -v -eject -speed=4 /tmp/mycdimage.iso

      NOTE – above device naming convention doesn’t work in Ubuntu use device  file directly…

      root@arun:~# cdrecord  -dev=/dev/cdrom  -multi -data -v -eject -speed=4 /tmp/mycdimage.iso

      TOC Type: 1 = CD-ROM
      scsidev: ‘/dev/cdrom’
      devname: ‘/dev/cdrom’
      scsibus: -2 target: -2 lun: -2
      Linux sg driver version: 3.5.27
      Wodim version: 1.1.6

      ….
      communication breaks or freezes immediately after that.
      FIFO size      : 12582912 = 12288 KB
      Track 01: data     0 MB         padsize:  242 KB
      Total size:        0 MB (00:04.02) = 302 sectors
      Lout start:        1 MB (00:06/02) = 302 sectors

      root@arun:~#

      ** Hey, just mount the CD and see

      NOTE – Brasero CD burning (http://www.gnome.org/projects/brasero/) – GNOME tool for writing/burning CD is included in Ubuntu 8.04!!

      Thank you,
      Arun Bagul

      (0) Comments    Read More   
      May
      27
      Posted on 27-05-2008
      Filed Under (Linux commands) by Arun Bagul

      Introduction –

      This is the simple way to change password of user on Unix/Linux system non interactively! This script is really helpful for updating password in bulk or adding new users and setting  there password in bulk. Another method is to expect tool please refer article on expect!!

      Let’s see the script now –

      root@arun:~# cat /script/mypasswd.sh
      #! /bin/bash

      if [ $# -eq 2 ]; then
      echo “Script to change password non-interactively”
      echo “——————————————-”
      else
      echo ” * Usage: mypasswd.sh username   password”
      exit 1
      fi
      passwd  $1<<ARUN
      $2
      $2
      <<ARUN
      root@arun:~#

      How to use it ?

      root@arun:~# ./mypasswd.sh
      * Usage: mypasswd.sh username   password
      root@arun:~#

      root@arun:~# ./mypasswd.sh  myuser   mypwd
      Script to change password non-interactively
      ——————————————-
      Enter new UNIX password: Retype new UNIX password: passwd: password updated successfully
      root@arun:~#
      Thank you,
      Arun Bagul

      (0) Comments    Read More   
      Mar
      17
      Posted on 17-03-2008
      Filed Under (Linux commands) by Ravi Bhure

      The write command enables you to write an actual message on the other terminal online. You have to issue the write command with the login ID of the user with whom you want to communicate. The write command informs the user at the other end that there is a message from another user. write pastes that message onto the other user’s terminal if their terminal’s write permissions are set. Even if they are in the middle of an edit session, write overwrites whatever is on the screen. The edit session contents are not corrupted; you can restore the original screen on most editors with Ctrl-L.

      write is mostly used for one-way communication, but you can have an actual conversation as well.

      example: write user [ttyname]

      With Regards,

      Ravi Bhure

      (1) Comment    Read More   
      Feb
      26

      Introduction- Since long time, I was thinking to write post on expect!!. and finally I start writing this post.. I am using expect tool for automation, scheduling and running commands on remote machine by using ssh in non-interactive mode. It’s very useful and handy tool for System admin specially Unix and Linux admin.

      What is Expect ?

      Expect is a Unix automation and testing tool, written by Don Libes. Expect has regular expression pattern matching and general program capabilities, allowing simple scripts to intelligently control programs such as telnet, ftp, and ssh, all of which lack a programming language, macros, or any other program mechanism. The result is that Expect scripts provide old tools with significantly new power, and flexibility.

      Example (1) non interactive SSH login –

      root@arunbagul:/home/arun# cat non-interactive.sh
      #!/usr/bin/expect -f
      spawn ssh arun@192.168.0.1
      expect “password:”
      sleep 1
      send “mypassword\r”
      interact

      root@arunbagul:/home/arun#

      root@arunbagul:/home/arun# ./non-interactive.sh
      spawn ssh arun@192.168.0.1
      arun@192.168.0.1’s password:
      Linux arunbagul.com 2.6.22-14-generic #1 SMP Tue Feb 12 07:42:25 UTC 2008 i686

      The programs included with the Ubuntu system are free software;
      You have new mail.
      Last login: Sat Mar 1 15:15:05 2008 from arunbagul.com
      arun@arunbagul:~$ id=1200(arun) gid=1200(arun)

      arun@arunbagul:~$

      Example (2) non interactive SCP copy –

      root@arunbagul:/home/arun# cat scp.sh
      #!/usr/bin/expect -f

      # set Variables
      set source [lrange $argv 0 0]
      set dest [lrange $argv 1 1]
      set timeout -1

      # connect via scp…
      spawn scp $source $dest

      #wait for the password to ask…
      expect “password:”
      sleep 1

      #provide password after askinng

      send “mypassword\r”

      interact
      #done
      root@arunbagul:/home/arun#

      * Now copy data to 192.168.0.1 system –

      root@arunbagul:/home/arun# ./scp.sh /tmp/myfile.txt arun@192.168.0.1:/tmp/arun/
      spawn scp /tmp/myfile.txt arun@192.168.0.1:/tmp/arun/
      arun@192.168.0.1’s password:
      myfile.txt 100% 8 0.0KB/s 00:00
      root@arunbagul:/home/arun#

      * Now copy data from 192.168.0.1 system to your system –

      root@arunbagul:/home/arun#./scp.sh arun@192.168.0.1:/tmp/arun/myfile.txt /tmp/
      spawn scp arun@192.168.0.1:/tmp/arun/myfile.txt /tmp/
      arun@192.168.0.1’s password:
      myfile.txt 100% 8 0.0KB/s 00:00
      root@arunbagul:/home/arun#
      Now you know, how this tool is powerful !!.. You can use this tool for automation purpose and where you don’t want to interact with system now and then use it…

      Note:- In above two example script is non interactive means it will not ask you to inter password …. expect will do it for you…!!

      Thank you,
      Arun

      (5) Comments    Read More   
      Jan
      20
      Posted on 20-01-2008
      Filed Under (Linux commands) by Arun Bagul

      SSH provides wounder facility to run linux command on remote machine, provided that you have SSH access to that machine…

      • We can use this feature of SSH for troubleshooting purpose… for example suppose there is “logout” command in your “.bashrc” file of remote user. In this case you will not get ssh access until you remove this “logout” command from “.bashrc” file of remote user. This can be done remotely by using SSH..

      1] I am login on machine ‘IndianGNU.org’ and trying to login to ‘192.168.0.1’ ie ‘Remote’ machine.. but it immediately logout. see below….

      root@IndianGNU.org:/home/arun.bagul# ssh arun.bagul@192.168.0.1
      arun.bagul@192.168.0.1’s password:
      Last login: Sun Jan 20 18:49:29 2008 from 192.168.0.5
      Connection to 192.168.0.1 closed.
      root@IndianGNU.org:/home/arun.bagul#

      2] This is happening because there is ‘logout’ command added in ‘.bashrc’ file of arun.bagul‘s profile on ‘192.168.0.1’

      3] How to check this ‘.bashrc’ file on ‘192.168.0.1’ –

      root@IndianGNU.org:/home/arun.bagul# ssh arun.bagul@192.168.0.1 ‘tail /home/arun.bagul/.bashrc’
      arun.bagul@192.168.0.1’s password:
      if [ -f /etc/bash_completion ]; then
      . /etc/bash_completion
      fi

      ######

      ## ‘logout’ command which will terminate your session just after login.
      #You will not get any access via SSH
      logout

      root@IndianGNU.org:/home/arun.bagul#

      4] How to remove this ‘logout’ command from remote file by ssh

      root@IndianGNU.org:/home/arun.bagul# ssh arun.bagul@192.168.0.1 ‘sed -i “s/logout/#welcome/g” /home/arun.bagul/.bashrc’
      arun.bagul@192.168.0.1’s password:
      root@IndianGNU.org:/home/arun.bagul#

      5] Check now –

      root@IndianGNU.org:/# ssh arun.bagul@192.168.0.1 ‘tail /home/arun.bagul/.bashrc’
      arun.bagul@192.168.0.1’s password:
      if [ -f /etc/bash_completion ]; then
      . /etc/bash_completion
      fi

      ######

      ## ‘#welcome’ command which will terminate your session just after #login.
      #You will not get any access via SSH
      #welcome

      root@IndianGNU.org:/home/arun.bagul#

      6] Now try to login on 192.168.0.1′ with user name ‘arun.bagul’ –

      root@IndianGNU.org:/home/arun.bagul# ssh arun.bagul@192.168.0.1
      arun.bagul@192.168.0.1’s password:
      Last login: Sun Jan 20 18:39:15 2008 from 192.168.0.5
      arun.bagul@Remote:~$

      7] Other uses of ssh for running remote command –

      root@IndianGNU.org:/home/arun.bagul# ssh arun.bagul@192.168.0.1 ‘df -h’
      arun.bagul@192.168.0.1’s password:
      Filesystem Size Used Avail Use% Mounted on
      /dev/hda2 79G 26G 50G 34% /
      varrun 1009M 108K 1009M 1% /var/run
      varlock 1009M 8.0K 1009M 1% /var/lock
      udev 1009M 104K 1009M 1% /dev
      devshm 1009M 0 1009M 0% /dev/shm
      /dev/hda5 56G 42G 11G 81% /backup
      /dev/hda1 361M 27M 315M 8% /boot
      /dev/hda6 9.2G 8.6G 180M 98% /var
      root@IndianGNU.org:/home/arun.bagul#
      ** List mounted partion –

      root@IndianGNU.org:/home/arun.bagul# ssh root@192.168.0.8 ‘mount’
      root@192.168.0.8’s password:
      /dev/hda3 on / type ext3 (rw)
      proc on /proc type proc (rw)
      sysfs on /sys type sysfs (rw)
      devpts on /dev/pts type devpts (rw,gid=5,mode=620)
      /dev/hda2 on /boot type ext3 (rw)
      tmpfs on /dev/shm type tmpfs (rw)
      /dev/hda7 on /usr type ext3 (rw)
      /dev/hda6 on /var type ext3 (rw)
      none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
      /usr/tmpDSK on /tmp type ext3 (rw,noexec,nosuid,loop=/dev/loop0)
      /tmp on /var/tmp type none (rw,noexec,nosuid,bind)
      sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)

      root@IndianGNU.org:/home/arun.bagul#
      Regards,

      Arun Bagul

      (0) Comments    Read More   
      Jan
      17
      Posted on 17-01-2008
      Filed Under (Linux commands) by Ravi Bhure

      One of the best methods to capture a Unix terminal session is to use the `script` command.

      In this example we start a script session, run a couple of commands, and then use the `exit` command to stop capturing the terminal session:

      $ script
      Script started, output file is typescript
      $ pwd
      /home/will
      $ ps
        PID  TT  STAT      TIME COMMAND
      11909  p0  Ss     0:00.05 -bash (bash)
      25622  p0  S+     0:00.01 script
      25623  p1  Ss     0:00.01 /usr/local/bin/bash -i
      25624  p1  R+     0:00.00 ps
      $ exit
       
      Script done, output file is typescript

      We have now captured our terminal session into the file “typescript”.

      We can use the `cat` command to view the contents of the “typescript” file:

      $ cat typescript
      Script started on Tue Jul 26 21:28:50 2005
      $ pwd
      /home/will
      $ ps
        PID  TT  STAT      TIME COMMAND
      11909  p0  Ss     0:00.05 -bash (bash)
      25622  p0  S+     0:00.01 script
      25623  p1  Ss     0:00.01 /usr/local/bin/bash -i
      25624  p1  R+     0:00.00 ps
      $ exit
       
      Script done on Tue Jul 26 21:29:13 2005
       

      If you’re new to UNIX, this concise book will tell you just what you need to get started and no more. This fifth edition is the most effective introduction to UNIX in print, covering Internet usage for email, file transfers, and web browsing. It’s an ideal primer for Mac and PC users who need to know a little about UNIX on the systems they visit. The new edition also contains many major and minor updates to help the reader navigate UNIX’s ever-expanding capabilities. In response to the popularity of Linux, the book now focuses on the popular bash shell preferred by most Linux users. A new chapter explains how to use ftp, pine for mail, and offers useful knowledge on how to surf the web. And the author has included tips throughout the text on security basics, especially in the Internet and networking sections. The book includes a completely updated quick reference card to make it easier for the reader to access the key functions of the command line.

      Thanks & Regards

      Ravi Bhure

      (0) Comments    Read More   
      Jan
      03
      Posted on 03-01-2008
      Filed Under (Linux commands) by Arun Bagul

      In my  case I am  using apache server  for reloading configuration file etc.

      *Check  apache is runnig on 80 port or  not ?

      root@indiangnu.org:/home/arun# netstat -nlp |  grep  80
      tcp6       0      0 :::80                   :::*                    LISTEN     5562/apache2

      root@indiangnu.org:/home/arun# vi /etc/apache2/
      apache2.conf     envvars          magic            mods-enabled/    README           sites-enabled/
      conf.d/          httpd.conf       mods-available/  ports.conf       sites-available/ ssl/

      2]  Modify  configuration files..

      root@indiangnu.org:/home/arun# cat  /etc/apache2/ports.conf
      Listen 80

      root@indiangnu.org:/home/arun#  vi  /etc/apache2/ports.conf

      root@indiangnu.org:/home/arun#  cat  /etc/apache2/ports.conf
      Listen 80
      Listen 8080

      root@indiangnu.org:/home/arun#

      root@indiangnu.org:/home/arun# netstat -nlp |  grep  80
      root@indiangnu.org:/home/arun# netstat -nlp |  grep  80
      tcp6       0      0 :::80                   :::*                    LISTEN     5562/apache2

      3]  Reload service ie configuration files etc.

      root@indiangnu.org:/home/arun# kill -HUP 5562

      4]  Check apache is using 80 and 8080 port or not ?

      root@indiangnu.org:/home/arun# netstat -nlp |  grep  80
      tcp6       0      0 :::8080                 :::*                    LISTEN     5562/apache2
      tcp6       0      0 :::80                   :::*                    LISTEN     5562/apache2
      root@indiangnu.org:/home/arun#

      (0) Comments    Read More   

      www.flickr.com
      arunbagul's photos More of arunbagul's photos
      Get Adobe Flash player
      -->