-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathauto-listen-vm.sh
More file actions
46 lines (43 loc) · 1.21 KB
/
Copy pathauto-listen-vm.sh
File metadata and controls
46 lines (43 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/bin/sh
IP="192.168.58.109"
OS="centos"
USER="cmcc"
password="123456"
add_bigren='"sudo su -c \"userdel -r bigren;useradd -s /bin/bash -m bigren -g root\""'
modify_passwd='"sudo su -c \"passwd bigren\""'
create_sshkey='ssh-keygen -t rsa'
#Warning:you must add "exp_continue" when expect "cmcc*" otherwise it won't execute the command:
#"userdel -r jason;useradd -s /bin/bash -m jason -g root"
add_bigren(){
expect<<EOF
set timeout -1
spawn ssh -t $USER@$IP $add_bigren
expect {
"cmcc*" {send "CMCC@22F\r";exp_continue}
"userdel*" {send "\r\n";exp_continue}
}
EOF
}
#The function of create_keygen has two functions:1,modify the password of bigren.
#2,add the sshkey for exchanging secret key for the first level machine
create_keygen()
{
expect<<EOF
set timeout -1
spawn ssh -t $USER@$IP $modify_passwd;
expect {
"*cmcc*" {send "CMCC@22F\r";exp_continue}
"*password:" {send "$password\r";exp_continue}
"*password:" {send "$password\r"}
}
spawn ssh -t bigren@192.168.58.109 $create_sshkey;
expect {
"*password:" {send "$password\r";exp_continue}
"Enter*" {send "\r\n";exp_continue}
"Enter*" {send "\r\n";exp_continue}
"Enter*" {send "\r\n"}
}
EOF
}
add_bigren
create_keygen