Bitcoin Forum
December 15, 2024, 05:50:46 PM *
News: Latest Bitcoin Core release: 28.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Help me with a simple Linux script  (Read 835 times)
sabe (OP)
Newbie
*
Offline Offline

Activity: 55
Merit: 0


View Profile
August 02, 2011, 07:53:30 PM
 #1

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!
cirz8
Newbie
*
Offline Offline

Activity: 42
Merit: 0


View Profile
August 02, 2011, 08:17:50 PM
Last edit: August 02, 2011, 08:58:25 PM by cirz8
 #2

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?
sabe (OP)
Newbie
*
Offline Offline

Activity: 55
Merit: 0


View Profile
August 03, 2011, 02:42:19 PM
 #3

Thanks, works like a gem!
cirz8
Newbie
*
Offline Offline

Activity: 42
Merit: 0


View Profile
August 03, 2011, 10:46:09 PM
 #4

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.
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!