0
爲什麼echo "Line $line"
內的附加'Line'不會被預置到for循環中的所有文件?
Bash:從ls命令內部爲循環格式化結果
#!/bin/bash
INPUT=targets.csv
IFS=","
[ ! -f $INPUT ] && { echo "$INPUT file not found"; exit 99; }
while read target user password path
do
result=$(sshpass -p "$password" ssh -n "$user"@"$target" ls "$path"*file* 2>/dev/null)
if [ $? -ne 0 ]
then
echo "No Heap dumps detected."
else
echo "Found a Heap dump! Possible OOM issue detected"
for line in $result
do
echo "Line $line"
done
fi
done < $INPUT
.csv文件內容..
[email protected]:~/scripts$ cat targets.csv
server.com,root,passw0rd,/root/
腳本輸出..
[email protected]:~/scripts$ ./checkForHeapdump.sh
Found a Heap dump! Possible OOM issue detected
Line file1.txt
file2.txt
好一個Barmar! – bobbyrne01