您好,我有一个在我的 Windows 10 PC 上运行的 apache 网络服务器,带有 xampp 和一个 RaspberryPi,可以通过脚本连接到它。该脚本检查特定端口上的网络服务器是否可用,如果可用,则启动浏览器并在服务器不再可用时关闭它。这是我的脚本:
#!/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
我第一次启动网络服务器时,它会连接并启动 midori,如果我停止网络服务器,它会关闭 midori。但是,如果我再次启动网络服务器,它就不再启动 midori,我不知道为什么......
这是我的browserlog
文件:
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
在这里,我手动停止了脚本!
也许你能帮我...