远程SSH两级跳转用户sodu的问题–sudo: no tty presen下载
[Linux]远程SSH两级跳转用户sodu的问题–sudo: no tty present and no askpass program specified 业务场景描述: 我有100多组mysql db服务器,那么其中10台我需要建一个mysql用户下的文件,如果知识兔按照正常流程来看,我需要在跳转控制机dbcrol上面 ssh 到mysql 服务器上面,但是sudo进去的可不是mysql帐号,而是一个novaadmin帐号,我还需要执行sudo su – mysql命令跳转进入mysql用户模式下,才能执行mkdir -p /mysqlog/slow_log/a1.log。 1 我需要先测试一个在跳转控制机器dbcrol上面能远程执行ssh mkdir的命令。[nova@dbcrol cacti]$ ssh db02703 “sudo su -u mysql 'mkdir /mysqllog/log/a1.log'”sudo: no tty present and no askpass program specifiedSorry, try again.sudo: no tty present and no askpass program specifiedSorry, try again.sudo: no tty present and no askpass program specifiedSorry, try again.sudo: 3 incorrect password attempts[nova@dbcrol cacti]$失败了,看来此路不通啊。 2 google,继续看看去掉‘’试试。在一篇文章里面看到 “sudo su -u mysql 'mkdir /mysqllog/log/a1.log'”中不需要把里面的命令行用''括起来,去掉试试看。[nova@dbcrol cacti]$ ssh db02703 “sudo su -u mysql mkdir /mysqllog/log/a1.log”sudo: no tty present and no askpass program specifiedSorry, try again.sudo: no tty present and no askpass program specifiedSorry, try again.sudo: no tty present and no askpass program specifiedSorry, try again.sudo: 3 incorrect password attempts[nova@dbcrol cacti]$失败了,看来此路also不通啊。dnzg.cn3 继续google之,有人说要去掉su 换成 “sudo -u mysql mkdir /mysqllog/log/a1.log”吧:[nova@dbcrol cacti]$ ssh db02703 “sudo -u mysql mkdir /mysqllog/log/a1.log”[nova@dbcrol cacti]OK,搞定了。 4 For循环,实现批量串行mkdir[nova@dbcrol cacti] vim create_log1_20131101.shfor i in `cat $1`; doecho $i;ssh $i “sudo -u mysql mkdir /mysqllog/log/a1.log”;echo “”;done; 5 执行脚本 [nova@dbcrol cacti] sh create_log1_20131101.sh db01list;db00101db00201db00301……..db12801至此,所有128台db执行完毕。
本文来自系统大全为您分享如需转载请注明!推荐win10下载
下载仅供下载体验和测试学习,不得商用和正当使用。