prd_ajudaremota 1.25 KB
Newer Older
Vinicius Ruoso's avatar
Vinicius Ruoso committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
#!/bin/bash

if grep -q none <<< $(hostname); then
    printf "STATUS+ONLINE\n"
    printf "PRD_VERSION+Ajuda Remota\n"

    ZONE="/prd/prd.zone"

    ZONEERROR=true
    if ! test -f $ZONE; then
        printf "PRD_SCHOOLINFO+NOZONE\n"
    else
        IP=$(/usr/sbin/ifconfig |grep "inet" |awk -F: '{print $2}' | \
            awk '{print $1}')
        SCHOLL="$(grep "\<$IP\>" "$ZONE")"
        if test -z "$SCHOLL"; then
            printf "PRD_SCHOOLINFO+NOINFO\n"
        else
            ZONEERROR=false
            DATA=$(cut -d';' -f2- <<< $SCHOLL |tr '_' ' '|tr '[A-Z]' '[a-z]'| \
                   sed -e 's#^\(.\)#\u\1#' -e 's#:\(.\)#:\u\1#g' \
                   -e 's# \(.\)# \u\1#g')

            NRE=$(cut -d: -f1 <<< $DATA)
            CITY=$(cut -d: -f2 <<< $DATA)
            NAME=$(cut -d: -f3 <<< $DATA)
        fi
    fi

    test "$ZONEERROR" = false &&
        printf "PRD_CITY+$CITY\n" &&
        printf "PRD_NAME+$NAME\n" &&
        printf "PRD_NRE+$NRE\n"

    while true; do
        UPSEC=$(cat /proc/uptime |cut -d. -f1)
        ((UPDAYS=UPSEC/60/60/24))
        ((UPHOURS=UPSEC/60/60 - UPDAYS*24))
        ((UPMINUTES=UPSEC/60 - UPHOURS*60 - UPDAYS*24*60))
        printf "UPTIME+$UPDAYS days, $UPHOURS:$UPMINUTES\n"
        sleep 1800
    done
fi