I've got a script that I run continually to monitor vsftpd logs. Here is a small example:
#!/bin/sh tail -n0 -F /var/log/vsftpd.log | while read line; do if echo "$line" | grep -q 'OK UPLOAD:'; then username=$(echo "$line" | cut -d" " -f9 | sed 's/\[\(.*\)\]/\1/') if [ $? -ne 0 ]; then echo "ERROR: Failure to get parse username. Line it is trying to parse: $line" >>/var/log/ftpmonitor.log # We need to remove the file with any error so it doesn't linger rm -rf $home$filenamewithpath if [ $? -ne 0 ]; then echo "ERROR: Failed to delete video file" >>/var/log/ftpmonitor.log exit 1 fi exit 1 fi # lot of other stuff here... fi done
I want to catch any errors I can with any command failure and stop. Originally I thought I'd use exit to stop. Normally that makes sense but in this case this script needs to keeping running all the time monitoring the vsftpd logs. So I don't want to exit the script I want to just stop any other commands after that failure. How can I achieve this?