確保該目錄存在,並且用戶具有足夠的權限。檢查過程退出狀態($?
變量)。將錯誤記錄到可靠寫入的地方。
dir="$HOME/public_html/database/"
db_file="${dir}/${Student_ID}.student"
error_log=/tmp/cgi-error.log
# If $dir doesn't exist
if [ ! -e "$dir" ]; then
# Create $dir path
mkdir -p $dir
if [ $? -gt 0 ]; then
echo "Failed to mkdir $dir" >>"$error_log"
exit 1
fi
chmod +wx $(dirname $dir) $dir
if [ $? -gt 0 ]; then
echo "Failed to set permissions for $dir" >>"$error_log"
exit 1
fi
fi
if [ ! -w "$db_file" ]; then
echo "$db_file is not writable!" >>"$error_log"
exit 1
fi
echo "Student_ID=${Student_ID}" 2>>"$error_log" >> "${db_file}"
if [ $? -gt 0 ]; then
echo "Failed to log $Student_ID to $db_file" >>"$error_log"
exit 1
fi
此外,請避免0777
權限。至少,除非/tmp
-like目錄的sticky bit設置爲:1777
,否則對於「其他」不需要w
權限。
該特定文件的權限是什麼? – Jahid
我試過在創建它時在本地創建文件0777,然後使用mv嘗試將其移動到數據庫目錄。雖然沒有運氣。 –
什麼是SO和版本? SELinux啓用? –