#!/bin/bash accept=${HTTP_ACCEPT,,} # The accept header may have multiple types, so we check if it's the same with 'application/json' replaced by ''. # I.e. If it contains 'application/json', it won't be the same with it removed. if [ "$accept" != "${accept/application\/json/}" ] ; then echo "Content-type: application/json" echo uptime | sed -r 's/^.*load average: (.*), (.*), (.*)/{"load": {"1": \1, "5": \2, "15": \3}}/;' else if [ "$accept" != "${accept/text\/html}" ] ; then echo "Content-type: text/html" echo echo "

load

" echo "

The 'load' resource contains the unix system load information for this server.

" echo "

GET is the only valid method.

" echo "

Data is returned as application/json.

" else echo "Content-type: text/plain" echo echo "LOAD" echo "The 'load' resource contains the unix system load information for this server." echo "GET is the only valid method." echo "Data is returned as application/json." fi fi