#!/bin/bash
if [[ -z $1 || -z $2 ]]; then
echo "ssh-expect 地址 密码 \"命令(分号分隔)\" "
exit 1
fi
cmd=$3
cmd=${cmd//\\/\\\\}
cmd=${cmd//\"/\\\"}
cmd=${cmd//\`/\\\`}
cmd=${cmd//\$/\\\$}
expect -c "
set timeout 30;
spawn ssh $1 \"$cmd\";
expect \"root@$1's\";
send \"$2\n\";
interact
"
ssh登录并执行命令脚本
最新推荐文章于 2024-07-19 09:45:02 发布