Created
April 2, 2013 02:42
-
-
Save hugozhu/5289546 to your computer and use it in GitHub Desktop.
Pi的cosm脚本
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
LOCATION='' | |
API_KEY='' | |
FEED_ID='' | |
#################################################### | |
COSM_URL=http://api.cosm.com/v2/feeds/$FEED_ID?timezone=+8 | |
cpu_load=`cat /proc/loadavg | awk '{print $2}'` | |
for i in 1 2 3 4 5; do | |
cpu_t=`cat /sys/class/thermal/thermal_zone0/temp | awk '{print $1/1000}'` | |
if [[ "$cpu_t" =~ ^- ]] | |
then | |
cpu_t='0.0' | |
else | |
echo $cpu_t | |
break | |
fi | |
done | |
site_online_users=`curl -s "http://online.cnzz.com/online/online.php?id=5144522&h=hzs16.cnzz.com&on=1&s=line" | sed -e 's/.*当前在线\[\([0-9]\).*/\1/g'` | |
echo $site_online_users | |
STR=`awk 'BEGIN{printf "{\"datastreams\":[ {\"id\":\"1\",\"current_value\":\"%.2f\"}, {\"id\":\"2\",\"current_value\":\"%.2f\"},{\"id\":\"3\",\"current_value\":\"%s\"}] } ",'$cpu_load','$cpu_t','$site_online_users'}'` | |
echo $cpu_t | |
echo $cpu_load | |
echo $STR | |
echo $STR > $LOCATION/cosm.json | |
curl -s -v --request PUT --header "X-ApiKey: $API_KEY" --data-binary @$LOCATION/cosm.json $COSM_URL |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment