Sunday, March 4, 2007

Automate your FTP login-ubuntu

#!/usr/bin/env expect
set username yourUsername
set pass yourPasswd
set host theHostspawn
ftp ${username}@${host}
expect "Password:"
send "${pass}\r"
expect "ftp> "
interact

The Towers of Hanoi-In linux

#! /bin/bash
#
# The Towers Of Hanoi
# Bash script
# Copyright (C) 2000 Amit Singh. All Rights Reserved.
# http://hanoi.kernelthread.com
#
# # The Tower of Hanoi is a mathematical puzzle attributed to
#+ Edouard Lucas, a nineteenth-century French mathematician.
#
# There are three vertical posts set in a base.
# The first post has a set of annular rings stacked on it.
# These rings are flat disks with a hole drilled out of the center,
#+ so they can slip over the posts.
# The rings have different diameters, and they stack in descending
#+ order, according to size.
# The smallest ring is on top, and the largest on the bottom.
#
# The task is to transfer the stack of rings
#+ to one of the other posts.
# You can move only one ring at a time to another post.
# You are permitted to move rings back to the original post.
# You may place a smaller ring atop a larger one,
#+ but *not* vice versa.
# Again, it is forbidden to place a larger ring atop a smaller one.
#
# For a small number of rings, only a few moves are required.
#+ For each additional ring,
#+ the required number of moves approximately doubles,
#+ and the "strategy" becomes increasingly complicated.
#
# For more information, see http://hanoi.kernelthread.com.
#
#1 #2 #3
#
#========================================#
E_NOPARAM=66 # No parameter passed to script.
E_BADPARAM=67 # Illegal number of disks passed to script.
Moves= # Global variable holding number of moves.
# Modifications to original script.
dohanoi() { # Recursive function.
case $1 in
0)
;;
*)
dohanoi "$(($1-1))" $2 $4 $3
echo move $2 "-->" $3
let "Moves += 1" # Modification to original script.
dohanoi "$(($1-1))" $4 $3 $2
;;
esac
}
case $# in
1)
case $(($1>0)) in # Must have at least one disk.
1)
dohanoi $1 1 3 2
echo "Total moves = $Moves"
exit 0;
;;
*)
echo "$0: illegal value for number of disks";
exit $E_BADPARAM;
;;
esac
;;
*)
echo "usage: $0 N"
echo " Where \"N\" is the number of disks."
exit $E_NOPARAM;
;;
esac
# Exercises:
# ---------
# 1) Would commands beyond this point ever be executed?
# Why not? (Easy)
# 2) Explain the workings of the workings of the "dohanoi" function.
# (Difficult)

Converting DOS Batch Files to Shell Scripts



#!/bin/bash
# viewdata.sh
# Conversion of VIEWDATA.BAT to shell script.
DATAFILE=/home/bozo/datafiles/book-collection.data
ARGNO=1
# @ECHO OFF Command unnecessary here.
if [ $# -lt "$ARGNO" ] # IF !%1==! GOTO VIEWDATA
then
less $DATAFILE # TYPE C:\MYDIR\BOOKLIST.TXT MORE
else
grep "$1" $DATAFILE # FIND "%1" C:\MYDIR\BOOKLIST.TXT
fi
exit 0 # :EXIT0
# GOTOs, labels, smoke-and-mirrors, and flimflam unnecessary.
# The converted script is short, sweet, and clean,
#+ which is more than can be said for the original.

For further .... clik
http://www.tldp.org/LDP/abs/html/dosbatch.html

Types of shell scripts

http://rpmfind.net/linux/RPM/System_Shells.htmlash-1.6.1-2 The Ash shell linux/i586ash-1.6.1-1.1 The Ash shell linux/i586bash-completion-20050121-3 Programmable completion for bash linux/noarchbash-completion-20040711-2 Programmable completion for bash linux/noarchbash-3.0-15.2 The GNU Bourne-Again Shellbash-3.0-15 The GNU Bourne-Again Shell linux/i586bash-3.0-8.2 The GNU Bourne-Again Shell linux/x86_64 linux/i586 linux/i586 linux/i586 linux/i586bashish-2.0.7-1.bashish.generic Theme Environment For Text Terminals linux/noarchbashish-2.0.6-1.bashish.generic Theme Environment For Text Terminals linux/noarchbashish-2.0.5.1-1.bashish.generic Theme Environment For Text Terminals linux/noarchbashish-2.0.5-1.bashish.generic Theme Environment For Text Terminals linux/noarchbashish-2.0.4-1.bashish.generic Theme Environment For Text Terminals linux/noarchpdksh-5.2.14-786 Public Domain Korn Shell linux/i586pdksh-5.2.14-783 Public Domain Korn Shell linux/i586sash-3.7-32 A stand-alone shell with built-in commands linux/i586sash-3.7-31 A stand-alone shell with built-in commands linux/i586tcsh-6.14.00-2.2 The C SHell linux/i586 linux/i586 linux/i586 linux/x86_64 linux/ppc linux/i586 linux/i586 linux/i586 linux/x86_64 linux/ppctcsh-6.12.00-455 The C SHell linux/i586tcsh-6.12.00-453.3 The C SHell linux/i586tcsh-6.12.00-453.2 The C SHell linux/x86_64 linux/i586 linux/i586 linux/i586zsh-4.2.4-5 Shell with comprehensive completion