Skip to content

Instantly share code, notes, and snippets.

@dphiffer
Created April 8, 2019 19:51
Show Gist options
  • Save dphiffer/19c15757f99c4708724699cdd53b7946 to your computer and use it in GitHub Desktop.
Save dphiffer/19c15757f99c4708724699cdd53b7946 to your computer and use it in GitHub Desktop.
Shell script to print the current weekly mean value Mauna Loa CO2 value
#!/bin/bash
# Prints the current weekly mean value Mauna Loa CO2 value, and
# compares it to the value from 365 days ago.
# Thanks to Pieter Tans <[email protected]> for data guidance.
url="ftp://aftp.cmdl.noaa.gov/products/trends/co2/co2_weekly_mlo.txt"
line=`curl -s $url | tail -n 1`
curr=`echo "$line" | cut -c 30-35`
year=`echo "$line" | cut -c 50-55`
diff=`echo "$curr - $year" | bc`
echo "Current Mauna Loa CO2: $curr ppm"
echo "365 days ago: $year ppm"
if [ "$diff" == "0" ] ; then
echo "→ no change since last year"
elif [[ $diff =~ ^- ]] ; then
echo "→ ${diff#-} ppm lower than last year"
else
echo "→ $diff ppm higher than last year"
fi
@dphiffer
Copy link
Author

dphiffer commented Apr 8, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment