I have bash shell and put the script in a file. It executes fine when I run it without sudo. When I run it as super user, it gives me error
[root@gums01 rotate_logs]# sudo ./rotate_logs.sh
./rotate_logs.sh: line 47: syntax error near unexpected token `<'
./rotate_logs.sh: line 47: `done < <(find $LOGS_PATH/ -maxdepth 1 -mtime +$FILES_OLDER_THAN_DAYS -type f \( -name "gums-app.log_*.log" \) -print0)'
Here is the partial content of the shell script. I have tried many articles but not able to understand why this error pops up when running as super user. Please ignore the variables you see in below. Those are already defined in same file.
FILES_OLDER_THAN_DAYS=30
files=()
while IFS= read -r -d $'\0'; do
files+=("$REPLY")
done < <(find $LOGS_PATH/ -maxdepth 1 -mtime +$FILES_OLDER_THAN_DAYS -type f \( -name "gums-app.log_*.log" \) -print0)
name=$(date --date="-$FILES_OLDER_THAN_DAYS day" '+%Y-%m-%d_%H:%M:%S')
if (( ${#files[@]} )); then
echo "[Time: $(date)] Making tar of GUMS log files older than $FILES_OLDER_THAN_DAYS days." >> $SCRIPT_LOG
tar cfz "$LOGS_PATH/zippedLogs/backup_$name.tar.gz" "${files[@]}";
echo "[Time: $(date)] Removing GUMS log files older than $FILES_OLDER_THAN_DAYS days from local" >> $SCRIPT_LOG
find $LOGS_PATH/ -maxdepth 1 -mtime +$FILES_OLDER_THAN_DAYS -type f \( -name "*gums-app.log_*.log" \) -exec rm -f {} \;
set_month_folder_id $LOG_GDRIVE_FOLDER_ID
echo $target_folder_id >> $SCRIPT_LOG
echo "[Time: $(date)] Uploading tar of log file to Google Drive" >> $SCRIPT_LOG
$MY_PATH/gdrive upload $LOGS_PATH/zippedLogs/backup_$name.tar.gz -p $target_folder_id >> $SCRIPT_LOG
echo "[Time: $(date)] Removing local tar file" >> $SCRIPT_LOG
rm -rf $LOGS_PATH/zippedLogs/*;
else
echo "[Time: $(date)] No GUMS log found older than $FILES_OLDER_THAN_DAYS days" >> $SCRIPT_LOG
fi