0

I'm using crontab to send messages to all users.

I wrote

*/1 * * * * wall $(bash some_shell_script.sh) 

But the problem is I always have to press Ctrl+D to end the message.

How can I solve this??

Kusalananda
  • 320,670
  • 36
  • 633
  • 936
KimJunseo
  • 3
  • 1
  • wall send it's argument from command line. does `bash some_shell_script.sh` terminate ? – Archemar Dec 12 '22 at 13:40
  • The parameter to wall is a text file. What are you trying to do with this shell script? – Anthony Kelly Dec 12 '22 at 13:54
  • 4
    It's unclear what the issue is as cron jobs are never interactive, and would therefore not be able to "wait for `Ctrl+D`". Please show the script that you are using in that command substitution. – Kusalananda Dec 12 '22 at 13:56
  • In my environment (Centos 8) after crontab task is executed (with wall in it) if I press CTRL+D I get exit from the "whole" shell... – Damir Dec 12 '22 at 14:51
  • 1
    As Kusulananda mentioned about cron is not interactive, I think OP should clarify more how he/she is able to get the possibility to enter CTRL+D to send messages and leave wall. Maybe he/she mixing running wall from inside crontab and running wall from shell directly... – Damir Dec 12 '22 at 15:02
  • @AnthonyKelly, my man page for wall gives the synopsis `wall [-n] [-t timeout] [message | file]`, so it looks like the argument can also be the message itself. – ilkkachu Dec 12 '22 at 18:38
  • @ilkkachu Interesting, I was looking at the man page on MacOS, which provides this synopsis `wall [-g group] [file]`. – Anthony Kelly Dec 13 '22 at 10:36
  • @AnthonyKelly, ok, it's different between systems, then! I looked at the [Debian man page](https://manpages.debian.org/bullseye/bsdutils/wall.1.en.html) (and made the mistake of generalizing to all Linuxen). The [FreeBSD one](https://www.freebsd.org/cgi/man.cgi?query=wall&apropos=0&sektion=1&manpath=FreeBSD+13.1-RELEASE&arch=default&format=html) indeed only says it takes a file, and then [this one](https://linux.die.net/man/1/wall) only takes a message. They did tag with [tag:linux] so they probably don't have the FreeBSD one, though. – ilkkachu Dec 13 '22 at 10:50

2 Answers2

0

You can use GNU screen to isolate the process in the background without exiting.

  1. Install GNU Screen for your distro
  2. screen -R wall
  3. wall $(bash some_shell_script.sh)
  4. Ctrl-A, Ctrl-D
Onyxia
  • 1
  • 1
0

The wall command executes within the context of cron. It does its thing and exits.

On the receiving display devices (terminals) you will get the notification from wall. This notification cares nothing about what you are doing on the terminal, so if you are quietly sitting at a command line prompt when the notification message is sent, the prompt will not be rewritten. You have found that you need to hit enter to get the prompt re-sent, but in practical terms this is unnecessary: you could simply enter your command normally.

Scenario timeline

  1. You are logged in and sitting at a command prompt
  2. The wall notification is sent to your terminal
  3. You type ls (and hit Enter)

At step 3 you do not have a visible prompt but the shell is still patiently waiting for your command.


Alternatively, perhaps you're actually talking about how you exit from the crontab command. In this instance the Ctrl/D is used to signal the end of input.

Scenario

  1. crontab
  2. You enter the line */1 * * * * bash some_shell_script.sh | wall
  3. You hit Ctrl/D to end data input to the crontab command

Note that the Ctrl/D in step 3 is nothing to do with wall. Also, this crontab entry will repeat your wall command every minute. Is that really what you want?

roaima
  • 107,089
  • 14
  • 139
  • 261
  • since cron invokes sh by default to parse the command line, I can't see how `wall $(bash some_shell_script.sh)` can ever makes sense as it passes the result of split+glob applied on the output of that bash command to `wall`. Likely the OP wants `bash some_shell_script.bash | wall` or `wall -- "$(bash some_shell_script.bash)"` – Stéphane Chazelas Dec 12 '22 at 19:25
  • @StéphaneChazelas agreed, and I should probably have noted that. Here I'm simply copying the line of code provided from the OP. It might be that they are aiming for an effect similar to `bash _some_shell_script.sh | xargs` of course - we don't know – roaima Dec 12 '22 at 20:45
  • Thanks a lot. I thought the wall command is not ended. But as you said wall is ended and I can just write a command like ls without typing enter. Frankly I don't know why this is happening but I'll try to figure out. Thank you – KimJunseo Dec 13 '22 at 03:58
  • I mean why the prompt disappears? now I know I can type any command like prompt is in there but I want to know why prompt disappears – KimJunseo Dec 13 '22 at 15:09
  • It had already been written – roaima Dec 13 '22 at 15:47