one-click-installation-script/resize_journal.sh
2022-12-17 23:13:12 +08:00

52 lines
1.8 KiB
Bash
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
head() {
# 支持系统Ubuntu 12+Debian 6+
ver="2022.12.17"
changeLog="一键修改journal日志记录大小释放系统盘空间"
clear
echo "#######################################################################"
echo "# ${YELLOW}一键修改journal大小脚本${PLAIN} #"
echo "# 版本:$ver #"
echo "# 更新日志:$changeLog #"
echo "# ${GREEN}作者${PLAIN}: spiritlhl #"
echo "# ${GREEN}作仓库${PLAIN}: https://github.com/spiritLHLS/one-click-installation-script #"
echo "#######################################################################"
echo "支持系统Ubuntu 12+Debian 6+"
echo "自定义修改大小单位为MB一般500M或者1G即可有的系统日志默认给了5G甚至更多不是做站啥的没必要"
# Display prompt asking whether to proceed with changing
read -p "Do you want to proceed with changing? [y/n] " -n 1 confirm
echo ""
# Check user's input and exit if they do not want to proceed
if [ "$confirm" != "y" ]; then
exit 0
fi
}
main() {
# Prompt the user for the desired size of the journal directory in MB
read -p "Enter the desired size of the journal directory in MB: " JOURNAL_SIZE_MB
# Convert the size from MB to bytes
JOURNAL_SIZE=$((JOURNAL_SIZE_MB * 1024 * 1024))
# Set the name of the log recording service
LOG_SERVICE="systemd-journald"
# Set the size of the journal directory
journalctl --disk-space=$JOURNAL_SIZE
# Restart the log recording service to force log rotation
systemctl restart $LOG_SERVICE
# Print the size of the journal directory
du -sh /var/log/journal
}
head
main