问题
My TCL script:
source reboot_patch.tcl
set a 1
while {$a < 10} {
exec reboot_patch.tcl
after 60000
incr a
}
I need to run "reboot_patch.tcl" script for every 1 min in my system. I wrote above script. But its running only once and its coming out.
Following is the "reboot_patch.tcl" script:
#!/usr/bin/tcl
package require Expect
spawn telnet 40.1.1.2
expect "*console."
send "\r"
expect "*ogin:"
send "test\r"
expect "*word:"
send "test\r"
expect "*>"
send "clear log\r"
expect "*#"
send "commit \r"
expect "*#"
Please suggest me a way to achieve this.
Thanks in advance.
Script to print numbers from 1 to 10 in windows 7:
#!c:\Tcl\bin\tclsh
set a 1
while { $a < 11} {
puts $a
incr a
}
I am unable to run the above script using "./" format in windows7.
回答1:
In general, exec
command will return the output of program execution. It is our responsibility to capture and print and manipulate it.
You have to print it manually like
puts [ exec ./reboot_patch.tcl ]
Or like,
set result [ exec ./reboot_patch.tcl ]
puts $result
Since you are using exec
without printing it's result, you have not seen anything. Then how come it got executed for the first time ? Who else can do except the following ?
source reboot_patch.tcl
Well, Since you have sourced the file and it got executed which seemed to be the first time execution but which is not actually from exec
command.
Note : If you are calling any of that sourced file's proc
, then only it is required to source it. As far as I can see you are not having any proc there. So, source is not required at all.
来源:https://stackoverflow.com/questions/27420398/how-to-run-a-tcl-script-to-tell-run-in-every-10-minutes