You are on page 1of 5

SSH Scripting:

Start the program with statement: #!/usr/bin/sh


We can also include: store_date=`date '+%Y%m%d%H%M'`

Echo: The command prints what is given on display
e.g.

#!/usr/bin/sh
store_date=`date '+%Y%m%d%H%M'`

# My first script {Comments after #. Anything after # will not be
compiled}

echo "Hello World!"

Output on terminal: Hello World!


chmod 755 first_script

chmod 755 will give read, write, and execute permission to the file `first_script`
./first_script
The statement above is used to execute the file in terminal
mkdir bin
mkdir is used to create a new directory
type command
type will display what type of command it is
I/O Redirection
Standard Output
Most command line programs that display their results do so by sending their
results to a facility called standard output.3
ls > file_list.txt

In this example, the ls command is executed and the results are written in a
file named file_list.txt. Each time the command above is repeated, file_list.txt is
overwritten (from the beginning) with the output of the commandls. If you
want the new results to be appended to the file instead, use ">>" like this

ls >> file_list.txt

Standard Input
Many commands can accept input from a facility called standard input.

sort < file_list.txt

In the above example we used the sort command to process the contents of
file_list.txt. The results are output on the display since the standard output is
not redirected in this example. We could redirect standard output to another file
like this:
sort < file_list.txt > sorted_file_list.txt

PIPES
With pipes, the standard output of one command is fed into the standard input
of another
ls -l | less
In this example, the output of the ls command is fed into less. By using
this "| less" trick, you can make any command have scrolling output

Command What it does
ls -lt | head
Displays the 10 newest files in the current
directory.
du | sort -nr
Displays a list of directories and how much
space they consume, sorted from the
largest to the smallest.
find . -type f -print | wc -l
Displays the total number of files in the
current working directory and all of its
FILTERS
Program What it does
sort
Sorts standard input then outputs the sorted result on standard
output.
uniq
Given a sorted stream of data from standard input, it removes
duplicate lines of data (i.e., it makes sure that every line is unique).
grep
Examines each line of data it receives from standard input and
outputs every line that contains a specified pattern of characters.
fmt
Reads text from standard input, then outputs formatted text on
standard output.
pr
Takes text input from standard input and splits the data into pages
with page breaks, headers and footers in preparation for printing.
head
Outputs the first few lines of its input. Useful for getting the header
of a file.
tail
Outputs the last few lines of its input. Useful for things like getting
the most recent entries from a log file.
tr
Translates characters. Can be used to perform tasks such as
upper/lowercase conversions or changing line termination
characters from one type to another (for example, converting DOS
text files into Unix style text files).
sed
Stream editor. Can perform more sophisticated text translations
than tr.
awk
An entire programming language designed for constructing filters.
Extremely powerful.


Mobatch: Purpose: To send moshell commands to several nodes in parallel.

Arguments:
- The first argument is the sitefile, sitelist, or dumpdir.
The sitefile is a file containing the list of sites to connect to. Each line in
the sitefile contains:
* The IP/DNS addresses and/or site names whose IP address are
defined in the IP database.
* Optionally: the uservariables/scriptingvariables to input with -v
option.
See example of sitefile and ipdatabase in:
moshell/examples/mobatch_files/
If using the sitelist, the sites are listed on the command line and
separated by commas.
The dumpdir is a directory containing:
* MO dumps (format: <kget.log.gz> or <modump.zip>)
* or CVs/dbdat files (format: <cv.zip> or <db.dat>) -> only
supported with option "-d"
- The second argument is the commmands or commandfile.
See example of commands below and commandfile in
moshell/examples/mobatch_files
If a directory is given, then a different commandfile will be used for each
node:
the name of each commandfile should be <node-name>.cmd or
<node-name>.mos
the <node-name> should be the same as given in the sitefile.
example: node-name is rbs602 ==> commandfile should be
rbs602.cmd or rbs602.mos
- The third argument (logdirectory) is optional. If no logdirectory is
specified, a default one will be used.

Options:
- t <minutes> Specify the number of minutes before timing out. Set
to 0 for no timeout (default=20 minutes)
- p <processes> Specify the maximum number of moshell sessions
that will run in parallel (default=10 parallel sessions)
- i <seconds> Specify the interval in seconds between spawning of
each moshell session (default=0 seconds)
- w <seconds> Specify the interval in seconds between the checks on
running sessions (default= 2.5 seconds)
- v <userVariables> Specify moshell uservariables. Type "moshell" on its
own for more info about this option.
- o Print output of every moshell session both to screen and to
logfile.
- s Silent. No output is printed.
- d Run moshell in sql mode. Only applicable when first
argument is a directory ("dumpdir")
- r Recursive folder search. Only applicable when first
argument is a directory ("dumpdir").

Examples:
mobatch -p 15 -t 60 ~/sitefiles/victoria-sites 'lt all ; get'
mobatch 10.1.128.10 ./cmdfiles/kget.mos
mobatch 10.1.128.10,rnc34,rbs10,mgw1.ericsson.se
./cmdfiles/kget.mos
mobatch ./sitefiles/all-rbs.txt ./cmdfiles/do_healthCheck.mos
mobatch -p 5 -t 1 ./sitefiles/all-rbs.txt 'cv cu ; rbs'
mobatch ./sitefiles/all-rnc.txt 'lt ^utrancell ; st cell'
mobatch ./sitefiles/all-bsc.txt ~/bsc-commandfiles/
mobatch -v
security_method=2,sa_credential=~/sam.pbe,sa_password=oemas -p 20
./all_mgw.txt 'hc'
mobatch -v ip_database=~/utran_network/ipdatabase
~/utran_network/ipdatabase 'lt all ; get '
mobatch modumpfolder/ 'str;std;sti;stv;inv'
mobatch -r modumpfolder/ 'str;std;sti;stv;inv'
mobatch -dr dbdatfolder/ dbc

You might also like