Showing posts with label linux. Show all posts
Showing posts with label linux. Show all posts

Saturday, August 8, 2015

History of linux


Mid 1960 - multics (a time sharing operating system) was getting developed by AT&T Bell but it was too large/complex.... finally AT&T pulled out from project.

In 1969-70,  Ken Thompson and Dennis Ritchie (both of AT&T Bell Laboratories) wrote Unix Operating system (on a much less scaled version).

Later they rewrote it in C, make it portable.

Unix philosophy was to use a large number of software tools, small programs that can be strung together through a command-line interpreter using pipes, as opposed to using a single monolithic program that includes all of the same functionality.

Both Unix and the C programming language were developed by AT&T and distributed to government and academic institutions, which led to both being ported to a wider variety of machine families than any other operating system.

Under Unix, the operating system consists of many utilities along with the master control program, the kernel. The kernel provides services to start and stop programs, handles the file system and other common "low-level" tasks that most programs share, and schedules access to avoid conflicts when programs try to access the same resource or device simultaneously. To mediate such access, the kernel has special rights, reflected in the division between user space and kernel space.

During the late 1970s and early 1980s, the influence of Unix in academic circles led to large-scale adoption of Unix (BSD and System V) by commercial startups, including Sequent, HP-UX, Solaris, AIX, and Xenix. In the late 1980s, AT&T Unix System Laboratories and Sun Microsystems developed System V Release 4 (SVR4), which was subsequently adopted by many commercial Unix vendors.

1983, none of the computer operating systerm was free.

1984, Richard M. Stallman (founder of Free Software Foundation) started developing the GNU operating system (a unix-like operating system)

The GNU Project has developed a comprehensive set of free software tools (cp, rm, vi, gcc) for use with BSD Operating system

By 1991, the GNU mid-level portions of the operating system were almost complete, and the upper level could be supplied by the X Window System, but the lower level (kernel, device drivers, system-level utilities and daemons) was still mostly lacking

GNU developed it's free operating system called 'GNU Hurd' which was an ambitious design, unexpectedly difficult to implement and has only been marginally usable.

At another hand, Tanenbaum started MINIX for educational purpose, and was first released in 1987, with its complete source code made available to universities for study in courses and research, however still licencsed.

1991, Linus Torvalds, who was working for MINIX, almost copy the concept from MINIX (which was more a micro kernel) and made a monolithic kernal called Linux and use GNU free utilities to proivde a 'free operating system'.

As 'hurd' was still not triggering, GNU also adopted Linux as kernal around 1992. Basically Linux was the 'kernal part' and the operating system was 'GNU/Linux' Operating system.







Tuesday, March 31, 2015

CISCO tips and tricks


/*************************************************
CISCO : copy to linux server TCL script
***************************************************/

[bgl-ads-146]@~$cat /nobackup/tapmahes/script/cpl.tcl
#!/bin/env expect

set timeout 60
spawn scp i86bi_linux-adventerprisek9-ms root@10.78.106.52:/root/tapesh/IOU/
expect "password:"
send "cryptolab\r"
expect "100%"
sleep 1

[bgl-ads-146]@~$



/***********************************
CISOC .bashrc alias list
************************************/

[bgl-ads-146]@~$cat ~/.bashrc | grep alias
alias cpl=/nobackup/tapmahes/script/cpl.tcl
alias emacs='/router/bin/emacs-22.3 &'
alias sun='ssh blr-stgios-view1'
alias junk='cd /nobackup/tapmahes/junk'
alias people='cd /nfs/wwwPeople/tapmahes'
alias ssh88='ssh mcp-bld-lnx-88'
alias ssh85='ssh mcp-bld-lnx-85'
alias ssh86='ssh mcp-bld-lnx-86'
alias ssh1='ssh blr-stgios-view1'
alias sshl='ssh root@10.78.106.52'
alias ssht='ssh -t tapmahes-vlnx ". .bashrc; bash -l"'
alias cs='cd /vob/cisco.comp/crypto && cscope-64 -R'
alias cs1='find . -name "*.[ch]" > cscope.files && cscope -d'
alias ver='cat /vob/ios/.publication_manifest | grep crypto'
alias crashinfo='mcp_gdb -p linkfarm/x86_64/usr/binos/bin/x86_64bi_linux_iosd-adventerprisek9-ms.sun'
alias corefile='mcp_gdb_core -p linkfarm/x86_64/usr/binos/bin/x86_64bi_linux_iosd-adventerprisek9-ms.sun -c '
alias tc='tcsh' #if ($?prompt) source ~/.cshrc.keychain
alias gdb64='/router/bin/gdb-bleeding-64'
alias uco='cc_unco -force_unco'
alias cco='cc_co -nc -f'
alias unix_image='unix-jo3s-ms'
alias mosy='/router/bin/mosy-14.2.0.0 -s'
alias buidmib='make dir/*.code '
alias osup='cd /vob/ios.sys6/sys/obj-7k-sup3-rp-earl7'
alias rpk9='make s72033_rp-adventerprisek9-m.ucode'
alias prep='prep-commit tapmahes@cisco.com'
alias ptall='make -k PRECOMMIT_CRYPTO=1 precommit.testall > & make.out &'
alias snaps='cd /auto/ios-snaps'
alias ht='cd  /auto/ios-snaps/haw_t.snap/ios/sys'
#alias ps='/usr/bin/ps'
alias sa='/auto/ses/bin/static_iosbranch'
alias myp='ps -ef | grep tapmahes'
alias mymake='ps -ef | grep tapmahes | grep make'
#alias gcc='/auto/router/bin/gcc.c2.95.3-p11a.solaris'
alias unix='cd /vob/ios/sys/obj-sp-unix'
alias linux='cd /vob/ios/sys/obj-x86_64bi-linux'
alias crypto='cd /vob/cisco.comp/crypto'
alias ikev2='cd /vob/cisco.comp/crypto/ikev2/src/ikev2'
alias objs='cd /vob/cisco.comp/crypto/objects/ios.sparc.v7/'
alias 2800='cd /vob/ios/sys/obj-7k-c2800'
alias update='cc_update -m LATEST'
alias gvim='gvim -bg lightblue -fg black'
alias gw='gvim -bg white -fg black'
alias gp='gvim -bg peachpuff -fg black'
alias gb='gvim -bg brown -fg white'
alias er='stty erase ^H'
alias eq='stty erase ^?'
alias ct='cleartool'
alias pwv='ct pwv'
alias rcscope='/router/bin/cscope'
alias myviews='ls /ws/tapmahes-bgl'
#alias flex "/auto/ses/bin/tools/iosclassic_fl"
alias sys='cd /vob/ios/sys'
#alias cscope='/sw/packages/cscope/12.9/solaris2bin/cscope.kani'
alias cscope='cscope-15.5-p7'
alias tb3='cd /auto/ios-snaps/t_base_3.snap/ios && cscope -d && cd -'
alias tb4='cd /auto/ios-snaps/t_base_4.snap/ios && cscope-64 -d && cd -'
alias googlem='cd /auto/ios-snaps/mcp_dev.snap/ios && cscope-64 -d && cd -'
alias xe37='cd /auto/ios-snaps/v152_4_s_xe37_throttle.snap/ios && cscope -d && cd -'
alias xe38='cd /auto/ios-snaps/v153_1_s_xe38_throttle.snap/ios && cscope -d && cd -'
alias xe39='cd /auto/ios-snaps/v153_2_s_xe39_throttle.snap/ios && cscope -d && cd -'
alias xe314='cd /auto/ios-snaps/v155_1_s_xe314_throttle.snap/ios && cscope-64 -d && cd -'
alias xe313='cd /auto/ios-snaps/v154_3_s_xe313_throttle.snap/ios && cscope-64 -d && cd -'
#alias tftp='cd /auto/tftp-blr-users1/tapmahes'
alias rss='cd /auto/ios-snaps/t_pi12_rss.snap/ios'
#alias s1='ssh blr-stgios-view1'
#alias s2='ssh blr-stgios-view2'
#alias mdi='make -j16 dependencies && cd obj-sp-unix && make -j16 unix-adventerprisek9-ms 2>&1 | tee c.txt'
#alias mdl='make -j16 dependencies && cd obj-x86_64bi-linux && make -j16 TOOLS_VER=c3.4.5-p1 x86_64bi_linux-jk9o3s-ms 2>&1 | tee c.txt'
alias mdl='cd /vob/ios/sys && make -j32 dependencies && cd /vob/ios/sys/obj-i86bi-linux && export GDB_FLAG=-g && make -j32 GDB_FLAG=-g i86bi_linux-adventerprisek9-ms 2>&1 | tee c.txt'
alias mdu='cd /vob/ios/sys && make -j32 dependencies && cd /vob/ios/sys/obj-sp-unix && export GDB_FLAG=-g && make -j32 GDB_FLAG=-g unix-adventerprisek9-ms 2>&1 | tee c.txt'
alias md='cd /vob/ios/sys && make -j32 dependencies'
alias ml='cd /vob/ios/sys/obj-i86bi-linux && export GDB_FLAG=-g && make -j32 GDB_FLAG=-g i86bi_linux-adventerprisek9-ms'
alias ml64='cd /vob/ios/sys/obj-x86_64bi-linux && export GDB_FLAG=-g && make -j32 GDB_FLAG=-g x86_64bi_linux-jk9o3s-ms 2>&1 | tee c.txt'
alias mi='make -j8 unix-adventerprisek9-ms 2>&1 | tee c.txt'
alias mil='make -j8 LEGOFILTER=shr_crypto_ipsec_common.o unix-adventerprisek9-ms 2>&1 | tee c.txt'
alias miln='make -j8 LEGOFILTER=shr_crypto_ikev2.o unix-adventerprisek9-ms 2>&1 | tee c.txt'
alias c7200p='cd /vob/ios/sys && make -j16 dependencies && cd obj-g4-c7100 && make -j16 c7200p-adventerprisek9-mz 2>&1 | tee c.txt'
alias c3900='cd /vob/ios/sys && cd obj-m8500-c3900 && make -j16 c3900-universalk9-mz 2>&1 | tee c.txt'
alias c3900e='cd /vob/ios/sys && cd obj-i86bi-ifr && make -j16 c3900e-universalk9-mz 2>&1 | tee c.txt'
alias c880data='cd /vob/ios/sys && cd obj-m8300-c880 && make -j16 c880data-universalk9-mz 2>&1 | tee c.txt'
alias c2951='cd /vob/ios/sys && cd obj-m8500-c2951 && make -j16 c2951-universalk9-mz 2>&1 | tee c.txt'
alias c2900='cd /vob/ios/sys && cd obj-cn-c2900 && make -j16 c2900-universalk9-mz 2>&1 | tee c.txt'
alias c1900='cd /vob/ios/sys && cd obj-cn-c1900 && make -j16 c1900-universalk9-mz 2>&1 | tee c.txt'
alias c3750e='cd /vob/ios/sys/obj-ppc-c3750e && make -j32 c3750e-universalk9-mz 2>&1 | tee c.txt'
alias c3845='cd /vob/ios/sys && make -j8 dependencies && cd obj-sb-c3845 && make -j8 c3845-adventerprisek9-mz 2>&1 | tee c.txt'
alias c1841='cd /vob/ios/sys && make -j8 dependencies && cd obj-5k-c1840 && make -j8 c1841-adventerprisek9-mz  2>&1 | tee c.txt'
alias c2800nm='cd /vob/ios/sys && make -j8 dependencies && cd obj-7k-c2800 && make -j8 c2800nm-adventerprisek9-mz 2>&1 | tee c.txt'
alias c7200pl='cd /vob/ios/sys/obj-g4-c7100 && make -j8 LEGOFILTER=shr_crypto_ipsec_common.o c7200p-adventerprisek9-mz 2>&1 | tee c.txt'
alias c3845l='cd /vob/ios/sys/obj-sb-c3845 && make -j8 LEGOFILTER=shr_crypto_ipsec_common.o c3845-adventerprisek9-mz 2>&1 | tee c.txt'
alias c1841l='cd /vob/ios/sys/obj-5k-c1840 && make -j8 LEGOFILTER=shr_crypto_ipsec_common.o c1841-adventerprisek9-mz  2>&1 | tee c.txt'
alias c2800nml='cd /vob/ios/sys/obj-7k-c2800 && make -j8 LEGOFILTER=shr_crypto_ipsec_common.o c2800nm-adventerprisek9-mz 2>&1 | tee c.txt'
alias ll='ls -al'
alias     ctl='ct lsview | grep tapmahes'
alias     ctlo='ct lsview | grep $1'
alias     ctv='ct setview'
alias rs='/usr/bin/runsparc.real'
alias tc='tcsh'
alias vi='vim'
#alias ls='ls --color=always'



/***************************************
CISCO short cut command file
****************************************/

Command to bind F12 to a bash file:
bind '"\e[24~":"source ~/.keyshort\n"'

[bgl-ads-146]@~$ cat .keyshort
assert()
{
if [ "$ans" == "" ]
then
exit
fi
}

ShowVariousDirectories()
{
echo "1) /vob/ios/sys"
echo "2) /vob/ios/sys/obj-x86_64bi-linux"
echo "3) /vob/ios/sys/obj-i86bi-linux"
echo "4) /vob/ios/sys/obj-sp-unix"
read -s -n 1 ans
echo --------------
case $ans in
1) cd /vob/ios/sys;;
2) cd /vob/ios/sys/obj-x86_64bi-linux ;;
3) cd /vob/ios/sys/obj-i86bi-linux ;;
4) cd /vob/ios/sys/obj-sp-unix ;;
esac
}

SetView()
{
select ans in `ls /view`;
do
assert
echo -ne "\033]0;${ans:9}\007"
cleartool setview $ans
echo -ne "\033]0;Terminal\007"
break
done
}

CreateView()
{
        echo "Please enter the branch: (if you want to pull view from label, press enter)"
        read branch
        if [ "$branch" == "" ]
        then
                echo "Please enter the label:"
                read label
                echo "Please enter a tag (anything which you can remember):"
                read tag
                start_task -l $label -v /vob/ios -t $tag -d /ws/tapmahes-bgl
        else
                echo "Please enter a tag (anything which you can remember):"
                read tag
                start_task -b $branch -v /vob/ios -t $tag -d /ws/tapmahes-bgl
        fi
}

BINOS()
{
        echo "Please select build type:"
        echo "1) 1RU            2) RP2                  3) RP3"
        read -n 1 type
        case $type in
        1) type=1ru;;
        2) type=rp2;;
        3) type=rp3;;
        esac
        echo "Please enter the label:"
        read label
        echo "Please enter BINOS dir name (anything which you can remember):"
        read binosdir
        mkdir /nobackup/tapmahes/$binosdir
        cd /nobackup/tapmahes/$binosdir
#       acme nw -sb binos -proj main%$label
        echo On Success, set the matching view in IOS and please run the following command from /vob/ios/sys: mcp_ios_precommit -r /nobackup/tapmahes/$binosdir/ "GDB_FLAG=-g" "$type""_super"
}

ShowDiff()
{
        tempifs=$IFS
        IFS=$'\n'
        array=(`ct lsco -avobs -cview | awk '{print $5"@@"$7, $5}' | sed s/\"//g`)
        IFS=$tempifs
        i=0
        while [ $i -lt ${#array[*]} ];
        do
        echo "$i: ${array[$i]}" | cut -d " " -f 1,3
        let i++
        done
        while [ true ];
        do
        echo "Choose file num (Press Enter to Exit):"
        read ans
        if [ "$ans" == "" ]
        then
        break
        fi
        vimdiff  ${array[$ans]}
        done
}

ShowLablesList()
{
        echo "Branch : (default : t_base_2)"
        read branch
        if [ "$branch" == "" ]
        then
                branch=t_base_2
        fi
        echo "Search String (Just Enter for None) : "
        read searchstr
        if [ "$searchstr" == "" ]
        then
                cc_branch_labels -b $branch -v /vob/ios | more
        else
                cc_branch_labels -b $branch -v /vob/ios | grep $searchstr | more
        fi
}

ShowCleartoolOptions()
{
echo "1) Show View"
echo "2) Set View"
echo "3) Create View"
echo "4) Create BINOS Tree"
echo "5) Show Diff"
echo "6) Show Lables list"
echo "7) Show current Lable"
read -s -n 1 ans
echo --------------
case $ans in
1) cleartool lsview | grep tapmahes
echo --------------
cleartool pwv;;
2) SetView;;
3) CreateView;;
4) BINOS;;
5) ShowDiff;;
6) ShowLablesList;;
7) ct edcs;;
esac
}

LaunchRouter()
{
echo "1) IOU"
echo "2) IOU with GDB"
echo "3) IOL"
echo "4) IOL with GDB"
echo "5) IOL 32 bit"
echo "6) IOL 32 bit with GDB"
read -s -n 1 ans
echo --------------
case $ans in
1)      echo "NVRAM Number:"
        read nvramid
        cd /vob/ios/sys/obj-sp-unix
        runsparc ./unix-adventerprisek9-ms -m1000 -n1000 $nvramid ;;
2)  cd /vob/ios/sys/obj-sp-unix
        runsparc /router/bin/gdb unix-adventerprisek9-ms.sun ;;
3)      echo "NVRAM Number:"
        read nvramid
        cd /vob/ios/sys/obj-x86_64bi-linux
        ./x86_64bi_linux-jk9o3s-ms -m1000 -n1000 $nvramid ;;
4)  cd /vob/ios/sys/obj-x86_64bi-linux
    gdb-bleeding-64 x86_64bi_linux-jk9o3s-ms.sun;;
5)      echo "NVRAM Number:"
        read nvramid
        cd /vob/ios/sys/obj-i86bi-linux
        ./i86bi_linux-adventerprisek9-ms -m1000 -n1000 $nvramid ;;
6)  cd /vob/ios/sys/obj-i86bi-linux
    gdb-bleeding i86bi_linux-adventerprisek9-ms.sun;;
esac
}

Compile_IOU_Minimal()
{
echo "1) Build common"
echo "2) Build IKEv2"
read -s -n 1 ans
echo --------------
cd /vob/ios/sys/obj-sp-unix
export GDB_FLAG=-g
case $ans in
1)  make -j32 GDB_FLAG=-g LEGOFILTER=shr_crypto_ipsec_common.o  unix-adventerprisek9-ms 2>&1 | tee c.txt;;
2) make -j32 GDB_FLAG=-g LEGOFILTER=shr_crypto_ikev2.o  unix-adventerprisek9-ms 2>&1 | tee c.txt;;
esac
}

Compile_IOL_X64_Minimul()
{
echo "1) Build common"
echo "2) Build IKEv2"
read -s -n 1 ans
echo --------------
cd /vob/ios/sys/obj-x86_64bi-linux
export GDB_FLAG=-g
case $ans in
1)  make -j64 GDB_FLAG=-g LEGOFILTER=shr_crypto_ipsec_common.o  x86_64bi_linux-jk9o3s-ms 2>&1 | tee c.txt;;
2)  make -j64 GDB_FLAG=-g LEGOFILTER=shr_crypto_ikev2.o  x86_64bi_linux-jk9o3s-ms 2>&1 | tee c.txt;;
esac
}

Compile_IOL_x32_Minimal()
{
echo "1) Build common"
echo "2) Build IKEv2"
read -s -n 1 ans
echo --------------
cd /vob/ios/sys/obj-i86bi-linux
export GDB_FLAG=-g
case $ans in
1)  make -j64 GDB_FLAG=-g LEGOFILTER=shr_crypto_ipsec_common.o  i86bi_linux-adventerprisek9-ms 2>&1 | tee c.txt;;
2)  make -j64 GDB_FLAG=-g LEGOFILTER=shr_crypto_ikev2.o  i86bi_linux-adventerprisek9-ms 2>&1 | tee c.txt;;
esac
}

CompileCode()
{
echo "1) Make Dependencies"
echo "2) IOU Minimal"
echo "3) IOU Full"
echo "4) IOU Fast"
echo "5) Router Build (Make sure to be in Correct OBJ dir)"
echo "6) IOL x64 Full"
echo "7) IOL x64 Minimal"
echo "8) IOL x32 Full"
echo "9) IOL x32 Minimal"
read -s -n 1 ans
echo --------------
case $ans in
1)      cd /vob/ios/sys
        make -j32 dependencies;;
2)      Compile_IOU_Minimal;;
3)  cd /vob/ios/sys/obj-sp-unix
        export GDB_FLAG=-g
        make -j32 GDB_FLAG=-g unix-adventerprisek9-ms 2>&1 | tee c.txt;;
4)  cd /vob/ios/sys/obj-sp-unix
        export GDB_FLAG=-g
        emake-aurora --env=ios unix-adventerprisek9-ms;;
5)      export GDB_FLAG=-g
        echo "Write the target name (Make sure you are in correct OBJ Dir) :"
        read target_router
        make -j32 GDB_FLAG=-g $target_router;;
6)      cd /vob/ios/sys/obj-x86_64bi-linux
        export GDB_FLAG=-g
        make -j32 GDB_FLAG=-g x86_64bi_linux-jk9o3s-ms 2>&1 | tee c.txt;;
7)  Compile_IOL_X64_Minimul;;
8)      cd /vob/ios/sys/obj-i86bi-linux
        export GDB_FLAG=-g
        make -j32 GDB_FLAG=-g i86bi_linux-adventerprisek9-ms 2>&1 | tee c.txt;;
9) Compile_IOL_x32_Minimal;;
esac
}

ShowMainMenu()
{
echo "1) Cleartools command"
echo "2) Moving into Directories"
echo "3) Launch Routers"
echo "4) Compile code"
read -s -n 1 ans
echo --------------
case $ans in
1) ShowCleartoolOptions;;
2) ShowVariousDirectories;;
3) LaunchRouter;;
4) CompileCode;;
esac
}


ShowMainMenu;


#select ans in "Cleartool commands" "Moving into Directories";
#do
#assert
#echo $ans
#case $ans in
#"Cleartool commands") ShowCleartoolOptions;;
#"Moving into Directories") echo second menu;;
#esac
#done



Tuesday, February 4, 2014

How to redirect traffic from one IP to another IP


/sbin/iptables -t nat -A PREROUTING -p icmp -d 10.106.210.176 -j DNAT --to-destination 10.20.1.2


To view whatever is configured:

/sbin/iptables -t nat -vnL --line-number  (with nat)
/sbin/iptables -vnL --line-number           (without nat)



To Delete/remove :
/sbin/iptables -D FORWARD 1   (without nat and 'FORWARD' is the policy, replace accordingly from whatever is listed from above command output)

another example to delete with nat:
/sbin/iptables -t nat -D PREROUTING 1   (here 1, 2 ..3 are the line-numbers which will get listed from view command)

Wednesday, December 28, 2011

Using ICOV as Code coverage tool (Simple steps)

I was searching for some free code coverage tool which is simple for first setup and quick enough to show me the results without doing much. I found ICOV very quick and useful for this.
Here are the steps if you want to set it up or want to give it a try :)

I was using Ubuntu 10.10 (32bit version) and installed ICOV using command
sudo apt-get install icov

once done, i moved in temp work directory where my 'C' file was there : test.c
i compiled it using

 gcc -g -fprofile-arcs  -ftest-coverage test.c

and then run the executable.
./a.out

then i use this command to generate code coverage information...

lcov --directory . --capture --output-file app.info

as i need this information in nice HTML output, i use this command

genhtml --output-directory ./output app.info


it creates a OUTPUT folder which contains 'index.html' which have detailed information of code coverage (for the instance you run few step before, below is the sample output).



Happy  Code Coverage