I have written a script to check in var/log directory, and it takes all the directories in there and checks if there is an archive directory in those directories. If an archive directory not exist, I want to create it, but once it's created the script tries to create it again.
vdir=$(sudo sh -c "find /var/log/ -maxdepth 1 -type d ! -name "archive"" )
for i in $vdir ;do
echo $i
if [[ ! -d $i/$arc ]];then
sudo sh -c "mkdir $i/$arc"
echo "$date:$HN:Creating:$i/$arc:directory" >> logrotation.log
fi
done
When I execute above code it gives me this error. Seems the script is not checking the condition.
mkdir: cannot create directory ‘/var/log/speech-dispatcher/archive’: File exists