I'm new to shell scripting and writing a script with multiple rm commands. the script has to remove files in some directories. I want to capture the exit status for each command and return the exit status if something fails and proceed with the next command. Can someone help me to correct my script.
#!/bin/bash
PATH1=mydir/folder/
PATH2=mydir/newfolder/
HOST= hostname | grep -o "[0-9]*" | head -1
case "$HOST" in
01)echo "Removing files in server 1.."
find $PATH1/logs -maxdepth 1 -mtime +30 -type f \( -name "*.log*" -o -name "*.out*" \) -exec rm -f {} \;
find $PATH1/logs -maxdepth 1 -mtime +30 -type f \( -name "*.log*" -o -name "*.out*" \) -exec rm -f {} \;
RETVAL=$?
;;
02)echo "Remove logfiles in server 02"
find $PATH2/logs -maxdepth 1 -mtime +30 -type f \( -name "*.log*" -o - name "*.out*" \) -exec rm -f {} \;
find $PATH2/logs -maxdepth 1 -mtime +30 -type f \( -name "*.log*" -o -name "*.out*" \) -exec rm -f {} \;
RETVAL=$?
;;
*)
echo "Removal of log files is complete"
esac