NASutils Knowledge BaseUnofficialPolski

BASIC · projectA greeting screen in yabasic

This program prints a greeting when you log in: a framed banner with "Good morning" and the NAS model, the date, then uptime, load, the free space of each data volume and one tip of the day. It prints once and ends, so it fits at the end of a login.

Programming on the NAS › BASIC in 30 lessons

  ╔══════════════════════════════════════════════════════════════╗
  ║                                                              ║
  ║   Good morning. Welcome to TBS-h574TX.                       ║
  ║   Friday, 27 November 2026, 09:30                            ║
  ║                                                              ║
  ╚══════════════════════════════════════════════════════════════╝

   Up for      1 d 13 h 10 min
   Load        1.17  0.90  0.88   (1, 5 and 15 minutes)

   Free space  CACHEDEV1_DATA  1.02 TiB  of 1.30 TiB  ███░░░░░░░░░
               CACHEDEV2_DATA  1.03 TiB  of 1.20 TiB  ██░░░░░░░░░░

   Tip  cat /proc/mdstat shows the state of each RAID group.
The greeting at 09:30 on Friday, 27 November 2026: "Good morning", the model TBS-h574TX, uptime, load, two data volumes with about 1 TiB free each, and the tip for SEED=7.

Download it on the NAS

curl -fsSLO https://kb.nasutils.net/projects/basic/hello.yab

hello.yab Download hello.yab

rem Hello screen: a framed greeting with the NAS's model, uptime, load, free space and a tip.
rem Run: yabasic hello.yab   (add it to your login, it prints once and ends)
rem No clear screen here: plain print passes UTF-8 frames and colour codes straight to the terminal.

proc$ = peek$("env", "PROC") : if proc$ = "" proc$ = "/proc"
now$ = peek$("env", "NOW")
if now$ = "" then
  dim d$(6) : n = token(date$, d$(), "-") : t$ = time$
  now$ = d$(4) + "-" + right$("0" + d$(2), 2) + "-" + right$("0" + d$(3), 2) + " " + left$(t$, 2) + ":" + mid$(t$, 4, 2)
endif
year = val(left$(now$, 4)) : month = val(mid$(now$, 6, 2)) : day = val(mid$(now$, 9, 2)) : hour = val(mid$(now$, 12, 2))

greet$ = "Good evening"
if hour >= 5 and hour < 12 greet$ = "Good morning"
if hour >= 12 and hour < 18 greet$ = "Good afternoon"
model$ = system$("getsysinfo model 2>/dev/null")
if model$ = "" model$ = "your NAS"
dim wday$(7), mon$(12)
n = token("Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday", wday$(), ",")
n = token("January,February,March,April,May,June,July,August,September,October,November,December", mon$(), ",")
when$ = wday$(weekday(year, month, day) + 1) + ", " + str$(day) + " " + mon$(month) + " " + str$(year) + ", " + mid$(now$, 12, 5)

print
print "  " + e$("33") + "╔" + rep$("═", 62) + "╗"
print "  ║" + rep$(" ", 62) + "║"
print "  ║   " + e$("1;33") + pad$(greet$ + ". Welcome to " + model$ + ".", 59) + e$("0;33") + "║"
print "  ║   " + e$("0") + pad$(when$, 59) + e$("33") + "║"
print "  ║" + rep$(" ", 62) + "║"
print "  ╚" + rep$("═", 62) + "╝" + e$("0")
print

open #1, proc$ + "/uptime", "r" : line input #1 a$ : close #1
up = val(a$)
print "   " + e$("33") + pad$("Up for", 12) + e$("0") + str$(int(up / 86400)) + " d " + str$(mod(int(up / 3600), 24)) + " h " + str$(mod(int(up / 60), 60)) + " min"
open #1, proc$ + "/loadavg", "r" : line input #1 a$ : close #1
dim w$(5) : n = token(a$, w$(), " ")
print "   " + e$("33") + pad$("Load", 12) + e$("0") + w$(1) + "  " + w$(2) + "  " + w$(3) + "   (1, 5 and 15 minutes)"
print

a$ = peek$("env", "DF")
if a$ = "" then a$ = system$("df -kP 2>/dev/null") else a$ = system$("cat '" + a$ + "'") : endif
dim line$(1), f$(6)
label$ = "Free space"
for i = 2 to token(a$, line$(), chr$(10))
  if token(line$(i), f$(), " ") = 6 and left$(f$(6), 15) = "/share/CACHEDEV" then
    free = val(f$(4)) / val(f$(2))
    used = int((1 - free) * 12 + 0.5)
    c$ = "32" : if free < 0.2 c$ = "31"
    print "   " + e$("33") + pad$(label$, 12) + e$("0") + pad$(mid$(f$(6), 8), 16) + e$(c$) + pad$(tib$(val(f$(4))), 10) + e$("0") + pad$("of " + tib$(val(f$(2))), 13) + e$("33") + rep$("█", used) + e$("0") + rep$("░", 12 - used)
    label$ = ""
  endif
next i
print

dim tip$(8)
tip$(1) = "df -h shows the size and free space of every volume."
tip$(2) = "cat /proc/mdstat shows the state of each RAID group."
tip$(3) = "getsysinfo cputmp prints the temperature of the CPU."
tip$(4) = "free -m shows the memory in megabytes."
tip$(5) = "top lists the busiest processes; q quits it."
tip$(6) = "dmesg | tail shows the newest messages of the kernel."
tip$(7) = "ls -l /share lists the shared folders and their volumes."
tip$(8) = "uptime prints the time since the start and the load."
seed = val(peek$("env", "SEED"))
if seed = 0 seed = val(mid$(time$, 4, 2)) * 60 + val(mid$(time$, 7, 2)) + 1
seed = mod(seed * 16807, 2147483647)
print "   " + e$("1;33") + "Tip  " + e$("0") + tip$(mod(seed, 8) + 1)
print

rem Day of the week, 0 = Sunday (Sakamoto's method)
sub weekday(y, m, d)
  local t$
  t$ = "032503514624"
  if m < 3 y = y - 1
  return mod(y + int(y / 4) - int(y / 100) + int(y / 400) + val(mid$(t$, m, 1)) + d, 7)
end sub

sub tib$(kb)
  if kb >= 1024 * 1024 * 1024 return str$(kb / 1024 / 1024 / 1024, "%.2f") + " TiB"
  return str$(kb / 1024 / 1024, "%.1f") + " GiB"
end sub

sub width(s$)
  local i, n, c
  for i = 1 to len(s$)
    c = asc(mid$(s$, i, 1))
    if c < 128 or c >= 192 n = n + 1
  next i
  return n
end sub

sub pad$(s$, n) : return s$ + rep$(" ", n - width(s$)) : end sub
sub rep$(s$, n) : local r$, i : for i = 1 to n : r$ = r$ + s$ : next i : return r$ : end sub
sub e$(code$) : return chr$(27) + "[" + code$ + "m" : end sub

What you learn

  • Plain print passes UTF-8 frames and colour codes straight to the terminal when the program never calls clear screen.
  • mid$(now$, 12, 2) cuts the hour out of "2026-11-27 09:30:00", and val() turns it into a number.
  • token(date$, d$(), "-") splits yabasic's own date into its parts.
  • Sakamoto's method finds the day of the week from the year, month and day in four lines.
  • seed = mod(seed * 16807, 2147483647) makes the next number of a random row; the same seed always gives the same tip.

How it works

The program first settles the time. With NOW set it takes that text; without it, it builds the same form from yabasic's date$ and time$. The hour picks the greeting: morning from 5, afternoon from 12, evening from 18. getsysinfo model names the NAS; on a PC that command is missing and the banner says "your NAS".

The banner is six print lines: the top edge, an empty line, the greeting, the date, an empty line and the bottom edge. pad$ fills each text to 59 letters, so the right edge stands in one column.

Below the banner come uptime and load from /proc, then one line for each data volume of df -kP: its free space in green (red below 20 % free), its size and a bar of the used part. Last comes a tip. The program turns SEED into a number from 0 to 7 with the Park and Miller formula and prints that tip.

Notes to the lines

  • 6–10Without NOW, date$ gives "5-11-27-2026-Fri-Nov" and time$ "09-30-00-0"; the program puts year, month, day and time in the order of NOW.
  • 11One line cuts year, month, day and hour out of the text.
  • 13–15Evening is the default; two if lines change it to morning or afternoon.
  • 16–172>/dev/null hides the error on a PC without getsysinfo, and the empty answer gives "your NAS".
  • 21weekday() returns 0 for Sunday, so the array of names starts at Sunday and the index gets 1 added.
  • 24–29The banner. e$("1;33") makes the greeting bold amber; e$("0;33") turns the frame back to plain amber.
  • 34Seconds of uptime become days, hours and minutes with int() and mod().
  • 45Only mount points that start with /share/CACHEDEV count: these are the data volumes.
  • 47The used share of 12 cells, rounded to a whole cell.
  • 49One line per volume: name, free space, size and the bar.
  • 50The label "Free space" stands on the first volume only.
  • 64–67SEED or, without it, the minute and second of the clock start the row; one step of it picks the tip.
  • 71–76Sakamoto's method: one digit per month in t$, and January and February count to the year before.

Run it

yabasic hello.yab

The program prints the banner and ends. To see it at every SSH login, start it from your login file; the Bash project "A greeting at the SSH login" shows which file QTS reads and why the line must be added again after a restart.

Try it yourself

Add a ninth tip and change the 8 on lines 55 and 67 to 9. Run the program with NOW="2026-11-27 21:15:00" and see the evening greeting.

More projects in BASIC