Shell implements a springboard machine

Source: Internet
Author: User

    • Zbuz add users, and bulk distribute SSH public key scripts:

#!/bin/bash. /etc/init.d/functionsfunction add_user () {         jumper= "$"         useradd ${jumper}         echo 123456 | passwd --stdin ${jumper} >/dev/ null 2>&1                 if [  ' grep -o  $jumper  /etc/passwd | wc -l '  -gt 1  ]                         then                         action  "Add user  ${jumper} success " /bin/true                 else                         action  "Add user ${jumper} success failure"  /bin/false                         exit 0                 fi        su  ${jumper} -c  "ssh-keygen -t dsa -p "  -f ~/.ssh/id_dsa > /dev/null 2>&1 "                 if [ $? -eq 0 ]                         then        &nbSp;                action   "Create ssh pub key success"  /bin/true                 else                         action   "Create ssh pub key failure"  /bin/false                 fi}add_user $*for n in 7  8    do        /usr/bin/expect /server/ Scripts/fenfa_key.exp /home/${jumper}/.ssh/id_dsa.pub ${jumper} 11.0.0.${n} >/dev/null  2>&1        IF [ $? -EQ 0 ]           then          action  "Fenfa ssh  pub key to 11.0.0.${n} success " /bin/true         else          action  "fenfa ssh  Pub key to 11.0.0.${n} failure " /bin/false         fidone
    • Expect for no password verification

#!/usr/bin/expectif {$ARGC! = 3} {puts "usage:expect $argv 0 Sshkey User host" exit} #define VarSet Sshkey  [lindex $argv 0]set User [lindex $argv 1]set host [lindex $argv 2]set password "123456" Spawn ssh-copy-id-i $sshkey [email Protected] $hostexpect {"yes/no" {send "yes\r"; exp_continue} "*password" {send "$password \ r"}}expect E Of
    • Simple shell script implementation Springboard

#!/bin/bashfunction traper () {        trap  '  INT  Quit tstp term hup}function menu () {        cat  <<-EOF================Host List==============         1) 11.0.0.7        2) 10.0.0.8         3) Exit================host end===============        eof} Function host () {user=test09        case  "$"  in  &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;1)              ssh [email protected]             ;; &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;2)              ssh [email protected]             ;; &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;3)          &NBSP;&NBSP;&NBSP;&NBSP;EXIT&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;ESAC} Function main () {  while true    do         traper        clear         menu        read -p  ' Pls input your  choice: '  num        host  $num   done}main
    • Boot script call Springboard machine script

cat/etc/profile.d/jump.sh #!/bin/bash[$UID-ne 0] && [$USER! = "Zihang"] &&/bin/bash/server/scripts/ tiaoban.sh


======================== deficiency, please advise =========================

This article is from the "Lost in Linux" blog, please be sure to keep this source http://zihang.blog.51cto.com/158746/1913476

Shell implements a springboard machine

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.