Shell Programming Examples: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
| Line 59: | Line 59: | ||
cat > aapbody | cat > aapbody | ||
$ | $ | ||
===mksysb=== | |||
Create a mksysb and remove older versions. The script runs on the NIM master and an NIM machine resource for the host to be backed up is needed. | |||
The mksysb is pulled from the NIM client. | |||
#/usr/bin/ksh | |||
# | |||
# Make mksysb | |||
# | |||
# Arguments Hostname and Suffix | |||
# Pick YYMMDD as suffix. | |||
# | |||
# Run the mksysb and cleanup older versions | |||
# | |||
P=/backups/mksysb/ | |||
nim -o define -t mksysb -a server=master -a source=${1} -a mk_image=yes -a mksysb_flags=ev -a location=$P${1}-${2}.mksysb ${1}-${2} >$P${1}-${2}.log 2>$P${1}-${2}.err | |||
if [ $? = 0 ] | |||
then | |||
echo NIM backup for ${1} completed successfully | |||
gzip $P${1}-${2}.mksysb & | |||
else | |||
echo NIM backup for ${1} failed, rc=$? | |||
fi | |||
# | |||
# Remove older versions | |||
# Remove NIM resources and corresponding files | |||
Versions=3 # Number of versions to keep on disk | |||
let Arg=$Versions+1 | |||
echo Available NIM resources: | |||
lsnim -t mksysb|grep ${1}|sort | |||
for i in $(lsnim -t mksysb|grep ${1}|sort -r|tail -n +$Arg|awk '{print $1}') | |||
do | |||
# nim -o remove -a rm_image=yes ${i} # Image renamed by gzip to .gz | |||
nim -o remove ${i} | |||
if [ $? = 0 ] | |||
then | |||
echo NIM resource ${i} deleted | |||
echo Available files: | |||
ls -l $P${1}* | |||
echo Removing files: | |||
ls -l $P${i}* | |||
echo rm $P${i}* | |||
else | |||
echo "Error during remove NIM resource ${i}, rc=$?" | |||
fi | |||
done | |||
[[Category:Unix]] | [[Category:Unix]] | ||
Revision as of 07:49, 11 June 2015
Ping all hosts in a subnet
subnet=”141.93.169
i=1
while [ $i -lt 255 ]
do
ping ${subnet}.${i} 2 1>/dev/null 2>&1
if [ $? -ne 0 ] ; then
echo "${subnet}.${i},down"
else echo "${subnet}.${i},up"
fi
i=$(expr $i + 1 )
done
sshhost
#!/bin/bash # # ssh-keygen -t dsa -b 8192 # Host=`echo $0|cut -d / -f5` echo "Logon " `date "+%m/%d/%y %H:%M:%S"` $Host >> $HOME/logs/sshhost.log # Use escape sequence to modify SecureCrt window title: ESC]; text CTRL-G printf "\033];$Host\007" Hmcs="hmc100.hmc200" Vios="uio200.uio299.uio300.uio399" User="" [ ! -z $(echo "$Hmcs" | grep "$Host") ] && User="hscroot@" [ ! -z $(echo "$Vios" | grep "$Host") ] && User="padmin@" [ ! -z $(echo "$Host" | grep "vio") ] && User="padmin@" ssh $User$Host printf "\033];`uname -n`\007" echo "Logof " `date "+%m/%d/%y %H:%M:%S"` $Host >> $HOME/logs/sshhost.log
copypublic.sh
#!/usr/bin/ksh # # Copy public key to another system. Target system is $1. scp -pr $HOME/.ssh/id_dsa.pub $1:/tmp/ ssh $1 <<EOF mkdir -m 700 .ssh cat /tmp/id_dsa.pub >>.ssh/authorized_keys chmod 600 .ssh/authorized_keys rm /tmp/id_dsa.pub EOF
postman
How to proces a mail
$ cat .forward |/home/roggt/receivemail $ cat receivemail #!/usr/bin/ksh echo $(date) >> aaplog echo "0" $0 >> aaplog echo "1" $1 >> aaplog echo $(env) >> aaplog echo Extension $EXTENSION >>aaplog cat > aapbody $
mksysb
Create a mksysb and remove older versions. The script runs on the NIM master and an NIM machine resource for the host to be backed up is needed. The mksysb is pulled from the NIM client.
#/usr/bin/ksh
#
# Make mksysb
#
# Arguments Hostname and Suffix
# Pick YYMMDD as suffix.
#
# Run the mksysb and cleanup older versions
#
P=/backups/mksysb/
nim -o define -t mksysb -a server=master -a source=${1} -a mk_image=yes -a mksysb_flags=ev -a location=$P${1}-${2}.mksysb ${1}-${2} >$P${1}-${2}.log 2>$P${1}-${2}.err
if [ $? = 0 ]
then
echo NIM backup for ${1} completed successfully
gzip $P${1}-${2}.mksysb &
else
echo NIM backup for ${1} failed, rc=$?
fi
#
# Remove older versions
# Remove NIM resources and corresponding files
Versions=3 # Number of versions to keep on disk
let Arg=$Versions+1
echo Available NIM resources:
lsnim -t mksysb|grep ${1}|sort
for i in $(lsnim -t mksysb|grep ${1}|sort -r|tail -n +$Arg|awk '{print $1}')
do
# nim -o remove -a rm_image=yes ${i} # Image renamed by gzip to .gz
nim -o remove ${i}
if [ $? = 0 ]
then
echo NIM resource ${i} deleted
echo Available files:
ls -l $P${1}*
echo Removing files:
ls -l $P${i}*
echo rm $P${i}*
else
echo "Error during remove NIM resource ${i}, rc=$?"
fi
done