shell script parsing data to variables then update

2019-06-09 15:29发布

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:

  1. save the data (numbers) to variables
  2. 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))'

1条回答
ら.Afraid
2楼-- · 2019-06-09 16:09
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) 
"
查看更多
登录 后发表回答