问题
If I create a script that will restart apache:
service httpd restart
... I will never know what the output was because it does not open the terminal window.
I am wondering if the output can be taken and then forwarded to:
notify-send output
... this way there is some visual of what happened for few seconds on the screen.
回答1:
First, you really should look inside the terminal when running your script.
Also, notice that services are started before login time (at boot time).
And server daemons like Apache or Lighttpd have their own log files usually under /var/log/;
You could put the output of service httpd restart command into some variable like
restart_msg=$(service httpd restart 2>&1)
where 2>&1 redirects stderr to stdout
then you can show that with
notify-send "HTTPD restarted" "$restart_msg"
But I don't think all this is a good idea. You should take the habit of restarting services inside a terminal and have a look at the output (in the rare case something gets wrong, you'll need all of it).
Read the Advanced Bash Scripting Guide.
来源:https://stackoverflow.com/questions/18120574/is-it-possible-to-forward-the-output-of-service-httpd-restart-for-example-to