chatgpt Linux scheduled task to clean up the log file script of rancher pod startup service

Linux scheduled task execution command

Suppose we want to execute a script file every X minutes, every X days, and every X o'clock every day, we can use the cron tool that comes with Linux to create a scheduled task

cleaning steps

You can use the cron tool that comes with Linux to create a scheduled task, and write a shell script to periodically clean up the log files of the Rancher startup service. Here is an example of a simple shell script that periodically cleans the log files of a Docker container on a weekly basis:

#!/bin/bash
# 清理 Docker 容器日志文件
sudo truncate -s 0 /var/lib/docker/containers/*/*-json.log

You can save the script above as a file such as clean_logs.sh and place it in a directory of your choice such as /opt/scripts/. Then you need to make the script executable so you can call it in cron. You can make a script executable with the following command:

chmod +x /opt/scripts/clean_logs.sh

Next, you need to add the script to a cron job using the crontab command. Open a terminal and edit the cron table with the following command:

crontab -e

Then, add the following line in the open editor to clean up the log file every Sunday at 2am:

0 2 * * 0 /opt/scripts/clean_logs.sh

This will run the /opt/scripts/clean_logs.sh script every Sunday at 2am to clean the log files of the Docker container. After saving and exiting the editor, cron will automatically run the script at the specified time. You can change the cron job schedule by editing the cron table, or use the crontab -r command to delete the added cron job.

chatgpt's answer

insert image description here

var code = “4a756eae-046f-48e3-a391-767eee3af306”
var code = “2716a93d-c46e-4179-bb3f-bb00371ccb43”

Guess you like

Origin blog.csdn.net/A_yonga/article/details/129119123