我使用 cPanel 创建了一个 cronjob。
每隔一段时间它就会运行这个生成备份的 php 文件:
<?php
include $_SERVER['DOCUMENT_ROOT'].'conectar.php';
$filename='backup_cursos_'.date('d-M-y__H:i:s').'.sql';
$result=exec('mysqldump '.DATABASE.' --password='.PASS.' --user='.USER.' --single-transaction >/home/cursos/backups/'.$filename,$output);
if($output==''){/* no output is good */}
else {/* we have something to log the output here*/}
?>
DATABASE
、PASS
和USER
常量存储在conectar.php
文件中。
每次 cron 运行时我都会收到此警告消息:
Warning: Using a password on the command line interface can be insecure.
我以为在那里添加常量是安全的,所以我的问题是:
如何以安全的方式运行 cron 作业?
最佳答案
参见 Suppress warning messages using mysql from within Terminal, but password written in bash script有关该问题的详细信息。基本上:不要通过命令行而是通过设置提供密码。
关于php - 如何以安全的方式运行 cron? (收到此警告 : "Using a password on the command line interface can be insecure"),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45775741/