如何运行TCL脚本以告知每10分钟运行一次? [英] How to run a TCL script to tell run in every 10 minutes?

查看:639
本文介绍了如何运行TCL脚本以告知每10分钟运行一次?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的TCL脚本:

source reboot_patch.tcl

set a 1
while {$a < 10} {
    exec reboot_patch.tcl
    after 60000
    incr a
}

我需要在系统中每1分钟运行"reboot_patch.tcl"脚本.我写了上面的脚本.但是它只运行一次就出来了.

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.

以下是"reboot_patch.tcl"脚本:

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.

谢谢.

在Windows 7中打印从1到10的数字的脚本:

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

}

我无法在Windows7中使用"./"格式运行上述脚本.

I am unable to run the above script using "./" format in windows7.

推荐答案

通常,exec命令将返回程序执行的输出.捕获并打印和操作它是我们的责任.

In general, exec command will return the output of program execution. It is our responsibility to capture and print and manipulate it.

您必须像

puts [ exec ./reboot_patch.tcl ]

或者,

set result [ exec ./reboot_patch.tcl ]
puts $result

由于使用的是exec而不打印结果,因此您什么也没看到.那它是如何第一次执行的呢?除了以下几点,谁还能做?

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

好吧,既然您已经获得了文件的源代码并执行了该文件,这似乎是第一次执行,但实际上并非来自exec命令.

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.

注意::如果您正在调用该源文件的任何proc,则仅需要源文件.据我所知,您那里没有任何进程.因此,根本不需要来源.

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.

这篇关于如何运行TCL脚本以告知每10分钟运行一次?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆