Gil*_*il' 15
在 Linux 下,at总是警告你它将用 执行指定的命令/bin/sh,而不是你最喜欢的 shell。您无法取消此消息,它在源代码中是硬编码的。
您传递的命令由/bin/sh. 如果您愿意,此命令可以是脚本的路径;then/bin/sh将执行脚本程序,从而启动脚本的解释器并解释脚本。脚本的语言完全独立于启动它的程序。因此,例如,如果您想执行一个 bash 脚本(即以 开头的脚本#!/bin/bash),只需将脚本的路径传递给at并忽略不相关的消息。
您可以通过更改脚本shebang来从不同的 shell 运行它。\n一些典型的 shebang 行:
\n\n\n\n\nRun Code Online (Sandbox Code Playgroud)\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
要在给定时间运行脚本,我建议您添加一个cronjob
\n\n例子:
\n\n\n\n以下行使用户程序 test.pl\xe2\x80\x94 表面上是一个 Perl\n 脚本\xe2\x80\x94 每两个小时运行一次,在午夜、凌晨 2 点、凌晨 4 点、上午 6 点、上午 8 点等\n 运行:
\n\n0 */2 * * * /home/用户名/test.pl
\n