Skip to content

Instantly share code, notes, and snippets.

@satokjp
Last active August 29, 2015 13:58
Show Gist options
  • Save satokjp/9949956 to your computer and use it in GitHub Desktop.
Save satokjp/9949956 to your computer and use it in GitHub Desktop.
#!/usr/bin/expect
# for cygwin64
#
# time format:
# date +"%m/%d %k:%M:%S %Y"
#
# timeout sec
set timeout 10
#
iif { $argc == 0 } {
puts "usage: set_time.tcl \[192.168.1.*\] \[time\]"
puts ""
puts "time format : date +\"%m/%d %k:%M:%S %Y\" "
exit
}
set IP [lindex $argv 0]
set TIME [lindex $argv 1]
# Host name
set HOST "[email protected]."
append HOST $IP
set PASSWD1 "user-passwd"
set PASSWD2 "root-passwd"
set CMD1 "ls -l"
set CMD2 "LANG=C"
set CMD3 "su -"
set CMD4 "date"
set CMD5 "date -s \"$TIME\""
set CMD6 "hwclock --systohc"
puts ""
puts "----- start -----"
puts "IP: 192.168.1.$IP"
puts "TIME: $TIME"
spawn ssh $HOST
sleep 1
expect "(yes/no)?" {
send "yes\n"
expect "password: "
send "$PASSWD1\r"
} "password: " {
send "$PASSWD1\r"
}
#expect "password:"
#send "$PASSWD\n"
expect "Last login"
expect "]$ "
send "$CMD1\r"
expect "]$ "
send "$CMD2\r"
expect "]$ "
send "$CMD3\r"
expect "Password: "
send "$PASSWD2\r"
#
expect "]\\# "
send "$CMD2\r"
#
expect "]\\# "
send "$CMD4\r"
#
expect "]\\# "
send "$CMD5\r"
#
expect "]\\# "
send "$CMD4\r"
#
expect "]\\# "
send "$CMD6\r"
#
#expect "]\\# "
#send "exit\r"
#
#expect "]\\$ "
#send "exit\r"
interact
puts "----- end -----"
exit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment