1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
|
#!/bin/sh
# Script Name: /etc/profile.d/ssh-login-info.sh
# Version: 1.0
# Author: PolloChang
# Date: 2025-10-07
# Description: ssh login banner
# Modified:
export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin
shopt -q login_shell && : || return 0
# os
upSeconds="$(cut -d. -f1 /proc/uptime)"
secs=$((${upSeconds}%60))
mins=$((${upSeconds}/60%60))
hours=$((${upSeconds}/3600%24))
days=$((${upSeconds}/86400))
UPTIME_INFO=$(printf "%d days, %02dh %02dm %02ds" "$days" "$hours" "$mins" "$secs")
if [ -f /etc/oracle-release ] ; then
PRETTY_NAME=$(< /etc/oracle-release)
elif [ -f /etc/redhat-release ] ; then
PRETTY_NAME=$(< /etc/redhat-release)
elif [ -f /etc/debian_version ]; then
DIST_VER=$(</etc/debian_version)
PRETTY_NAME="$(grep PRETTY_NAME /etc/os-release | sed -e 's/PRETTY_NAME=//g' -e 's/"//g') ($DIST_VER)"
else
PRETTY_NAME=$(cat /etc/*-release | grep "PRETTY_NAME" | sed -e 's/PRETTY_NAME=//g' -e 's/"//g')
fi
if [[ -d "/system/app/" && -d "/system/priv-app" ]]; then
model="$(getprop ro.product.brand) $(getprop ro.product.model)"
elif [[ -f /sys/devices/virtual/dmi/id/product_name ||
-f /sys/devices/virtual/dmi/id/product_version ]]; then
model="$(< /sys/devices/virtual/dmi/id/product_name)"
model+=" $(< /sys/devices/virtual/dmi/id/product_version)"
elif [[ -f /sys/firmware/devicetree/base/model ]]; then
model="$(< /sys/firmware/devicetree/base/model)"
elif [[ -f /tmp/sysinfo/model ]]; then
model="$(< /tmp/sysinfo/model)"
fi
MODEL_INFO=${model}
KERNEL=$(uname -srmo)
USER_NUM=$(who -u | wc -l)
RUNNING=$(ps ax | wc -l | tr -d " ")
# disk
totaldisk=$(df -h -x devtmpfs -x tmpfs -x debugfs -x aufs -x overlay --total 2>/dev/null | tail -1)
disktotal=$(awk '{print $2}' <<< "${totaldisk}")
diskused=$(awk '{print $3}' <<< "${totaldisk}")
diskusedper=$(awk '{print $5}' <<< "${totaldisk}")
DISK_INFO="\033[0;33m${diskused}\033[0m of \033[1;34m${disktotal}\033[0m disk space used (\033[0;33m${diskusedper}\033[0m)"
# cpu
cpu=$(awk -F':' '/^model name/ {print $2}' /proc/cpuinfo | uniq | sed -e 's/^[ \t]*//')
cpun=$(grep -c '^processor' /proc/cpuinfo)
cpuc=$(grep '^cpu cores' /proc/cpuinfo | tail -1 | awk '{print $4}')
cpup=$(grep '^physical id' /proc/cpuinfo | wc -l)
CPU_INFO="${cpu} ${cpup}P ${cpuc}C ${cpun}L"
# get the load averages
read one five fifteen rest < /proc/loadavg
LOADAVG_INFO="\033[0;33m${one}\033[0m / ${five} / ${fifteen} with \033[1;34m$(( cpun*cpuc ))\033[0m core(s) at \033[1;34m$(grep '^cpu MHz' /proc/cpuinfo | tail -1 | awk '{print $4}')\033 MHz"
# mem
MEM_INFO="$(cat /proc/meminfo | awk '/MemTotal:/{total=$2/1024/1024;next} /MemAvailable:/{use=total-$2/1024/1024; printf("\033[0;33m%.2fGiB\033[0m of \033[1;34m%.2fGiB\033[0m RAM used (\033[0;33m%.2f%%\033[0m)",use,total,(use/total)*100);}')"
# network
# extranet_ip=" and $(curl -s ip.cip.cc)"
IP_INFO="$(ip a | grep glo | awk '{print $2}' | head -1 | cut -f1 -d/)${extranet_ip:-}"
# user login
user=$(whoami)
path=$(pwd)
home=$HOME
# * Calculate last login
LASTLOGS=$(last -i -d -n 4 -w 2>/dev/null) # 減少 -n 參數,只需要取得前 4 筆
LASTLOG1=$(echo "${LASTLOGS}" | head -1)
LASTLOG2=$(echo "${LASTLOGS}" | head -2 | tail -1)
LASTLOG3=$(echo "${LASTLOGS}" | head -3 | tail -1)
LASTLOG4=$(echo "${LASTLOGS}" | head -4 | tail -1)
# info
echo -e "
Information as of: \033[1;34m$(date +"%Y-%m-%d %T")\033[0m
\033[0;1;31mProduct\033[0m............: ${MODEL_INFO}
\033[0;1;31mOS\033[0m.................: ${PRETTY_NAME}
\033[0;1;31mKernel\033[0m.............: ${KERNEL}
\033[0;1;31mCPU\033[0m................: ${CPU_INFO}
\033[0;1;31mHostname\033[0m...........: \033[1;34m$(hostname)\033[0m
\033[0;1;31mIP Addresses\033[0m.......: \033[1;34m${IP_INFO}\033[0m
\033[0;1;31mUptime\033[0m.............: \033[0;33m${UPTIME_INFO}\033[0m
\033[0;1;31mMemory\033[0m.............: ${MEM_INFO}
\033[0;1;31mLoad Averages\033[0m......: ${LOADAVG_INFO}
\033[0;1;31mDisk Usage\033[0m.........: ${DISK_INFO}
\033[0;1;31mUsers online\033[0m.......: \033[1;34m${USER_NUM}\033[0m
\033[0;1;31mRunning Processes\033[0m..: \033[1;34m${RUNNING}\033[0m
\033[0;1;31mlastlog1\033[0m...........: ${LASTLOG1}
\033[0;1;31mlastlog2\033[0m...........: ${LASTLOG2}
\033[0;1;31mlastlog3\033[0m...........: ${LASTLOG3}
\033[0;1;31mlastlog4\033[0m...........: ${LASTLOG4}
\033[0;1;31mlogincount\033[0m.........: $( users | wc -w)
"
|