管理员在登录系统时显示如下信息
#!/bin/bash
#show sysinfo
# Function to get root disk usage
get_root_disk_usage() {
df -h | awk '$NF=="/"{print $5}'
}
# Get root disk usage
root_disk_used=$(get_root_disk_usage)
# Check if root disk usage is empty
if [ -z "$root_disk_used" ]; then
echo "Error: Failed to retrieve root disk usage."
exit 1
fi
# Get login count
login_count=$(who | wc -l)
# Get process count
process_count=$(($(ps -ef | wc -l) - 1))
# Output system information
echo "Root disk used info:"
echo "当前根分区已使用: $root_disk_used"
echo "当前登录系统的用户数量: $login_count"
echo "当前进程的数量: $process_count"