Last active
January 1, 2016 03:32
-
-
Save greyhoundforty/ac0ac2c331381e4dd4fb to your computer and use it in GitHub Desktop.
Simple script to test writing to json formatted file
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
## Simple script to test writing to json formatted file. | |
#!/bin/bash | |
# Get hostname | |
hostname=`hostname -A` 2> /dev/null | |
# Get distro | |
distro=`python -c 'import platform ; print platform.linux_distribution()[0] + " " + platform.linux_distribution()[1]'` 2> /dev/null | |
# Get uptime | |
if [ -f "/proc/uptime" ]; then | |
uptime=`cat /proc/uptime` | |
uptime=${uptime%%.*} | |
seconds=$(( uptime%60 )) | |
minutes=$(( uptime/60%60 )) | |
hours=$(( uptime/60/60%24 )) | |
days=$(( uptime/60/60/24 )) | |
uptime="$days days, $hours hours, $minutes minutes, $seconds seconds" | |
else | |
uptime="" | |
fi | |
printf '{"hostname":"%s","distro":"%s","uptime":"%s"}\n' "$hostname" "$distro" "$uptime" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment