Bash Script To Rotate A Log file To A Time Stamped File – Linux

A bash script that rotates a file (logfile.txt) to a timestamped
file(logfile_20180719.txt), which could be invoked by cron every 24 hours.

Move the created bash file to newly created scripts folder.

mv /home/hass/ /var/scripts/
Change permission to allow +x (execute permissions)

I used the below site to generate the time for the cron job

Add the location of the script file to the crontab
Sudo crontab -e

Cron Job Generated (you may copy & paste it to your crontab):
1 1 * * * test >/dev/null 2>&1
Your cron job will be run at: (5 times displayed)
2019-11-19 01:01:00 UTC
2019-11-20 01:01:00 UTC
2019-11-21 01:01:00 UTC
2019-11-22 01:01:00 UTC
2019-11-23 01:01:00 UTC

Leave a Reply

Your email address will not be published. Required fields are marked *