可以转发“service httpd restart”的输出,例如到“notify-send $ output”? [英] Is it possible to forward the output of "service httpd restart" for example to "notify-send $output"?

查看:351
本文介绍了可以转发“service httpd restart”的输出,例如到“notify-send $ output”?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我创建的脚本将重新启动apache:

 服务httpd重新启动



...我永远不知道输出是什么,因为它没有打开终端窗口。



我想知道是否可以取得输出,然后转发:

 通知发送输出



...以这种方式,可以看到屏幕上发生了几秒钟的情况。

解决方案

首先,你应该在运行脚本时查看终端内部。



此外,请注意,服务是在登录时间之前启动的(在引导时)。



Apache或Lighttpd通常在 / var / log / ;

下有自己的日志文件

服务httpd重新启动命令到一些变量,如

  restart_msg = $ httpd restart 2>& 1)

其中 2& / code>重定向 stderr stdout



b
$ b

 通知发送HTTPD重新启动$ restart_msg

但我不认为这是一个好主意。您应该习惯在终端重新启动服务,并查看输出(在极少数情况下,错误,您需要所有的输出)。



阅读高级Bash脚本指南


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.

解决方案

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.

这篇关于可以转发“service httpd restart”的输出,例如到“notify-send $ output”?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆