Bitcoin Forum
December 04, 2016, 08:20:26 AM *
News: To be able to use the next phase of the beta forum software, please ensure that your email address is correct/functional.
 
   Home   Help Search Donate Login Register  
Pages: [1]
  Print  
Author Topic: Help me with a simple Linux script  (Read 597 times)
sabe
Jr. Member
*
Offline Offline

Activity: 55


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!

Found my post helpful? Please donate to: 135t2FmsNQA9uKNxFwewFHYQKTvVMUza8W
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction. Advertise here.
1480839626
Hero Member
*
Offline Offline

Posts: 1480839626

View Profile Personal Message (Offline)

Ignore
1480839626
Reply with quote  #2

1480839626
Report to moderator
1480839626
Hero Member
*
Offline Offline

Posts: 1480839626

View Profile Personal Message (Offline)

Ignore
1480839626
Reply with quote  #2

1480839626
Report to moderator
1480839626
Hero Member
*
Offline Offline

Posts: 1480839626

View Profile Personal Message (Offline)

Ignore
1480839626
Reply with quote  #2

1480839626
Report to moderator
cirz8
Jr. Member
*
Offline Offline

Activity: 42


View Profile
August 02, 2011, 08:17:50 PM
 #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?

Mandatory?  123ABCcirz8CcieVh9UwThEX2vkoJF33Te
sabe
Jr. Member
*
Offline Offline

Activity: 55


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

Thanks, works like a gem!

Found my post helpful? Please donate to: 135t2FmsNQA9uKNxFwewFHYQKTvVMUza8W
cirz8
Jr. Member
*
Offline Offline

Activity: 42


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.

Mandatory?  123ABCcirz8CcieVh9UwThEX2vkoJF33Te
Pages: [1]
  Print  
 
Jump to:  

Sponsored by , a Bitcoin-accepting VPN.
Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!