FastHandle - IT Operations Examples

FastHandle is fast operation tools for infrastructure configurations and tests.

User Tools

Site Tools


Sidebar


Top     SiteMap

Manager Server

Target Server

$FHHOME/bin/xxx.sh | xxxx.exp













.

fhscripts:fh:fhssh.sh.html



This is an old revision of the document!



FastHandle Scripts

fhssh.sh - auto login script

Operation

$ fhssh.sh 192.168.0.10


Script

#!/bin/bash
#=====================================================================
# fhssh.sh
# 
# How to use
#    fhssh.sh  xx.xx.xx.xx
#=====================================================================

if [ -z $1 ]; then
    echo 'ERROR:  $1 argument is null'
    echo 'How to use:'
    echo 'fhssh.sh 192.168.0.10'
    exit 1
fi

HOST=$1

# ------------------------------------------
SSH_PASS () {

expect -c "
set timeout 5
spawn ssh  ${USER}@${HOST}
expect \"assword:\"
send \"$PASSWD\r\"
interact
"
}

# ------------------------------------------
SSH_KEY_NOPASS () {

expect -c "
set timeout 5
spawn ssh -i ${KEY} ${USER}@${HOST}
expect \"$\"
interact
"
}

# ------------------------------------------
SSH_KEY_PASS () {

expect -c "
set timeout 5
spawn ssh -i ${KEY} ${USER}@${HOST}
expect \"assword:\"
send \"$PASSWD\r\"
expect \"$\"
interact
"
}

# ------------------------------------------
SRX () {

expect -c "
set timeout 5
spawn ssh  ${USER}@${HOST}
expect \"assword:\"
send \"$PASSWD\r\"
expect \"%\"
send \"cli\r\"
expect \">\"
send \"show configuration | display set | no-more\"
interact
"
}


cat <<MENU
=====================================================================
Select Number or character
---------------------------------------------------------------
   1) production  user01   password atuh
   2) stating  user01
   3) test  user01
   a) SRX  production
   b) SRX  staging
   c) SRX  qa
   q) quit
=====================================================================
MENU

echo -n -e "\t >"
read NUM
case ${NUM} in
  1) USER=user01
     PASSWD=testpass
     SSH_PASS
    ;;
  2) USER=user01
     PASSWD=testpass
     KEY=/home/xxx/.ssh/xxxx.pub
     SSH_KEY_NOPASS
    ;;
  3) USER=user01
     PASSWD=testpass
     SSH_KEY_PASS
    ;;
  a) USER=user01
     PASSWD=testpass
     SRX
    ;;
  b) USER=user01
     PASSWD=testpass
     SRX
    ;;
  c) USER=user01
     PASSWD=testpass
     SRX
    ;;
  q|Q) exit
     ;;
  *) echo "ERROR : selection is missed."
     exit
     ;;
esac








FastHandle Scripts



fhscripts/fh/fhssh.sh.html.1512218728.txt.gz ยท Last modified: 2017/12/02 21:45 by kurihara