Replacing part of a filename using bash scripting

My brother has a dovecot mail server that every now and again the cache would corrupt on it. He would just go in, check the logs and rename the file affected. He just asked if I could script the process. So this little script will search through a log, extract the filename, alter its name and move the file to the new location:



grep "Error: Maildir filename has wrong W value:" $QFILE | while read line
fileNo=$(echo "$line" | awk '{split($0,a,","); for (idx in a) { split(a[idx], b, "="); if (b[1] == "W") print b[2]; }}')
fileName=$(echo "$line" | awk '{split($0,a," /"); print a[2]}')
echo "/$fileName"
echo "$fileNo"
echo "/$fileNameFixed"
mv /$fileName /$fileNameFixed


Popular posts from this blog

Windows Server and the Task Scheduler Error Code 0x3

IPv6 Ready!

The living wage failure