| View previous topic :: View next topic |
| Author |
Message |
Kernel78 Moderator

Joined: 24 Jun 2005 Posts: 3652
|
Posted: Sat Oct 10, 2009 9:45 pm Post subject: uprecords + sqlite |
|
|
come ogni buon ossessivo compulsivo che si rispetti uso uprecords ma non mi sentivo soddisfatto dal fatto che salvasse i propri dati in un banale file di testo quindi mi sono detto: "ehi, perchè non usare sqlite" e mi sono messo a scrivere questa cavolata
| Code: | #!/bin/bash
updb="/var/spool/uptimed/uprecords.db"
if [ ! -e $updb ]
then
sqlite3 $updb "CREATE TABLE uptime(bootid text primary key, time integer, system text);"
fi
bootid=$(cat /proc/sys/kernel/random/boot_id)
sys=$(uname -sr)
uptime=$(cat /proc/uptime | cut -f 1 -d .)
echo " # Uptime | System Boot up"
echo "----------------------------+---------------------------------------------------"
sqlite3 $updb "replace into uptime(bootid,time,system) values(\"$bootid\",$uptime,\"$sys\");"
OIFS=$IFS
IFS='
'
for ret in $(sqlite3 $updb "select bootid,time,system from uptime order by time desc limit 10;")
do
count=$((count+1))
uptime=$(echo $ret | cut -f 2 -d \|)
upfrom=$(date -d @$(($(date +%s)-$uptime)) +"%a %b %d %H:%M:%S %Y")
sys=$(echo $ret | cut -f 3 -d \|)
bootid=$(echo $ret | cut -f 1 -d \|)
if [ "$bootid" == "$(cat /proc/sys/kernel/random/boot_id)" ]
then
printf "\033[1m"
this="->"
else
printf "\033[0m"
this=" "
fi
days=$(($uptime/86400))
hours=$(($(($uptime%86400))/3600))
mins=$(($(($(($uptime%86400))%3600))/60))
secs=$(($(($(($uptime%86400))%3600))%60))
printf "%-5.5s%d %5d days, %02d:%02d:%02d | %-25.25s %s\n" $this $count $days $hours $mins $secs $sys $upfrom
done
printf "\033[0m"
echo "----------------------------+---------------------------------------------------"
| al momento è proprio banale ma conto di aggiungere statistiche e altre amenità
Suggerimenti, consigli o commenti ? _________________ Le tre grandi virtù di un programmatore: pigrizia, impazienza e arroganza. (Larry Wall).
Prima di postare un file togli i commenti con | Code: | | grep -vE '(^[[:space:]]*($|(#|!|;|//)))' |
|
|
| Back to top |
|
 |
Cristian75 Apprentice

Joined: 30 Nov 2005 Posts: 234
|
|
| Back to top |
|
 |
Kernel78 Moderator

Joined: 24 Jun 2005 Posts: 3652
|
Posted: Wed Sep 15, 2010 5:43 pm Post subject: |
|
|
| Cristian75 wrote: | | Credo che possa essere utile spiegare come si usa. |
lanci lo script
conviene metterlo in crontab ogni minuto per avere la situazione aggiornata ma se il sistema è stabile (non rischi spegnimenti catastrofici) puoi semplicemente metterlo in local.stop _________________ Le tre grandi virtù di un programmatore: pigrizia, impazienza e arroganza. (Larry Wall).
Prima di postare un file togli i commenti con | Code: | | grep -vE '(^[[:space:]]*($|(#|!|;|//)))' |
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|