shell脚本解析数据变量,然后更新数据库 [英] shell script parsing data to variables then update a database
问题描述
我有我的网络所发送的数据在HTML页面上的设备。我需要能够从页面收集数据并将其插入到我的数据库,所以我可以有历史参照数据。我可以用下面的命令来检索网站等领域。结果返回由换行分隔的三个数字。
我想运行此作为一个Linux cron作业,所以我想用一个Linux脚本:
- 保存数据(数字)变量
- 连接到我的数据库,并在表 插入数据
我的命令行来检索信息如下。这从设备解析出的数据的伟大工程:
卷曲-s http://local_device.com/dtm.html?address=C5:0 |的grep -Po'[0-9] +(= [^ 0-9] +(C 5:2'; | C5:6≤| C5:13))'
设置 - $(卷曲-s http://local_device.com/dtm.html?address=C5:0 | grep的-Po[0-9] +(? = [^ 0-9] +(C 5:2'; | C5:6≤| C 5:13))')
C5_2 = $ 1
C5_6 = $ 16
C5_13 = $ 3
MySQL的-e
INSERT INTO db.table VALUES($ C5_2,$ C5_6,$ C5_13)
I have a device on my network that is posting data to an html page. I need to be able to collect the data from the page and insert it into my database so I can have historical reference to the data. I am able to use the following command to retrieve the fields from the site. The result returns three numbers separated by a line break.
I would like to run this as a linux cron job, so I would like to use a linux script to:
- save the data (numbers) to variables
- connect to my database and insert the data in a table
My command line to retrieves the information is below. This works great for parsing out the data from the device:
curl -s http://local_device.com/dtm.html?address=C5:0 | grep -Po '[0-9]+(?=[^0-9]+(C5:2<|C5:6<|C5:13))'
see below for a reference, since they are numbers, I did not quote them:
set -- $(curl -s http://local_device.com/dtm.html?address=C5:0 | grep -Po '[0-9]+(?=[^0-9]+(C5:2<|C5:6<|C5:13))')
C5_2=$1
C5_6=$2
C5_13=$3
mysql -e "
INSERT INTO db.table VALUES ($C5_2, $C5_6, $C5_13)
"
这篇关于shell脚本解析数据变量,然后更新数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!