How to run a TCL script to tell run in every 10 minutes?

主宰稳场 提交于 2020-01-04 05:18:25

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!