小编lon*_*gaa的帖子

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

我需要稍后运行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
Run Code Online (Sandbox Code Playgroud)

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

at -f mail.sh
Run Code Online (Sandbox Code Playgroud)

但我找不到通过{email}参数的正确方法,

我试图在Shell中设置一个可变的环境,但也是徒劳的:

register.php文件中,我写道:

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

mail.sh中,我写道:

#! /bin/bash
php mail.php $email
Run Code Online (Sandbox Code Playgroud)

php linux shell

5
推荐指数
2
解决办法
3112
查看次数

标签 统计

linux ×1

php ×1

shell ×1