linux - 如何在 bash/zsh 中自动发出(新邮件)通知?

标签 linux bash shell email notifications

好吧,我的问题的标题有点含糊。现在让我解释清楚。

我们知道 bash 中有一个“MAILCHECK”,每隔几分钟 bash 就会检查邮箱,如果有新邮件会给你一个消息。请注意,您不需要此通知的命令。如果有新邮件,Bash 会随时自动打印消息。

在这里,我有几个问题:

  1. 在我的 zsh 中没有这样的通知(也许我忘记了一些东西在我的 .zshrc 中)

  2. 如何在bash/zsh中改变“新邮件通知”的格式

  3. 如何执行a certain command在 bash/zsh 中完成我的任何命令后。例如当我输入 ls<enter> , ls将被执行,然后 the certain command将被执行。 如果我能做到这一点,自动通知就完成了!

清楚了吗?有什么建议吗?

最佳答案

<强>1。 zsh 中的邮件通知:

我认为它就像 bash;如果 shell 知道在哪里查找邮件并且 MAILCHECK 参数设置为非负整数,则会发生邮件通知。

<强>2。更改邮件通知消息。

(来自 man bash):

MAILPATH
  A colon-separated list of file names to be checked for mail.  The message to be
  printed when mail arrives in a particular file may be specified by separating
  the file name from the message with a '?'.  When used in the text of the
  message, $_ expands to the name of the current mailfile.  Example:
    MAILPATH='/var/mail/bfox?"You have mail":~/shell-mail?"$_ has mail!"'
  Bash  supplies  a default value for this variable, but the location of the user
  mail files that it uses is system dependent (e.g., /var/mail/$USER).

我认为 zsh 大致相同,除了还将 mailpath 公开为 MAILPATH 的数组版本。

<强>3。运行任意命令:

bash 中,PS1 的值被打印为命令提示符。除非未设置 promptvars 选项(默认设置),否则字符串在使用前会经历参数扩展、命令替换、算术扩展和引号删除。第二个意味着您可以在命令提示符下执行任意 shell 命令。

zsh 具有相同的功能,由 shell 选项 promptsubst(或 PROMPT_SUBST,如联机帮助页所述)控制。与 bash 不同,默认情况下未设置 shell 选项。此外,您可能会发现无法更改 PS1 的值(如果您的发行版使用提示主题),因为提示主题会在每个命令提示符之前重置 PS1

事实证明,zsh 有一种不同的机制,可以在打印提示之前运行 shell 函数(或在其他情况下;我只关注这一种情况)。有一个名为 precmd_functions 的数组参数,其值是将在每个提示符之前运行的函数的名称。 (提示主题系统使用此机制在打印之前重置 PS1。)

关于linux - 如何在 bash/zsh 中自动发出(新邮件)通知?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17246534/

相关文章:

regex - 用于多个搜索的 sed 正则表达式语法

shell - 精确匹配,前导和尾随特殊字符(包括空格)除外

linux - 对于冒号前的字段与模式匹配的行,在冒号后提取字段

linux - (Ubuntu) Linux : Is it possible to find out if you're running inside §script§ command?

linux - 如何判断 iptables 现在是否阻止了 url

html - 将 xml 文件转换为 html 文件的基本步骤

linux - 从 AWK 命令获取输出并根据空格逐行显示

c - 使用管道和永不结束的命令重现 bash 行为

linux - 如何限制在循环中执行的命令的 shell 脚本中的输出

linux - 向 Yocto 生成的自定义 Linux 镜像添加新内核参数