forked from cbsd/cbsd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnodes.subr
35 lines (29 loc) · 829 Bytes
/
nodes.subr
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
#update idle in SQLite for $1 nodename
idle_update()
{
cbsdsql nodes "update nodelist set idle=datetime('now','localtime') where nodename=\"${1}\""
}
# check age of ssh mux lock. If ctime greater than 1 minutes
# then out "Connected (uptime min)" and return 0
# else - out "Offline" and return 1
# required included inventory for $sqlreplica
# sample:
# if check_locktime /usr/jails/ftmp/shmux_199.48.133.74.lock >/dev/null 2>&1; then
# echo "OK"
# fi
check_locktime()
{
#always return online if no shmux activated
[ "${sqlreplica}" = "0" ] && return 0
local cur_time=$( /bin/date +%s )
local difftime
[ ! -f "${1}" ] && return 1
eval $( stat -s ${1} )
difftime=$(( ( cur_time - st_mtime ) / 60 ))
if [ $difftime -lt 1 ]; then
return 1
else
echo "$difftime"
return 0
fi
}