Shell Programming Examples: Difference between revisions

From RoggeWiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 59: Line 59:
  cat    > aapbody
  cat    > aapbody
  $
  $
[Category:Unix]

Revision as of 15:37, 2 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
$

[Category:Unix]