Startup script for digital signage
I had a bit of an issue with an Ubuntu box used for digital signage where I need the machine to come up after a restart, automatically log in a user, then launch a full screen web page in Chrome.
I initially added a shell script which launched Chrome as part of the user session.
Unfortunately, this did not allow enough time for a network connection to be made.
I tried adding a sleep 20 to the script but all this did was delay the operating system from making a network connection for 20 seconds.
I also tried using &’s to return control to the operating system after the sleep command but this did not help as it moved straight onto launching chrome again.
I the end I referred to the ever green Stack Overflow and constructed a small shell script with a recursive function which checks for the presence of an IPV4 connection to a specific address and adapted this to sleep every 5 seconds until the connection is made:
check_net is a shell script function which is called by itself upon failing to connect to the target server. The IP address is shown as 192.168.0.1 but this can be any destination answering to pings.
#!/bin/bash
check_net() {
if ping -q -c 1 -W 1 192.168.0.1 >/dev/null; then
# echo "up"
google-chrome --start-fullscreen --password-store=basic
else
# echo "down"
sleep 5
check_net
fi
}
check_net