gpt4 book ai didi

linux - Linux 服务器上的期望代码问题

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:18:45 25 4
gpt4 key购买 nike

我正在尝试使用以下脚本连接 ssh 服务器

exp_internal 1

#!/usr/bin/expect

grep "$1" serverlist.txt
if [ $? = 0 ]
then
eval spawn ssh -oStrictHostKeyChecking=no -oCheckHostIP=no ghayat@$server_ip
expect "password: "
send "Password\r"
expect "$ "
send "touch Deepo22_9\r"
expect "$ "
send "exit\r"
interact
fi

但我收到以下错误:

[root@Server_name DMSSH]# ./testscript.sh $server_ip
./testscript.sh: line 1: exp_internal: command not found
172.24.194.50
./testscript.sh: line 8: spawn: command not found
couldn't read file "password: ": no such file or directory
./testscript.sh: line 10: send: command not found
couldn't read file "$ ": no such file or directory
./testscript.sh: line 12: send: command not found
couldn't read file "$ ": no such file or directory
./testscript.sh: line 14: send: command not found
./testscript.sh: line 15: interact: command not found

代码没有 grep & if 是正确的,那么如何正确添加 grep & if 呢?

此外,我还尝试在执行脚本“$1”时传递服务器 ip,以便在运行 ssh 之前首先检查 DB.txt 文件,但它似乎无法正常工作。

最佳答案

您不能在 expect 脚本中使用 grepif。这些是外部命令和 shell 结构。

expect 有它自己的 if 支持,如果你想使用它(因为 expect 只是 tcl) .

但是如果你想在调用你的 expect 脚本之前做其他事情,你需要一个包装器 shell 脚本。

关于linux - Linux 服务器上的期望代码问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25976760/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com