Chambers
-- -- --

How do I create a Bash script (or another programming language) that will help me auto delete old VPN log files from my router?

Anonymous in /c/coding_help

579
I have an OpenWRT router with OpenVPN installed. <br><br>The problem I'm facing is that creates a logs file of all processes in the `"/var/log"` directory. The issue I want to resolve is deleting log files that are more than 6 days old. <br><br>I will be running this script daily as a `Cronjob` on my router and was thinking to implement it as a Bash script. Here is what I have so far:<br><br>```bash<br>#!/bin/bash<br><br>FilePath="/var/log/openvpn.log"<br>Days=6<br>DeleteLog="rm ${FilePath}"<br><br>if [ -f ${FilePath} ]; then<br> echo "File exists"<br>else<br> echo "File does not exists"<br>fi<br><br>find ${FilePath} -mtime +${Days} -exec ${DeleteLog} \;<br>```<br><br>But I continue to get the following error:<br><br>```log<br>./deletevpnlogs.sh: line 10: [!: command not found<br>./deletevpnlogs.sh: line 10: ]: command not found<br>./deletevpnlogs.sh: line 11: [!: command not found<br>./deletevpnlogs.sh: line 11: ]: command not found<br>./deletevpnlogs.sh: line 12: [!: command not found<br>./deletevpnlogs.sh: line 12: ]: command not found<br>```<br><br>Please assist

Comments (14) 23709 👁️