Skip to content

Instantly share code, notes, and snippets.

@ghostflare76
Created November 20, 2023 04:32
Show Gist options
  • Save ghostflare76/e4dff4bf11a728c67e9eb422e278c946 to your computer and use it in GitHub Desktop.
Save ghostflare76/e4dff4bf11a728c67e9eb422e278c946 to your computer and use it in GitHub Desktop.
expect timeout
#!/usr/bin/expect -f
set timeout 3
#log_user 1
spawn ./test
expect "Enter command - start, stop or quit"
send "start\r"
set total_update_file_count "not found"
set global_version "not found"
set forward_version "not found"
set time [clock format [clock seconds] -format "%Y-%m-%d %H:%M"]
set finish_time "not found"
expect {
-re {total_update_file_count :: (\d+),} {
set total_update_file_count $expect_out(1,string)
scan $total_update_file_count "%d" total_update_file_count
}
-re {Global Version : (\d+)} {
set global_version $expect_out(1,string)
scan $global_version "%d" global_version
exp_continue
}
-re {Forward Version : (\d+)} {
set forward_version $expect_out(1,string)
scan $forward_version "%d" forward_version
exp_continue
}
timeout {
send "\003"
exit 1
}
}
set timeout 300
expect "pause."
send "r\r"
if {$total_update_file_count > 0} {
puts "update occurred"
set result 0
} else {
puts "no updates"
set result 1
}
expect {
-re {finish. (\d+\.\d+)} {
set finish_time $expect_out(1,string)
}
}
puts "$global_version $forward_version $total_update_file_count $finish_time $time"
exit $result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment