shell-027 shell常见错误集锦

本文深入解析了在使用Expect脚本时遇到的常见错误,如wrong #args: should be set varName? newValue?及SSH连接失败的问题,并提供了详细的解决方案。同时,还讨论了rsync命令在目标服务器上未找到的情况,强调了确保服务器间软件一致性的重要性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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 the set command, and indicates that you've either said set 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 standard tclsh, 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 (setag_around_waterresid and the complex [$ag_around_water get resid]) and tells set 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)

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值