Shell+expect Completing the remote startup service

Source: Internet
Author: User

Expect script: file name: expect_ssh

#!/usr/bin/expectset host [lindex $argv 0]set username [lindex $argv 1]set Password [lindex $argv 2]spawn ssh [email prote CTED] $hostexpect {"(yes/no)?" {send "yes\n" expect "*assword:" {send "$password \ n"}} "*assword:" {send "$password \ r"}}set pwd 1234567expect "$" Send "su-\r" expect "Password:" Send "$PWD \ r" expect "*]#" send "kill-9 ' ps-ef|grep java|grep-v grep|awk ' {print \$2} ' \ r ' Expect "#" send "Nohup su-tomcat-c/usr/local/tomcat6/bin/startup.sh &\r" send "\ r" send "exit\r" send "exit\r" expect E Of

Bash script: Call expect script, bash file name: bash_ssh.sh

#!/bin/shrpm-q expect &>/dev/nullif [$?-ne 0]; Then echo "Install expect ..." yum install-y expect >/dev/nullfilist_file=$1cat $list _file | While read Linedo host_name= ' echo $line | awk ' {print $} ' username= ' echo $line | awk ' {print $} ' password= ' echo $line | awk ' {print $} './expect_ssh $host _name $username $passworddone

Create a Host.list file

# Touch host.list192.168.66.130 Tom 123456192.168.66.131 Tom 123456

How to use:

SH bash_ssh.sh host.list

Shell+expect Completing the remote startup service

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.