-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathfgt-set.exp
51 lines (41 loc) · 910 Bytes
/
fgt-set.exp
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
47
48
49
50
51
#!/usr/bin/expect -f
# Set variables
set hostip [lindex $argv 0]
set hostname [lindex $argv 1]
set username [lindex $argv 2]
set password [lindex $argv 3]
set logfile [lindex $argv 4]
set file "fgt-set.cmd"
set fd [open "$file" r]
set data [read $fd]
close $fd
set lines [split $data \n]
spawn ssh -o StrictHostKeyChecking=no $username\@$hostip
expect {
timeout { send_user "\nTimeout Exceeded - Check Host\n"; exit 1 }
eof { send_user "\nSSH Connection To $hostname Failed\n"; exit 1 }
"$hostname*#" {send "\n"}
"*assword:" {
send "$password\n"
}
}
send "\n"
expect "$hostname*#"
#log_user 0
set timeout 6000
log_file -a ${logfile}.log
send_user "Sending commands to $hostname"
send "\r"
expect "$hostname *#"
foreach line $lines {
send "$line\r"
expect "$hostname *#"
send "\r"
expect "$hostname *#"
}
send "\r"
expect "$hostname *#"
log_file
send_user "\n$hostname updated\n"
send "exit\n"
exit 0