Bash · projectA greeting at the SSH login
This script greets you when you log in over SSH and shows the state of the NAS in one framed banner: model, uptime, cores and logical processors, load, the free space of each data volume and a tip of the day. It runs with QTS's own Bash 3.2, so it needs no extra package.
╔═ Hello ══════════════════════════════════════════════════════════════════╗ ║ ║ ║ ░▒▓█ Good morning, root █▓▒░ 2026-11-27 09:30 ║ ║ ║ ║ Model TBS-h574TX ║ ║ Up for 1 d 13 h 10 min ║ ║ CPU 10 cores, 12 logical processors ║ ║ Load 1.17 0.90 0.88 (1, 5 and 15 minutes) ║ ║ ║ ║ Free space on the data volumes ║ ║ CACHEDEV1_DATA ████░░░░░░░░░░░░░░░░ 1044.8 GiB free of 1327.1 GiB ║ ║ CACHEDEV2_DATA ██░░░░░░░░░░░░░░░░░░ 1054.6 GiB free of 1232.3 GiB ║ ║ ║ ║ Tip cat /proc/mdstat shows the state of every RAID group. ║ ║ ║ ╚══════════════════════════════════════════════════════════════════════════╝
SEED=7.Download it on the NAS
curl -fsSLO https://kb.nasutils.net/projects/bash/hello.shhello.sh Download hello.sh
#!/usr/bin/env bash
# hello.sh: a greeting for the SSH login. It prints a framed banner with a greeting for the time of day, the NAS
# model, its uptime and load, the free space of the data volumes and a tip of the day, then ends.
# Run it: bash hello.sh (NOW, SEED, PROC and DF may replace the clock, the tip's number, /proc and df -k)
# It uses nothing newer than Bash 3.2, the version of QTS's own /bin/sh.
set -uo pipefail
PROC=${PROC:-/proc}
NOW=${NOW:-$(date '+%Y-%m-%d %H:%M:%S')}
SEED=${SEED:-$(date '+%j')}
A=$'\e[38;5;214m' G=$'\e[32m' R=$'\e[31m' D=$'\e[2m' B=$'\e[1m' N=$'\e[0m'
W=76 # the width of the frame
edge() { # LEFT RIGHT TITLE: the top or the bottom edge
local line
if [[ -n $3 ]]; then
printf -v line '%*s' $((W - 5 - ${#3})) ''
line="═ $3 ${line// /═}"
else
printf -v line '%*s' $((W - 2)) ''
line=${line// /═}
fi
printf '%s%s%s%s%s\n' "$A" "$1" "$line" "$2" "$N"
}
row() { # TEXT: one line inside the frame; \e[NG puts the right edge at column W whatever the text holds
printf '%s║%s %s\e[%dG%s║%s\n' "$A" "$N" "$1" "$W" "$A" "$N"
}
bar() { # PERCENT WIDTH: green up to 69 %, amber up to 89 %, red from 90 %
local p=$1 w=$2 full colour=$G fill rest
((p >= 70)) && colour=$A
((p >= 90)) && colour=$R
full=$((p * w / 100))
printf -v fill '%*s' "$full" ''
printf -v rest '%*s' $((w - full)) ''
printf '%s%s%s%s%s' "$colour" "${fill// /█}" "$D" "${rest// /░}" "$N"
}
gib() { # KIB: the size in GiB with one decimal
local t=$((($1 * 10 + 524288) / 1048576))
printf '%d.%d' $((t / 10)) $((t % 10))
}
hour=$((10#${NOW:11:2}))
if ((hour >= 5 && hour < 12)); then
greeting="Good morning"
elif ((hour >= 12 && hour < 18)); then
greeting="Good afternoon"
elif ((hour >= 18 && hour < 22)); then
greeting="Good evening"
else
greeting="Working late"
fi
tips=(
"getsysinfo cputmp prints the temperature of the CPU."
"cat /proc/mdstat shows the state of every RAID group."
"getcfg System Version prints the version of QTS."
"ls /share lists the shared folders of the NAS."
"df -h shows the size and the free space of every volume."
"uptime prints how long the NAS has run and its load."
)
tip=${tips[$((10#$SEED % ${#tips[@]}))]}
model=$(getsysinfo model 2>/dev/null) || model=$(uname -n)
read -r up _ <"$PROC/uptime"
up=${up%.*}
read -r l1 l5 l15 _ <"$PROC/loadavg"
cpus=$(grep -c '^processor' "$PROC/cpuinfo")
cores=$(awk -F': ' '/^physical id/ {p = $2} /^core id/ {print p "-" $2}' "$PROC/cpuinfo" | sort -u | wc -l)
edge ╔ ╗ "Hello"
row ""
row "$A░▒▓█$N $B$greeting, ${USER:-$(id -un)}$N $A█▓▒░$N$(printf '\e[%dG' $((W - 19)))$D${NOW:0:16}$N"
row ""
row "$(printf '%-12s' Model)$B$model$N"
row "$(printf '%-12s' 'Up for')$((up / 86400)) d $((up % 86400 / 3600)) h $((up % 3600 / 60)) min"
row "$(printf '%-12s' CPU)$cores cores, $cpus logical processors"
row "$(printf '%-12s' Load)$l1 $l5 $l15 $D(1, 5 and 15 minutes)$N"
row ""
row "${B}Free space on the data volumes$N"
while read -r _ size used avail pct mnt; do
[[ $mnt == /share/* && $mnt != /share/*/* ]] || continue
row "$(printf '%-16s' "${mnt#/share/}")$(bar "${pct%\%}" 20) $G$(gib "$avail") GiB$N free of $(gib "$size") GiB"
done < <(if [[ -n ${DF:-} ]]; then cat "$DF"; else df -k; fi)
row ""
row "${A}Tip$N $tip"
row ""
edge ╚ ╝ ""
What you learn
\e[76Gmoves the cursor to column 76, so the right edge of the frame lines up whatever colours the line holds.${NOW:11:2}cuts the hour out of a date string, and10#reads "09" as nine, not as a wrong octal number.${tips[$((SEED % ${#tips[@]}))]}picks one entry of an array by a number, here the day of the year.[[ $mnt == /share/* && $mnt != /share/*/* ]]keeps the data volumes and skips folders mounted inside them.- Where QTS reads the login files, and why a line added to them is gone after a restart.
How it works
The script draws the banner from the top down. edge prints the top and the bottom edge, row one line between them. row prints the left edge, the text, then \e[76G and the right edge, so it never has to count the width of coloured text.
The greeting depends on the hour: morning from 5, afternoon from 12, evening from 18, and "Working late" from 22. The tip is one of six commands of QTS; its number is the day of the year, so you get a new tip each day. In the test, SEED=7 fixes it.
The facts come from the same places as in the menu: getsysinfo model, /proc/uptime, /proc/loadavg, /proc/cpuinfo and df -k. The script counts cores as the distinct pairs of physical id and core id, and logical processors as the processor lines. On a real NAS, df -k also lists folders that Container Station and Samba mount inside a volume, such as /share/CACHEDEV1_DATA/.samba/lock/msg.lock. The test of the mount point leaves only /share/CACHEDEV1_DATA and its kind.
Notes to the lines
- 5Arrays,
[[ ]],printf -vand$'\e'all work in Bash 3.2, so the script also runs as QTS's ownbash. - 9–10Without
NOWandSEEDthe script takes the clock and the day of the year (date '+%j'). - 14–24
edgemakes a line of═from spaces and writes the title into it when there is one. - 26–28
rowprints the text between the edges;\e[%dGjumps to columnWfor the right edge. - 45
10#makes Bash read the hour in base 10, so "08" and "09" do not stop the script. - 46–54The greeting by the hour.
- 64The remainder of the division by the number of tips is always a valid index of the array.
- 71
awkprints one pair ofphysical idandcore idper logical processor;sort -u | wc -lcounts the distinct pairs, the cores. - 83–86One row per data volume: name, bar of the used space, free space and size in GiB.
Run it
bash hello.shThe script prints the banner and ends.
To see it at every SSH login, copy hello.sh to a data volume, for example /share/homes/admin/hello.sh (that folder exists when Enable home folder for all users is on under Users, Home Folder). The admin account logs in over SSH with the home folder /root and QTS's /bin/sh, which is Bash 3.2. That shell reads /etc/profile and then /root/.profile. QTS keeps its root file system in RAM (df / shows none), so both files start fresh after every restart. A line you add to them is gone after a restart. TurboShell adds its own line again each time it starts for the same reason.
Add the line again after each restart:
echo '[ -f /share/homes/admin/hello.sh ] && bash /share/homes/admin/hello.sh' >> /root/.profileThe next SSH login shows the banner. QTS also has a boot hook: with Run user defined processes during startup on (Control Panel, Hardware, General), it runs autorun.sh from its configuration partition at every boot, and that script could add the line. Editing autorun.sh means mounting that partition by hand, so this page keeps to the line above.
Try it yourself
Add a row with the CPU temperature from getsysinfo cputmp. Add a seventh tip to the array and run the script with SEED=6 to see it.
More projects in Bash
- A framed menu in pure BashA Bash script draws a menu in a double frame, moves a highlighted bar with the arrow keys and opens boxes with the NAS's memory, volumes, uptime and load. You learn cursor moves, colours and key reading without any extra tool.
- A greeting at the SSH loginA Bash script greets you by the time of day and shows the NAS model, uptime, CPU, load, the free space of the data volumes and a tip of the day in one framed banner. You learn to frame text with escapes and how to show it at every SSH login on QTS.
- A live dashboard of the NASA Bash script redraws the CPU, load, temperatures, memory, data volumes and network rates of the NAS every 2 seconds until you press q. You learn to wait for a key with a timeout and to compute a rate from two readings of a counter.
- Blink: a memory game with drive-bay LEDsIn this Bash game the four drive-bay LEDs of a drawn NAS light up in a sequence that grows by one each round, and you repeat it with the keys 1 to 4. You learn timed drawing, seeded random numbers and how to ignore keys typed at the wrong moment.
- Copy a folder with a progress barA Bash script copies a folder block by block and shows a progress bar, the bytes copied, the speed and the time left, with an optional speed limit. You learn traps for Ctrl+C, redrawing lines in place and reading keys while a job runs.
- A backup wizard with dialogA Bash script uses dialog to show a checklist of the NAS's share folders, a confirmation, a progress gauge and a summary of what rsync would copy. You learn dialog's boxes, its colour file and how to feed a gauge from a loop.