Is it possible to forward the output of “service httpd restart” for example to “notify-send $output”? [closed]

二次信任 提交于 2019-12-12 03:09:50

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!