我编写了一个bash脚本,它运行到每台机器并运行一组命令。我正在使用在该计算机上具有sudo privlidges的用户iis。但是,当我运行sudo yum命令时,我得到了sudo:抱歉,你必须有一个tty才能运行sudo。
不确定有什么问题?我使用-t命令强制但它仍然不起作用
bash脚本
#!/bin/bash
INPUT=ccidetails.csv
OLDIFS=$IFS
IFS=,
[ ! -f $INPUT ] && { echo "$INPUT file not found"; exit 99; }
while read privateip password
do
echo $privateip
scp /home/Data/Test.c iis@$privateip:/tmp
sshpass -p$password </dev/null ssh -t -o "StrictHostKeyChecking no" iis@$privateip "
hostname
cd /tmp
gcc Test.c -o TEST
./TEST
sudo yum -y update glibc
gcc Test.c -o TEST
./TEST
exit
" >> output.txt
done < $INPUT
IFS=$OLDIFS
错误:
sudo: sorry, you must have a tty to run sudo
答案 0 :(得分:7)
在远程主机上注释/ etc / sudoers下面的行:
grep tty /etc/sudoers
#Defaults requiretty
这将允许你继续。确保您了解这样做的后果:
man sudoers | grep -i requiretty -A 5
requiretty If set, sudo will only run when the user is logged in
to a real tty. When this flag is set, sudo can only be
run from a login session and not via other means such
as cron(8) or cgi-bin scripts. This flag is off by
default.
如果您不想全局禁用requiretty,可以为特定用户禁用它:
示例:
Defaults requiretty
Defaults:your_username_goes_here !requiretty
答案 1 :(得分:2)
虽然这不是SO的问题,但你几乎就在那里......你需要改变的是上面的-t数...试试这个:
sshpass -p$password </dev/null ssh -ttt -o "StrictHostKeyChecking no" iis@$privateip "