001.[root@pyzc-mycat test]# ./expect130.expect
wrong # args: should be "set varName ?newValue?"
while executing
"set host "192.168.106.130" #在expect里定义变量是需要加set 这里定义host为第二台机器"
(file "./expect130.expect" line 2)
https://stackoverflow.com/questions/34095529/tcl-error-wrong-args-should-be-set-varname-newvalue
That message:
wrong # args: should be "set varName ?newValue?"
is a standard error thrown when a built-in command gets the wrong number of arguments to evaluate. In this case, it's coming from theset
command, and indicates that you've either saidset
on its own, or given more than two further arguments to it.
If you examine the stack trace (usually printed with the error message when using standardtclsh
, though it's changeable with user code) then you'll get told where the problem happened. However,in this case we can look through and see that this line near the bottom of the script:
set ag_around_water resid [$ag_around_water get resid]
has what appears to be a space instead of an underscore in the variable name. Now, spaces arelegal in variable names, but then the variable name needs to be quoted, and that can get a bit annoying. It's usually best to avoid using them like that. Without quoting, Tcl doesn't know that that's meant to be one word; the generic parsing layer decides there's really four words there (set
,ag_around_water
,resid
and the complex[$ag_around_water get resid]
) and tellsset
to deal with that, which it doesn't like.
Remember, Tcl's generic syntactic parsing happens first, before command arguments are interpreted semantically. Always.
002.[root@pyzc-mycat test]# ./expecttr.expect root 192.168.106.130 w
spawn ssh root#这里定义第一个递归参数@192.168.106.130#定义第二个参数
ssh: Could not resolve hostname 192.168.106.130#\345\256\232\344\271\211\347\254\254\344\272\214\344\270\252\345\217\202\346\225\260: Name or service not known
send: spawn id exp6 not open
while executing
"send "$cm\r""
(file "./expecttr.expect" line 13)
#的注释请另起一行
003.[root@pyzc-mycat ~]# rsync -av root@192.168.106.130:/tmp/12.txt /tmp/
root@192.168.106.130's password:
bash: rsync: 未找到命令
rsync: connection unexpectedly closed (0 bytes received so far) [Receiver]
rsync error: remote command not found (code 127) at io.c(226) [Receiver=3.1.2]
线上的目标服务器没有安装rsync导致(两端服务器都要安装yum install -y rsync)