2

I would like to know if it's possible to create an alias (on my .zsh_aliases) to launch a command from the graphical session to a tty (does not matter 1 or 6 ...) ?

I tried with for example cmatrix:

    alias matrix='sudo chvt 1 && cmatrix -B'

and it will open the tty 1 but launch cmatrix on the current shell (on the Xsession).

(I have a zsh shell on Debian 10)

Jeff Schaller
  • 67,283
  • 35
  • 116
  • 255
shengu
  • 23
  • @Quasímodo thank you very much ! I did not know this program, it suits me, but if possible is there a way that it displays the screen of the terminal in question without doing CTRL + ALT + F1 for example, without doing it manually ? – shengu Oct 21 '20 at 19:38
  • Gilles has the answer for that :) – Quasímodo Oct 21 '20 at 22:28

1 Answers1

2

chvt 1 causes vt 1 to become visible, but doesn't affect where subsequent commands run. cmatrix -B runs on the same terminal where the original shell is running. If you want to run cmatrix on another terminal, you have to let the system know that this is what you want to do.

Use openvt to run a program on a different virtual console. Pass the -s option if you also want to make that console visible. openvt needs to run as root. If you don't want to run cmatrix as root, you'll need to use su to lower privileges.

sudo openvt -c 1 -s su "$USER" -c 'cmatrix -B'
  • thanks for your answer but it doesn't work for me. I got the following message : openvt: Can't open the file : /dev/tty1 : Operation not allowed Did you encounterred this ? Thanks in advance for your help – shengu Oct 23 '20 at 07:15
  • @shengu You need to be root, that's why the code I posted has sudo in front. – Gilles 'SO- stop being evil' Oct 23 '20 at 08:21
  • sorry i did not mention that i tested it as root and also with sudo su before – shengu Oct 23 '20 at 09:20
  • @shengu I don't see how my version of openvt could output this exact message. (Is it a translation back into English? If so, don't do that: always copy-paste error messages.) And I can't think of a reason why openvt -c 1 wouldn't work as root (assuming you are on a PC or similar hardware with a console). – Gilles 'SO- stop being evil' Oct 23 '20 at 09:25
  • sudo openvt -vf -c 1 -s su "$USER" -e 'ls'

    openvt: Impossible d'ouvrir le fichier : /dev/tty1 : Opération non permise Here is the exact output of the command.

    – shengu Oct 23 '20 at 11:39
  • @shengu Ok, so it's “Operation not permitted” (EPERM), not “Access denied” (EACCES). I guess a process that's already running on tty1 (X server maybe) forbids others from also accessing it. Use a different vt. – Gilles 'SO- stop being evil' Oct 23 '20 at 12:23