Hello I have an apache webserver running on my Windows 10 PC with xampp and a RaspberryPi to connect to it with a script. The script checks if the webserver is available on specific port and if ist available start the browser and close it if the server is not available anymore. Here's my Script:
#!/bin/bash
### BEGIN INIT INFO
# Provides: browerstartup.sh
# Required-Start:
# Required-Stop:
# Should-Start:
# Should-Stop:
# X-Start-Before:
# X-Stop-After:
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# X-Interactive:
# Short-Description: If connection available, connecT!
# Description: If connection is available on port 80: Then connect.
### END INIT INFO
server="192.168.16.74"
sleep=10
while [ true ] ; do
echo "Script start" >> /home/pi/browserlog
midori=$(pgrep "midori")
nc -w 5 -z $server 80 >/dev/null 2>&1
if [ $? -ne 0 ] ; then
echo "Server isnt running!" >> /home/pi/browserlog
if [ $midori ] ; then
echo "Midori is still running but server is offline: Killing midori"
kill $midori
fi
else
echo "Server is running!" >> /home/pi/browserlog
if ! [ $midori ] ; then
echo "Starting midori" >> /home/pi/browserlog
midori -e Fullscreen -a http://$server/Website/t1&
fi
fi
echo "Sleep $sleep" >> /home/pi/browserlog
sleep $sleep
done
The first time I start the webserver it connects and starts midori and if I stop the webserver it closes midori. But if I start the webserver again it doesnt start midori any more and I have no idea why...
Here is my browserlog
file:
Script start
Server is running!
Starting midori
Sleep 10
Script start
Server is running!
Starting midori
Sleep 10
Script start
Server is running!
Starting midori
Sleep 10
Script start
Server is running!
Starting midori
Sleep 10
Script start
Server is running!
Starting midori
Sleep 10
Script start
Server is running!
Starting midori
Sleep 10
Script start
Server is running!
Starting midori
Sleep 10
Script start
Server is running!
Starting midori
Sleep 10
Script start
Server is running!
Starting midori
Sleep 10
Script start
Server is running!
Starting midori
Sleep 10
Script start
Server is running!
Starting midori
Sleep 10
Script start
Here I stopped the script manually!
Maybe you can help me...