Hello I keep my log files under /opt/project/logs/ and I want to daily copy these to /opt/bkp by compressing them.
For this I have written this and works well:
#!/bin/bash
getdate(){
date --date="$1 days ago" "+%Y_%m_%d"
}
rm -rf "/opt/bkp/logs/myapp_log_"$(getdate 365).gz ;
/bin/cat /opt/project/logs/myapp.log | gzip > /opt/bkp/logs/myapp_log_`date +%Y_%m_%d`.gz ;
echo "" > /opt/project/logs/myapp.log ;
However it is not functional or general, I will have several applications saving files with their names ie app1.log app2.log under the same /opt/project/logs/ folder. How can I make this as a "function" where script reads each file under /opt/project/logs/ directory and taking backup of each file ends with .log extension?