Update disk-check.sh
This commit is contained in:
parent
6c48e599fc
commit
2c7b0fd090
|
@ -4,22 +4,20 @@
|
|||
OS=$(uname)
|
||||
OUTPUT_FILE="/tmp/disk_report.txt"
|
||||
echo "Starting disk space report... This may take a few minutes." > $OUTPUT_FILE
|
||||
start_time=$(date)
|
||||
|
||||
# Output start time
|
||||
echo "Report started at: $start_time" >> $OUTPUT_FILE
|
||||
|
||||
# Function to estimate the size of the package cache
|
||||
estimate_package_cache_size() {
|
||||
echo "Estimating the size of the package cache:" >> $OUTPUT_FILE
|
||||
if [[ $OS == "Linux" ]]; then
|
||||
if [[ -d /var/cache/apt ]]; then
|
||||
if [[ $OS == "Linux" && -d /var/cache/apt ]]; then
|
||||
sudo du -sh /var/cache/apt 2>>$OUTPUT_FILE >> $OUTPUT_FILE || echo "Error estimating apt cache size." >> $OUTPUT_FILE
|
||||
else
|
||||
echo "/var/cache/apt directory not found." >> $OUTPUT_FILE
|
||||
fi
|
||||
elif [[ $OS == "FreeBSD" ]]; then
|
||||
if [[ -d /var/cache/pkg ]]; then
|
||||
elif [[ $OS == "FreeBSD" && -d /var/cache/pkg ]]; then
|
||||
sudo du -sh /var/cache/pkg 2>>$OUTPUT_FILE >> $OUTPUT_FILE || echo "Error estimating pkg cache size." >> $OUTPUT_FILE
|
||||
else
|
||||
echo "/var/cache/pkg directory not found." >> $OUTPUT_FILE
|
||||
fi
|
||||
echo "Package cache directory not found for $OS." >> $OUTPUT_FILE
|
||||
fi
|
||||
echo >> $OUTPUT_FILE
|
||||
}
|
||||
|
@ -27,18 +25,12 @@ estimate_package_cache_size() {
|
|||
# Function to estimate the size of old package files
|
||||
estimate_old_packages_size() {
|
||||
echo "Estimating the size of old package files:" >> $OUTPUT_FILE
|
||||
if [[ $OS == "Linux" ]]; then
|
||||
if [[ -d /var/lib/apt/lists ]]; then
|
||||
if [[ $OS == "Linux" && -d /var/lib/apt/lists ]]; then
|
||||
sudo du -sh /var/lib/apt/lists /var/lib/apt/lists/partial 2>>$OUTPUT_FILE >> $OUTPUT_FILE || echo "Error estimating old packages size." >> $OUTPUT_FILE
|
||||
else
|
||||
echo "/var/lib/apt/lists directory not found." >> $OUTPUT_FILE
|
||||
fi
|
||||
elif [[ $OS == "FreeBSD" ]]; then
|
||||
if [[ -d /var/db/pkg ]]; then
|
||||
elif [[ $OS == "FreeBSD" && -d /var/db/pkg ]]; then
|
||||
sudo du -sh /var/db/pkg 2>>$OUTPUT_FILE >> $OUTPUT_FILE || echo "Error estimating old packages size." >> $OUTPUT_FILE
|
||||
else
|
||||
echo "/var/db/pkg directory not found." >> $OUTPUT_FILE
|
||||
fi
|
||||
echo "Old package directory not found for $OS." >> $OUTPUT_FILE
|
||||
fi
|
||||
echo >> $OUTPUT_FILE
|
||||
}
|
||||
|
@ -46,18 +38,12 @@ estimate_old_packages_size() {
|
|||
# Function to estimate the size of system logs
|
||||
estimate_log_size() {
|
||||
echo "Estimating the size of system logs:" >> $OUTPUT_FILE
|
||||
if [[ $OS == "Linux" ]]; then
|
||||
if command -v journalctl &>/dev/null; then
|
||||
if [[ $OS == "Linux" && $(command -v journalctl) ]]; then
|
||||
sudo journalctl --disk-usage 2>>$OUTPUT_FILE >> $OUTPUT_FILE || echo "Error estimating journal log size." >> $OUTPUT_FILE
|
||||
else
|
||||
echo "journalctl command not found on Linux." >> $OUTPUT_FILE
|
||||
fi
|
||||
elif [[ $OS == "FreeBSD" ]]; then
|
||||
if [[ -d /var/log ]]; then
|
||||
elif [[ $OS == "FreeBSD" && -d /var/log ]]; then
|
||||
sudo du -sh /var/log 2>>$OUTPUT_FILE >> $OUTPUT_FILE || echo "Error estimating log size in /var/log." >> $OUTPUT_FILE
|
||||
else
|
||||
echo "/var/log directory not found." >> $OUTPUT_FILE
|
||||
fi
|
||||
echo "Log directory not found for $OS." >> $OUTPUT_FILE
|
||||
fi
|
||||
echo >> $OUTPUT_FILE
|
||||
}
|
||||
|
@ -80,6 +66,7 @@ list_large_directories() {
|
|||
if [[ -d $directory ]]; then
|
||||
sudo du -ah $directory 2>/dev/null | sort -hr > /tmp/du_output.txt || echo "Error scanning directories in $directory." >> $OUTPUT_FILE
|
||||
cat /tmp/du_output.txt >> $OUTPUT_FILE
|
||||
sleep 2 # Added delay to ensure command has sufficient runtime
|
||||
else
|
||||
echo "$directory directory not found." >> $OUTPUT_FILE
|
||||
fi
|
||||
|
@ -106,7 +93,7 @@ categorize_large_directories() {
|
|||
echo >> $OUTPUT_FILE
|
||||
}
|
||||
|
||||
# Main function calls
|
||||
# Main function calls with timestamps
|
||||
echo "Estimating potential storage savings..." >> $OUTPUT_FILE
|
||||
estimate_package_cache_size
|
||||
estimate_old_packages_size
|
||||
|
@ -127,7 +114,10 @@ if [[ -d "/home/virtfs" ]]; then
|
|||
categorize_large_directories
|
||||
fi
|
||||
|
||||
# Output end time
|
||||
end_time=$(date)
|
||||
echo "Storage savings estimation and large directory listing completed." >> $OUTPUT_FILE
|
||||
echo "Report completed at: $end_time" >> $OUTPUT_FILE
|
||||
|
||||
# Upload the report to hastebin
|
||||
response=$(curl -s -X POST -T $OUTPUT_FILE https://haste.nixc.us/documents)
|
||||
|
|
Loading…
Reference in New Issue