Help converting date-time value to decimal

Hi

I need help to do some calculation in script.
I have a monitor program (munin) that I would like to log uptime information from a server.

The script looks like this (not complete):

#!/bin/sh
# server_uptime

### Config Start
# Reads the server parameters using the HTTP port with correct username and password


user="root"
pass="password"
port="80"
server="192.168.1.20"

### Config End

url="http://$user:$pass@$server:$port"

case $1 in
   config)
        cat <<'EOM'
graph_title Server uptime
graph_vlabel days
graph_category System
uptime.label Server1

EOM
        exit 0;;
esac

echo -n "uptime.value "
echo `wget -q -O - "$url" | grep Uptime`

Output from this is a long line. Start of it is omitted. End looks always the same.

*** <BR><BR>Current time 10:27:14<BR>NodeID: d3432<BR>Uptime: 22d 18:10:37

I can get 22 (days) and 18(hours) out from this but I like to see the output like this
uptime.value 22.75

So I need to calculate 22+18/24 Days+Hour/24
I have tried different solution with printf, but can not get it to calculate.

converting date-time value to decimal

echo "22d 18:10:37" |awk -F "[d :]" '{printf "%.2f", $1+($3*3600+$4*60+$5)/24/3600}'
22.76
2 Likes

Thanks alot.
Happy new year.

---------- Post updated at 01:34 PM ---------- Previous update was at 12:20 PM ----------

I need some more help. (my skills with are not very good)
How do I get all lest of the string from "Uptime:" so it becomes like
22d 18:10:37

wget -q -O - "$url" | sed 's/.*>Uptime: //'

Thanks for reply
echo "bla bla bla Uptime: 212d 18:10:37" | sed 's/.*>Uptime: //'
gives
bla bla bla Uptime: 212d 18:10:37
and not
212d 18:10:37

There's a spurious > sign in the sed.

echo "bla bla bla Uptime: 212d 18:10:37" | sed 's/.*Uptime: //'
212d 18:10:37

Should be:

echo "bla bla bla Uptime: 212d 18:10:37" | sed 's/.*Uptime: //'

instead of:

echo "bla bla bla Uptime: 212d 18:10:37" | sed 's/.*>Uptime: //'

if you dont have a ">" before Uptime.

Thanks, works great now