我在脚本里用 expect ssh 到机器上执行命令,比如 ls,如何把这个结果拿回来在脚本里使用?
expect -c "
spawn ssh -f -o StrictHostKeyChecking=no [email protected] ls
expect {
\"*assword\" {set timeout 6000; send \"123456\`\n\"; exp_continue ; sleep 30; }
\"yes/no\" {send \"yes\n\"; exp_continue;}
}
interact"
搜了半天没整明白
1
araraloren 2017 年 11 月 8 日
|
2
crytis OP @araraloren 但是我要用 expect 输入密码
|
3
dongrenwen 2020 年 9 月 7 日
ret=$(
expect -c " spawn ssh -f -o StrictHostKeyChecking=no [email protected] ls expect { \"*assword\" {set timeout 6000; send \"123456\`\n\"; exp_continue ; sleep 30; } \"yes/no\" {send \"yes\n\"; exp_continue;} } interact" ) cat <<EOF ${ret} EOF |
4
dongrenwen 2020 年 9 月 7 日
```bash
ret=$( expect -c " spawn ssh -f -o StrictHostKeyChecking=no [email protected] ls expect { \"*assword\" {set timeout 6000; send \"123456\`\n\"; exp_continue ; sleep 30; } \"yes/no\" {send \"yes\n\"; exp_continue;} } interact" ) cat <<EOF ${ret} EOF ``` |