我寫了一個 shellscript 如下,以檢查 samba 共享中的檔案:
date_gen=$(date --date="3 days ago" "%-Y%m%d")
fileName=${date_gen}"_Combined Reg Report.xlsx"
if [ ! -f smb://nfs/carboard/"${fileName}" -U ]
then
echo "File does not exist in Bash"
else
echo ${fileName}
fi
exit 1
有人可以幫助我這有什么問題嗎,我總是收到“Bash 中不存在檔案”。檔案夾中有檔案。
謝謝,藝術
uj5u.com熱心網友回復:
您應該檢查它是否已安裝,然后檢查檔案
if mount | grep -q /nfs/cardboard
then
if [[ ! -f /nfs/cardboard/"${fileName}" ]]
then
...
fi
else
echo "not mounted"
fi
uj5u.com熱心網友回復:
使用以下命令檢查檔案是否存在smbclient:
filename="$(date --date='3 days ago' ' %Y%m%d')_Combined Reg Report.xlsx"
if smbclient -A smbauth.conf '//nfs/carboard' -c "ls \"$filename\"" > /dev/null 2>&1
then
echo the file exists
else
echo the file is not there
fi
smbauth.conf以以下格式存盤憑據的檔案在哪里:
username=myuser
password=mypassword
domain=MYDOMAIN
我不知道轉義是如何作業的smbclient(似乎某些字符"無法轉義),但在您的情況下,雙引號就足夠了。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/380098.html
上一篇:EC2磁盤使用率無緣無故不斷增加
