我需要爲須藤通過ssh運行命令: -運行sudo命令通過ssh
ssh ${SSH_SERVER} -l "sudo <command>"
我要帶密碼的腳本,並把它提供給須藤 - 有點像。
export PASSWORD=<From user>
ssh ${SSH_SERVER} -l "sudo <command> | echo $PASSWORD"
我不能寫這樣的腳本,需要幫助。
的bash -version GNU的bash,版本4.1.2(1)-release下(x86_64-紅帽Linux的GNU的) 版權所有(C)2009自由軟件基金會,公司 許可的GPLv3 +:GNU GPL版本3或後來http://gnu.org/licenses/gpl.html
================編輯===================
我試過的建議下面給出,但我得到一個錯誤。
[[email protected] ~]$ cat temp.sh
#!/bin/bash -xv
function f1 {
### Do NOT indent these lines until end comment ###
cat > /tmp/$HOSTS-pw.sh <<EOS
#!/bin/sh -xv
ssh -q -tt $HOSTS sudo "sudo ls" <<EOC
$SUDOPW
EOC
EOS
### End Comment ###
chmod 700 /tmp/$HOSTS-pw.sh
/tmp/$HOSTS-pw.sh >/dev/null
if [ -f /tmp/$HOSTS-pw.sh ]; then rm -f /tmp/$HOSTS-pw.sh; fi
}
export HOSTS="destination.host"
echo "Enter SUDO password:"
read -s SUDOPW
f1
unset SUDOPW
exit 0
[[email protected] ~]
[[email protected] ~]
[[email protected] ~]
[[email protected] ~]$ ./temp.sh
#!/bin/bash -xv
function f1 {
### Do NOT indent these lines until end comment ###
cat > /tmp/$HOSTS-pw.sh <<EOS
#!/bin/sh -xv
ssh -q -tt $HOSTS sudo "sudo ls" <<EOC
$SUDOPW
EOC
EOS
### End Comment ###
chmod 700 /tmp/$HOSTS-pw.sh
/tmp/$HOSTS-pw.sh >/dev/null
if [ -f /tmp/$HOSTS-pw.sh ]; then rm -f /tmp/$HOSTS-pw.sh; fi
}
export HOSTS="destination.host"
+ export HOSTS=destination.host
+ HOSTS=destination.host
echo "Enter SUDO password:"
+ echo 'Enter SUDO password:'
Enter SUDO password:
read -s SUDOPW
+ read -s SUDOPW
f1
+ f1
+ cat
+ chmod 700 /tmp/destination.host-pw.sh
+ /tmp/destination.host-pw.sh
#!/bin/sh -xv
ssh -q -tt destination.host sudo "sudo ls" <<EOC
My-password
EOC
+ ssh -q -tt destination.host sudo 'sudo ls'
tcgetattr: Inappropriate ioctl for device
+ '[' -f /tmp/destination.host-pw.sh ']'
+ rm -f /tmp/destination.host-pw.sh
unset SUDOPW
+ unset SUDOPW
exit 0
+ exit 0
的[適當的方式來須藤通過ssh]可能的複製(http://stackoverflow.com/questions/10310299/proper-way-to-sudo-over-ssh) – idjaw