为什么`at` 警告我命令将使用/bin/sh 执行?如果我想要不同的外壳怎么办?

Cra*_*lus 14 shell at

我尝试在我at的脚本中使用它并打印:

警告:命令将使用 /bin/sh 执行

如果需要,我将如何使用不同的外壳?

Gil*_*il' 15

在 Linux 下,at总是警告你它将用 执行指定的命令/bin/sh,而不是你最喜欢的 shell。您无法取消此消息,它在源代码中是硬编码的。

您传递的命令由/bin/sh. 如果您愿意,此命令可以是脚本的路径;then/bin/sh将执行脚本程序,从而启动脚本的解释器并解释脚本。脚本的语言完全独立于启动它的程序。因此,例如,如果您想执行一个 bash 脚本(即以 开头的脚本#!/bin/bash),只需将脚本的路径传递给at并忽略不相关的消息。


vfb*_*lva 3

您可以通过更改脚本shebang来从不同的 shell 运行它。\n一些典型的 shebang 行:

\n\n
\n
#!/bin/sh \xe2\x80\x94 Execute the file using sh, the Bourne shell, or a compatible shell\n#!/bin/csh -f \xe2\x80\x94 Execute the file using csh, the C shell,\n#!/usr/bin/perl -T \xe2\x80\x94 Execute using Perl with the option for taint checks\n#!/usr/bin/php \xe2\x80\x94 Execute the file using the PHP command line interpreter\n#!/usr/bin/python -O \xe2\x80\x94 Execute using Python with optimizations to code\n#!/usr/bin/ruby \xe2\x80\x94 Execute using Ruby\n
Run Code Online (Sandbox Code Playgroud)\n
\n\n

要在给定时间运行脚本,我建议您添加一个cronjob

\n\n

例子:

\n\n
\n

以下行使用户程序 test.pl\xe2\x80\x94 表面上是一个 Perl\n 脚本\xe2\x80\x94 每两个小时运行一次,在午夜、凌晨 2 点、凌晨 4 点、上午 6 点、上午 8 点等\n 运行:

\n\n

0 */2 * * * /home/用户名/test.pl

\n
\n