Bitcoin Forum

Bitcoin => Mining support => Topic started by: sabe on August 02, 2011, 07:53:30 PM



Title: Help me with a simple Linux script
Post by: sabe on August 02, 2011, 07:53:30 PM
Here's what I'm trying to do, I am trying to extract the temperature from every card and send them to my web server as a GET request so I can update a database on my web server.

What I have so far:

Code:
export DISPLAY=:0;aticonfig --adapter=all --odgt | grep -o '...\...' | sed -e 's/^[ \t]*//'

This gives me:

Code:
91.00
91.50
91.00
82.50

How do I chop this with shell scripting and send it as part of a GET request as such:

Code:
GET http://www.mywebsite.com/update_temp.php?rig=1&temp1=91.00&temp2=91.50&temp3=91.00&temp4=82.50

Thanks Gurus!


Title: Re: Help me with a simple Linux script
Post by: cirz8 on August 02, 2011, 08:17:50 PM
curl
sorry, came back and saw that you just didn't want the GET solved, you wanted some chopping as well.

Quote
#!/bin/bash
Counter="0"
URL="http://www.mywebsite.com/update_temp.php?rig=1"

for Temp in `export DISPLAY=:0;aticonfig --adapter=all --odgt | grep -o '...\...' | sed -e 's/^[ \t]*//'`
  do
    Counter="$(($Counter+1))"
    URL="${URL}&temp$Counter=$Temp"
  done
curl "$URL"

Working as intended?


Title: Re: Help me with a simple Linux script
Post by: sabe on August 03, 2011, 02:42:19 PM
Thanks, works like a gem!


Title: Re: Help me with a simple Linux script
Post by: cirz8 on August 03, 2011, 10:46:09 PM
And if you prefer one-liners
Code:
curl "http://www.mywebsite.com/update_temp.php?rig=1`DISPLAY=:0;aticonfig --adapter=all --odgt | awk 'BEGIN {counter=1} /Temperature/ {printf "&temp"counter++"="$5}'`"

At first I thought maybe sed could do this, but after 30min of trying sed, and spamming the google search, I gave up and gave awk a shot and was surprised at how easy and powerful the syntax was.