我在脚本里用 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 Nov 8, 2017
|
2
crytis OP @araraloren 但是我要用 expect 输入密码
|
3
dongrenwen Sep 7, 2020
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 Sep 7, 2020
```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 ``` |