即使 .csv 文件中有 2 个条目(行),为什么这个 while 循环只执行一次?
当没有文件/目录与表达式匹配时,字符串'ls:/root/ heapdump:没有这样的文件或目录'怎么会输出到控制台?
#!/bin/bash
INPUT=targets.csv
[ ! -f $INPUT ] && { echo "$INPUT file not found"; exit 99; }
while IFS=, read target user password path
do
result=$(sshpass -p "$password" ssh "$user"@"$target" ls "$path"*heapdump*)
if [ $? -ne 0 ]
then
echo "No Heap dumps detected."
else
echo "Found a Heap dump! Possible OOM issue detected"
fi
done < $INPUT
.csv 内容..
rob@laptop:~/scripts$ cat targets.csv
server.com,root,passw0rd,/root/
server.com,root,passw0rd,/root/
输出 ..
rob@laptop:~/scripts$ ./checkForHeapdump.sh
ls: /root/*heapdump*: No such file or directory
No Heap dumps detected.