#!/bin/sh

unique_append()
{
	grep -qF "$1" "$2" || echo "$1" >> "$2"
}

mSc="net_stats"

uci set shared-state.${mSc}=dataType
uci set shared-state.${mSc}.name='net-stats'
uci set shared-state.${mSc}.scope='community'
uci set shared-state.${mSc}.ttl='1200'
uci set shared-state.${mSc}.update_interval='120'
uci commit shared-state

unique_append \
	'*/3 * * * * ((sleep $(($RANDOM % 120)); shared-state-async insert net-stats < /tmp/shared-state/network_statistics.json &> /dev/null)&)' \
	/etc/crontabs/root
