我試圖將SSH
自動化到一臺機器中,然後運行一些命令。但是,我正在逐漸的SSH
部分卡:自動化SSH和運行命令
for h in ${hosts[*]}; do
ssh -i foo.pem [email protected]$h
echo "here"
sudo bash
cd /data/kafka/tmp/kafka-logs/
exit
exit
done
當我運行該腳本,我可以SSH方式,但自動化在此消息停止:
********************************************************************************
This is a private computer system containing information that is proprietary
and confidential to the owner of the system. Only individuals or entities
authorized by the owner of the system are allowed to access or use the system.
Any unauthorized access or use of the system or information is strictly
prohibited.
All violators will be prosecuted to the fullest extent permitted by law.
********************************************************************************
Last login: Thu Dec 10 10:19:23 2015 from 10.81.120.55
-bash: ulimit: open files: cannot modify limit: Operation not permitted
當我按下control + d
,我的echo "here"
命令執行,然後我的腳本退出。不執行其餘的命令。
我看周圍,我試過,但我得到這個語法錯誤:
./kafka_prefill_count.sh: line 38: warning: here-document at line 26 delimited by end-of-file (wanted `EOF')
./kafka_prefill_count.sh: line 39: syntax error: unexpected end of file
腳本:
for h in ${hosts[*]}; do
ssh -i foo.pem [email protected]$h << EOF
echo "here"
sudo bash
cd /data/kafka/tmp/kafka-logs/
ls | grep "$dir_name"
exit
exit
bash -l
EOF
done
試着用'sudo'? –
您可以使用ssh命令'ssh -i foo.pem bc2-user @ $ h'運行命令。編寫連接設備上運行的腳本可能比一系列ssh命令更容易。 –
@MattTuttle我試圖運行相同的命令集到很多機器,所以我必須將該腳本複製到每臺機器=/ – Liondancer