3
我在這裏有一個方便的腳本,可以返回將在7天內過期或已過期的帳戶。我想讓它在多臺主機上運行,而無需將腳本放在每臺主機上,我添加了for loop
和ssh $SERVER >> EOF
部件,但它只是在運行腳本的系統上運行命令。
我相信錯誤是ssh $SERVER >> EOF
但我不確定,因爲語法看起來正確。
#!/bin/bash
for SERVER in `cat /lists/testlist`
do
echo $SERVER
ssh $SERVER >> EOF
sudo cat /etc/shadow | cut -d: -f1,8 | sed /:$/d > /tmp/expirelist.txt
totalaccounts=`sudo cat /tmp/expirelist.txt | wc -l`
for((i=1; i<=$totalaccounts; i++))
do
tuserval=`sudo head -n $i /tmp/expirelist.txt | tail -n 1`
username=`sudo echo $tuserval | cut -f1 -d:`
userexp=`sudo echo $tuserval | cut -f2 -d:`
userexpireinseconds=$(($userexp * 86400))
todaystime=`date +"%s"`
if [[ $userexpireinseconds -ge $todaystime ]] ;
then
timeto7days=$(($todaystime + 604800))
if [[ $userexpireinseconds -le $timeto7days ]];
then
echo $username "is going to expire in 7 Days"
fi
else
echo $username "account has expired"
fi
done
sudo rm /tmp/expirelist.txt
EOF
done
我已經做出了你提到的小改動,但行爲是一樣的。另外我注意到,對於測試列表中的每個服務器,它都會給出以下錯誤。 'line 7:EOF:Permission denied' 'line 29:EOF:command not found' – SpruceTips
'EOF:command not found'消息意味着你做錯了什麼。最有可能的是,您縮進了EOF,而我明確指出EOF不能縮進('結束標記必須位於第1列'中)。也就是說,你應該得到關於「這裏的文檔不完整」等錯誤,所以我不確定你真正嘗試了什麼。 –
發現它,我使用'>>'而不是'<<'。所有工作現在,謝謝! – SpruceTips