I have a script that I am using to clear out all lines of a log files older than X days. X can be passed in via command line as well as the log file name, ex usage:
./purge-catalina.sh 3 /opt/tomcat8/logs/catalina.out
The script itself looks like this:
date_pattern=$(date -d "-$1 day" '+%Y-%m-%d') catalina_file="$2" echo "Purging all logs older than $date_pattern" #grep -v "$pattern" $2 > catalina.out.temp; mv catalina.out.temp $2 awk -v d="$date_pattern" '($1 " " $2) > d' $catalina_file
When I pass in variables to the script and then run the awk command like above, the awk portion seems to not grab the correct lines. However, if I don't pass in any variables to the script and hardcode the variables to be:
date_pattern=$(date -d "-3 day" '+%Y-%m-%d') catalina_file="logfile.log"
It works fine. How can I pass in variables to the script and also use $1 and $2 in the awk script?