如果关闭时出错,则重新加载浏览器的bash脚本

如果关闭时出错,则重新加载浏览器的bash脚本,bash,shell,raspberry-pi2,Bash,Shell,Raspberry Pi2,我在屏幕上运行树莓Pi 2来显示一个网站。Epiphany浏览器有时会意外关闭 我正在尝试创建一个脚本,如果浏览器出现故障,它将重新加载浏览器,我遇到的问题是,有一些xdotool命令在之后运行,我无法确定要放在哪里 以下是我到目前为止的情况: #!/bin/bash until epiphany "http://localhost/index.php" ; do echo "Service 'epiphany' crashed with exit code #?. Respawning...

我在屏幕上运行树莓Pi 2来显示一个网站。Epiphany浏览器有时会意外关闭

我正在尝试创建一个脚本,如果浏览器出现故障,它将重新加载浏览器,我遇到的问题是,有一些xdotool命令在之后运行,我无法确定要放在哪里

以下是我到目前为止的情况:

#!/bin/bash

until epiphany "http://localhost/index.php" ; do
echo "Service 'epiphany' crashed with exit code #?. Respawning..." >&2
sleep 1
done
此脚本将运行,打开浏览器,并在进程终止时重新加载浏览器。启动后,我需要运行以下程序:

sleep 10
xdotool search --class epiphany windowactivate
xdotool key F11
这使得《顿悟》全屏放映

while ps ax | grep -v grep |epiphany ; do
sleep 60
echo "Refreshing page"
xdotool search --class epiphany windowactivate
xdotool key F5
done
这会在一分钟后刷新屏幕,并每60分钟重复一次

我没有刷新网页本身的原因是,如果网络中断,它将在屏幕上显示未找到的页面,并且不会再次重试


感谢您的阅读。

您可能可以将它们组合成一个脚本。 这将是组合文件:

combined.sh:

#/bin/bash

epiphany "http://localhost/index.php" &
sleep 10
xdotool search --class epiphany windowactivate
xdotool key F11

while ps ax | grep -v grep |epiphany ; do
sleep 60
echo "Refreshing page"
xdotool search --class epiphany windowactivate
xdotool key F5
done
service.sh

#/bin/bash

until combined.sh ; do
echo "Service 'epiphany' crashed with exit code #?. Respawning..." >&2
sleep 1
done

我正在做这件事,我没有一个树莓测试,但它应该工作。直到epiphany关闭,第一个脚本才会停止,当它关闭时,combined.sh会再次执行。

下面是我最后提出的解决方案:

screen.sh

#!/bin/bash
if [ -a /home/pi/.config/epiphany/session_state.xml ];
     then
     rm /home/pi/.config/epiphany/session_state.xml;
fi

epiphany "http://localhost/index.php" &
sleep 10
xdotool search --desktop 0 --class epiphany-browser windowactivate
xdotool key F11

while ps ax |grep -v grep| grep epiphany; do
sleep 30
xdotool search --desktop 0 --class epiphany-browser windowactivate
xdotool key F5
done
web.sh

#!/bin/bash
/home/pi/screen.sh &
wait
until /home/pi/screen.sh; do
echo "Epiphany has closed in error, respawning..."
sleep 1
done
如果您终止epiphany的pid,它将在下一个刷新周期(30秒)重新启动浏览器


如果关闭浏览器,它将退出该过程。

如果要在不使用其他工具的情况下运行Ephiphone maximized(非全屏),并在崩溃时重新启动:

#!/bin/bash
#script that runs Ephipany browser and restarts it if it crashes.

WEBPAGEDIR=/home/pi/bin/WebPage
LOGFILE="$WEBPAGEDIR/WebPage_$(date '+%Y%m').log"

function log {
    LogStr="[$(date '+%F %X')] $1"
    echo "$LogStr"
    echo "$LogStr" >> "$LOGFILE"
}

function rmfile {
    rm "$WEBPAGEDIR/$1" &>/dev/null
}

function runBrowser {
    log "Starting browser"

    #-- delete old Epiphany session files so browser starts maximized
    rmfile states.xml
    rmfile session_state.xml~
    rmfile session_state.xml
    rmfile bookmarks.rdf
    rmfile cookies.sqlite
    rmfile ephy-*

    epiphany -a --profile="$WEBPAGEDIR" "$WEBPAGEDIR/index.html" &> /dev/null

    return $?
}

log "----------------"
log "New Session"


#-- start browser.  Restart it if it crashes --------- 
until runBrowser; do
    log "Browser crashed with exit code $?.  Restarting browser ..."
    sleep 1
done

# --- exit -----------------
log "Ended Session"
exit 0

我必须修改service.sh直到~/combined.sh,否则它会说找不到命令。combined.sh本身运行良好,但是当运行service.sh时,当epiphany严重终止时,combined.sh关闭,没有其他情况发生。您可以在48(?)小时后接受自己的答案,以获得宝贵的声誉积分。好的Q和As,继续发帖!