我使用 bash
编写了一个 CGI
脚本,该脚本执行 MySQL
查询。由于我的目的是自动执行任务,因此我必须将 MySQL 凭据
放入脚本中,并且仅使用纯文本形式的密码。对我来说,问题是执行脚本的服务器是具有外部访问权限的生产服务器。我正在寻找一种保留自动化但不提供纯文本密码的解决方案。
代码如下
#!/bin/bash
echo "Content-type: text/html"
echo ""
echo "<html>"
echo "<body>"
mysql -h $host -u root -ptest -e "select User,marks,percent from $db;" | sed 's/\t/,/g' > /tmp/out.csv `
gnuplot gnudg.sh
echo "<img src="http://172.16.0.19/report/histreport.png" alt="DG-Reports">"
echo "</body>"
echo "</html>" `
脚本权限:
ls -l /var/www/cgi-bin/ssdg/ssdgplot.sh
-rwxr-xr-x 1根根1589年4月22日12:41/var/www/cgi-bin/ssdg/ssdgplot.sh
最佳答案
对于 mysql,您可以使用从 reference1 读取的选项文件, reference2 您可以设置用户名和密码等值
[db-details]
user=username
password=password
并读取此文件以在脚本中登录数据库。 并避免除 root 之外的其他人读取它,只需将权限设置为
chmod 600 option_file
关于使用脚本进行 MySQL 身份验证,无需以纯文本形式提供密码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23216341/