php - 如何在命令中将参数传递给 linux

标签 php linux shell

我需要稍后运行一个 mail.php 文件,而不是让用户在提交 register.php 时等待验证电子邮件发送。

所以我选择使用 at 命令在 1 分钟后在命令行中运行 mail.php(在 register.php 中调用):

但我只能在 at 命令的交互模式下向该 php 文件发送参数。

at now + 1 minute
at> php mail.php {email}     # {email} is the argument I want to pass

因为我希望这是自动的,所以我需要在运行 shell 脚本时使用:

at -f mail.sh

但是我找不到合适的方法来传递 {email} 参数,

我尝试在 Shell 中设置环境变量,但还是徒劳:

register.php文件中,我这样写:

shell_exec('export email=foo@bar.com');
shell_exec('at -f mail.sh now + 1 minute');

ma​​il.sh中,我写道:

#! /bin/bash
php mail.php $email

最佳答案

你可以使用这个:

shell_exec('echo php mail.php test@test.com | at now + 1 minute');

关于php - 如何在命令中将参数传递给 linux,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19980131/

相关文章:

php - 我想制作一个互斥的复选框,因此表中一次只能有一条记录

linux - Linux 中的进程附加到哪个端口

html - 正则表达式问题匹配 HTML 标记

linux - redhat 4.1安装zeromq报错

unit-testing - Bash:在文件保存时执行脚本?

linux - 在远程服务器 linux 上复制/移动文件

linux - 检查终端输出是否与我的字符串匹配

php - YAML 文件不能包含制表符作为缩进

php - php mysql数据库连接错误

php - 如果查询不存在,显示模板图像?