问题描述
我需要运行在wget的一个特定的MySQL查询,这是在后台运行,下载完的文件。例如...
I need to run a specific mysql query upon wget, which is running in the background, finishes downloading a file. For example...
HTTP://domain/file.zip
然后运行:
更新表
SET 状态
='活'WHERE ID
='1234'
我怎么会去这样做?
推荐答案
我会建议在子shell启动wget命令,这样可以保证它完成你运行你的mysql命令。在bash中,这是用括号完成。
I would recommend launching the wget command in a subshell so you can ensure it completes before you run your mysql command. In bash, this is done with parentheses.
也可以使用&放大器;&安培;
所以,只有当wget命令有一个成功的退出状态mysql命令运行
Also use &&
so that the mysql command runs only if the wget command has a success exit status.
#!/bin/sh
(
wget "http://domain/file.zip" && mysql -u user -ppassword database -e "UPDATE..."
) &
在把明文密码的脚本它可以在 PS
房源进行查看。
Putting the password in plaintext in the script is not necessarily a good idea because it can be viewed in a ps
listing.
相反,你可以依靠你的〜/ .my.cnf
文件中的 [客户]
部分。您也可以使用 MYSQL_PWD
环境变量。两个方案都意味着没有密码的命令上市可见。
Instead, you can rely on the [client]
section in your ~/.my.cnf
file. You can also use the MYSQL_PWD
environment variable. Either of these solutions means there's no password visible in the command listing.
这篇关于运行MySQL查询的wget完成下载文件后,的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!