2017-07-05 151 views
1

如果用戶存在,我有腳本來檢查遠程服務器,但它只檢查第一個用戶。該腳本讀取服務器列表的文本文件並執行SSH到每個服務器,然後檢查是否ID存在:shell腳本來檢查用戶是否存在於遠程服務器中

export users 
 

 
for SERVER in `cat ./serverlist.txt` 
 
do 
 
     ssh $SERVER <<+ 
 
     set -A users "John" "Mary" "Joe" "Ana" "Jake" "Jana" "Ben" 
 
     for ids in {0..6} 
 
     do 
 
      id ${users[$ids]} 
 
     done 
 
+ 
 
done

請幫

+0

爲什麼在遙控器上設置變量?只要在John Mary的''中做'id',或者在本地分配變量並遍歷本地變量。 –

回答

0

使用'+'防止本地shell擴展變量在這裏的文件。

for SERVER in `cat ./serverlist.txt` 
do 
     ssh $SERVER <<'+' 
     set -A users "John" "Mary" "Joe" "Ana" "Jake" "Jana" "Ben" 
     for ids in {0..6} 
     do 
      id ${users[$ids]} 
     done 
+ 
done 

僅供參考。

for server in `cat ./serverlist.txt` 
do 
     ssh -- "$server" <<'+' 
     set -A ids "John" "Mary" "Joe" "Ana" "Jake" "Jana" "Ben" 
     for id in "${ids[@]}" 
     do 
      id "$id" 
     done 
+ 
done 
相關問題