gpt-3.5-turbo-0125· OpenAI
WildChat-4.8M (AI2)
Write a shell script that rotates log files daily. The script should keep a maximum of…
- User
Write a shell script that rotates log files daily. The script should keep a maximum of seven days' worth of logs and compress the older logs.
- Assistant
Here is an example shell script that rotates log files daily:
#!/bin/bash log_dir="/var/log/myapp" log_file="myapp.log" # Create log directory if it does not exist if [ ! -d "$log_dir" ]; then mkdir -p "$log_dir" fi # Rotate log files if [ -f "$log_dir/$log_file" ]; then mv "$log_dir/$log_file" "$log_dir/$log_file.$(date +"%Y-%m-%d")" fi # Compress older log files find "$log_dir" -name "$log_file.*" -mtime +7 -exec gzip {} \;You can save this script to a file (e.g.,
rotate_logs.sh) and make it executable using the following command:chmod +x rotate_logs.shYou can then set up a cron job to execute this script daily by adding the following line to your crontab:
0 0 * * * /path/to/rotate_logs.shThis cron job will run the
rotate_logs.shscript at midnight every day, rotating the log files and compressing older logs as needed.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.