fgconsole - print the number of the active VT.
fgconsole [--help|--version|--next-available]
If the active VT is /dev/ttyN, then prints N on standard output. If the console is a serial console, then "serial" is printed instead. --next-available Will show the next unallocated virtual terminal. Normally 6 virtual terminals are allocated, with number 7 used for X; this will return "8" in this case.
chvt(1).