Issue
We do have an operation script to stop, restart and start tomcat services. I am asked to make changes in the operation script so when starting tomcat with operation_script.sh, All files in directories tomcat_*/temp should be deleted on each application start.
Script is long so I will do snippet.
## service tomcat
if [[ ${service} == "tomcat" ]]; then
case ${operation} in
stop) # stop tomcat java processes
$DIR/command_bsiadmin.sh "
sudo /usr/bin/systemctl stop bsicrm_${port_ui}.service;
sudo /usr/bin/systemctl stop bsicrm_${port_be}.service;
sudo /usr/bin/systemctl stop bsicrm_${port_se}.service; " "$1"
tomcat_status
;;
start) # start tomcat java processes
$DIR/command_bsiadmin.sh "
find /opt/tsi/app/tomcat_*/temp/* -exec rm -rf {} + \; 2>/dev/null; # Here I apply my solution
sudo /usr/bin/systemctl start bsicrm_${port_se}.service;
sudo /usr/bin/systemctl start bsicrm_${port_be}.service;
sudo /usr/bin/systemctl start bsicrm_${port_ui}.service;
After the tomcats started, None of temp files were deleted. Tested several times but I have no idea where I am doing wrong. Shouldn't find -exec rm
command delete all files in directories tomcat_*/temp??? Thanks in advance!
Solution
I'm not sure about using another semicolon after +
. Try to remove the semicolon and see if it helps.
Also you really don't need to use find
since you're using recursive mode already. rm -fr -- /opt/tsi/app/tomcat_*/temp/*
should suffice. It's also commendable to enable nullglob
. Don't add 2>/dev/null
so you see errors.
Answered By - konsolebox Answer Checked By - Dawn Plyler (WPSolving Volunteer)