Score:4

Disable output of systemctl and apt-get

fi flag

I'm currently writing a script that installs and configures the Samba server automatically for me. I was wondering why this command sudo apt-get -y install samba > /dev/null && sudo systemctl enable smbd.service > /dev/null still gives this output.

Extracting templates from packages: 100%
Synchronizing state of smbd.service with SysV service script with /lib/systemd/systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install enable smbd

How can I prevent the commands from giving any output?

Thanks

Ubuntu Server 20.04.3 LTS

in flag
This is outside the scope of the question, but why would you *not* want to see the output of software being installed? This is a very simple way to see if there are problems before they become problems. Is the goal to have this script run on a fleet of systems to quietly start up Samba shares?
user.dz avatar
ng flag
Welcome to Ask Ubuntu. Does [this answer](https://askubuntu.com/a/1182696/26246) the question? seems related to stderr stream.
driver1848 avatar
fi flag
@matigo No, I'm just planning to install Samba on a single local nas machine, but the parts haven't arrived yet and I wanted to learn a bit more about bash scripting because I was bored. And to why I don't want to see the output: To be honest, I don't know...
driver1848 avatar
fi flag
@user.dz Not sure where this config file is or what command I'd need. But this would probably help me.
user.dz avatar
ng flag
@driver1848 try this `sudo apt-get -yy install samba 1> /dev/null 2> /dev/null && sudo systemctl enable smbd.service 1> /dev/null 2> /dev/null` (it redirects stderr too).
driver1848 avatar
fi flag
Thank you, this fixed my issue!
Score:5
ng flag

> will redirect only stdout. stderr stream should be redirected too. Same commands as below:

sudo apt-get -qq install samba 1> /dev/null 2> /dev/null && sudo systemctl enable smbd.service 1> /dev/null 2> /dev/null

  • apt-get..-qq will suppress more installation dialogs
  • 1> /dev/null discards STDOUT
  • 2> /dev/null discards STDERR
pasman pasmański avatar
mx flag
Option `apt-get -yy` is not documented in manual. In which version it is implemented ?
user.dz avatar
ng flag
@pasmanpasmański my mistake, It is `-qq`
Score:4
mx flag

If your script uses bash, then you should use the &> operator for redirecting any output, that is both stderr and stdout:

sudo apt-get -y install samba &>/dev/null \
&& sudo systemctl enable smbd.service &> /dev/null 
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.