1

I'm trying to setup a simple script to run on a cron job that runs in the background and notifies any open terminals of the outcome using the wall command. However when testing, I don't get any output at all. I'm using WSL Ubuntu and zsh via the Terminal app from Microsoft.

Running tty and w returns the below, while who returns nothing at all.

 hardya@GBH-HARDYA1  ~  tty
/dev/pts/4
 hardya@GBH-HARDYA1  ~  w
 09:16:01 up 3 days,  4:30,  0 users,  load average: 0.00, 0.00, 0.00
USER     TTY      FROM             LOGIN@   IDLE   JCPU   PCPU WHAT

Any ideas?

3
  • 2
    Probably related to this. I'm pretty sure that the owner of that answer will provide you an explanation here! :) Commented Feb 16, 2023 at 9:58
  • Thanks @EdgarMagallon, I'd not found that particular one. So you're saying IF wall using the same behind the scenes info as who, it might be that it's fundamentally incompatible with WSL at the moment Commented Feb 16, 2023 at 11:18
  • Yeah, and as I said you have an answer now by that user! I do know nothing about WSL/Windows so I was not able to provide a full explanation and solution. Commented Feb 17, 2023 at 2:04

1 Answer 1

4

@EdgarMagallon is correct on two counts in the comments:

  • This is related to the who command issue mentioned on Ask Ubuntu
  • The owner of that answer (me) will ... ;-)

Ok, so yes, the wall command does appear to use the same mechanism as who for determining the logged-in users and their terminals.

So to get it to work under WSL2:

  • You'll need a recent release of WSL that reports 0.67.6 or higher (preferably 1.0.3 or higher) in wsl --version. If it returns invalid command, make sure that your Windows is fully updated, then install the new Windows Subsystem for Linux from the Microsoft Store.

  • Enable Systemd as noted in this answer

  • After restarting WSL and confirming that Systemd is enabled, run su - $USER to force a "login" of your user.

  • Then, in another terminal, you can run:

    sudo wall Wallaby # Or a real message
    

    And it should display in the logged-in terminal. Keep in mind that sudo is required on many distributions. It used to be that wall was setguid on Ubuntu and Debian, but that doesn't appear to be the case any longer.

  • w and who should also show your logged-in user.

Of course, this doesn't necessarily help you achieve your desired script, since WSL doesn't force logins. Some possibilities for that:

  • Force a su - $USER login in shells where you want to receive the notifications.

  • Write a Zsh prompt function to monitor a file (or perhaps fifo?) and update the prompt with the "completion" information (until cleared). Note that I find this easier in Fish, but I feel certain it would be possible in Zsh (or even Bash) as well.

  • Run tmux in your terminal(s) and use tmux display-message to notify of the competion.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .