Useful Scripts

Prevent Idle Shutdown

This script uses the kodi-send tool to prevent Kodi from shutting down if there are active SSH, SAMBA, or NFS connections. The script checks every 60 seconds, and if at least one connection exists the command InhibitIdleShutdown(true) is sent to Kodi.
Create /storage/.config/prevent_idle.sh with the following content:
1
#!/bin/sh
2
3
IDLE_SHUTDOWN_ALLOWED_LAST_STATE=-1
4
5
while true
6
do
7
KODI_RUNNING=`ps -A | grep kodi.bin | grep -v grep | wc -l`
8
if [ 1 == $KODI_RUNNING ] ; then
9
SSH_ACTIVE=`netstat -tnpa | grep 'tcp.*:22.*ESTABLISHED.*' | wc -l`
10
NFS_ACTIVE=`netstat -tnpa | grep 'tcp.*:111.*ESTABLISHED.*' | wc -l`
11
SMB_ACTIVE=`netstat -tnpa | grep 'tcp.*:445.*ESTABLISHED.*' | wc -l`
12
[ $SSH_ACTIVE -gt 0 -o $NFS_ACTIVE -gt 0 -o $SMB_ACTIVE -gt 0 ] && IDLE_SHUTDOWN_ALLOWED=1 || IDLE_SHUTDOWN_ALLOWED=0
13
if [ $IDLE_SHUTDOWN_ALLOWED_LAST_STATE != $IDLE_SHUTDOWN_ALLOWED ] ; then
14
IDLE_SHUTDOWN_ALLOWED_LAST_STATE=$IDLE_SHUTDOWN_ALLOWED
15
kodi-send --action="AllowIdleShutdown"
16
if [ 0 == $IDLE_SHUTDOWN_ALLOWED ] ; then
17
kodi-send --action="InhibitIdleShutdown(false)"
18
else
19
kodi-send --action="InhibitIdleShutdown(true)"
20
fi
21
fi
22
fi
23
sleep 60
24
done
Copied!
Call the script from /storage/.config/autostart.sh so it runs as a background task. It will continue to monitor the state of connections until the device is halted.
1
(
2
/usr/bin/bash /storage/.config/prevent_idle.sh
3
)&
Copied!

DYNU IP Updater

This script identifies your public IP address and updates a https://dynu.com Dynamic DNS record.
Create /storage/.config/dynu_update.sh with the following content:
1
#!/bin/sh
2
3
DYNU_USERNAME="username"
4
DYNU_PASSWORD="password-hash"
5
DYNU_HOSTNAME="example.dynu.com"
6
REFRESH_RATE=60
7
8
PUBLIC_IP=0.0.0.0
9
10
test_ip ()
11
{
12
if [ -n $2 ] ; then
13
if [ $1 != $2 ] ; then
14
update_ip $2
15
echo $2
16
else
17
echo $1
18
fi
19
fi
20
}
21
22
update_ip ()
23
{
24
DYNU_WGET="https://api.dynu.com/nic/update?hostname=$DYNU_HOSTNAME&myip=$1&username=$DYNU_USERNAME&password=$DYNU_PASSWORD"
25
DYNU_UPDATE=`wget $DYNU_WGET -O - -q ; echo`
26
(>&2 echo "$DYNU_UPDATE")
27
}
28
29
while true; do
30
PUBLIC_IP_TEST=`wget http://ipecho.net/plain -O - -q ; echo`
31
echo $PUBLIC_IP - $PUBLIC_IP_TEST
32
PUBLIC_IP="$(test_ip $PUBLIC_IP $PUBLIC_IP_TEST)"
33
sleep $(REFRESH_RATE)
34
PUBLIC_IP_TEST=`curl -s checkip.dyndns.org | sed 's#.*Address: \(.*\)</b.*#\1#'`
35
echo $PUBLIC_IP - $PUBLIC_IP_TEST
36
sleep $(REFRESH_RATE)
37
PUBLIC_IP_TEST=`curl -s ifconfig.co`
38
echo $PUBLIC_IP - $PUBLIC_IP_TEST
39
PUBLIC_IP="$(test_ip $PUBLIC_IP $PUBLIC_IP_TEST)"
40
sleep $(REFRESH_RATE)
41
done
Copied!
Call the script from /storage/.config/autostart.sh so it runs as a background task. It will continue to monitor the state of connections until the device is halted.
1
(
2
/usr/bin/bash /storage/.config/dynu_update.sh
3
)&
Copied!
Note: If you set the refresh rate under 60 seconds the checkip.dyndns.org server will probably block your requests causing the script to fail.
Last modified 11mo ago
Export as PDF
Copy link