2

I have added several lines to be executed in systemwide /etc/bash.bashrc such as notifying a login via email, etc. I have noticed that upon exit which invokes logout, systems prints those lines to the users as :

USER@IP:~$ exit
logout
[1]+  Done                    cat /home/USER/a.txt | ssmtp EMAIL@gmail.com
Connection to IP closed.

How can I suppress this on my system?

1
  • 5
    Can you add your additions to your /etc/bash.bashrc file to your question, please? – Byte Commander Apr 14 '18 at 20:39
4

The [1]+ Done ... part of your output seems to come from Bash's job control. You usually get it when a command that you have started in background terminates, like this:

$ sleep 1 &
[1] 20931

$ 
[1]+  Done                    sleep 1

One solution to suppress these job control outputs is to launch the background command in a subshell, by enclosing it in parentheses:

$ ( sleep 1 &)

$ 

I can't tell whether this is appropriate in your situation, because you haven't shown your actual commands yet and this approach comes with a few disadvantages:

The job can't be controlled any more (e.g. jobs, bg, fg commands), but as it runs from a startup script, I assume that wouldn't be intended anyway.
If the command were modifying its environment (e.g. setting variables or changing the working directory), that would only affect the subshell then and no longer the rest of the script.


Another way is to make the shell forget about the job after it started using disown, like:

$ sleep 1 & disown
[1] 27248

$ 

That way however, it will also no longer terminate when the shell exits, so it might keep running past the user logout, if I understood this right (correct me if not).


Sources and further reading:

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.