Difference between revisions of "Log rotation script example"
Jump to navigation
Jump to search
(Created page with "#!/bin/bash # Log Rotate # create a copy and clear the current log file cp -a /var/log/fail2ban.log /var/log/fail2ban.log.tmp && echo "" | tee /var/log/fail2ban.log # compre...") |
|||
Line 1: | Line 1: | ||
+ | |||
+ | ``` | ||
#!/bin/bash | #!/bin/bash | ||
# Log Rotate | # Log Rotate | ||
Line 10: | Line 12: | ||
# remove intermediate copy | # remove intermediate copy | ||
rm /var/log/fail2ban.log.tmp | rm /var/log/fail2ban.log.tmp | ||
+ | ``` |
Revision as of 22:41, 1 July 2021
```
- !/bin/bash
- Log Rotate
- create a copy and clear the current log file
cp -a /var/log/fail2ban.log /var/log/fail2ban.log.tmp && echo "" | tee /var/log/fail2ban.log
- compress the copy with datestamp in the title for log retention
tar cfj /var/log/fail2ban_log_$(date +"%Y%m%d").tar.bz2 /var/log/fail2ban.log.tmp
- remove intermediate copy
rm /var/log/fail2ban.log.tmp ```