4

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

driver1848
  • 41
  • 2
  • 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? – matigo Jan 01 '22 at 15:02
  • Welcome to Ask Ubuntu. Does [this answer](https://askubuntu.com/a/1182696/26246) the question? seems related to stderr stream. – user.dz Jan 01 '22 at 15:09
  • 2
    @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 Jan 01 '22 at 15:11
  • @user.dz Not sure where this config file is or what command I'd need. But this would probably help me. – driver1848 Jan 01 '22 at 16:05
  • @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). – user.dz Jan 01 '22 at 16:28
  • Thank you, this fixed my issue! – driver1848 Jan 01 '22 at 17:08

2 Answers2

5

> 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
user.dz
  • 47,137
  • 13
  • 140
  • 258
4

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 
BeastOfCaerbannog
  • 12,964
  • 10
  • 49
  • 77
pasman pasmański
  • 1,757
  • 1
  • 6
  • 20