简体   繁体   English

继续远程bash脚本

[英]Continue remote bash script

I'm only an apprentice in my first year and this is my first post, so please bear with me. 第一年我只是一个学徒,这是我的第一篇文章,所以请多多包涵。

First of all: We use Raspberry Pi's with stretch distribution. 首先:我们使用具有拉伸分布的Raspberry Pi。

With every update we roll out we have to do release tests. 每次发布更新时,我们都必须进行发布测试。 Normally one has to execute certain commands manually and remotely on the Pi's via ssh and compare the outcome with what it should be, if the new release works. 通常情况下,如果新版本有效,则必须通过ssh在Pi上手动并远程执行某些命令,并将结果与​​应该的结果进行比较。 I'm currently working on automating this process with a bash script which works fine so far. 我目前正在使用bash脚本来实现此过程的自动化,目前为止效果还不错。

However, at various points we have to create certain flagfiles that initiate certain processes and reboot the Pi afterwards so it detects the flagfiles and executes the processes. 但是,在很多时候,我们必须创建某些标志文件来启动某些进程,然后再重新启动Pi,以便它检测到标志文件并执行进程。 The problem is that rebooting of course ends my script. 问题是重启当然会结束我的脚本。

Now I know that you can just write a cronjob that executes a script @reboot or write a function in your script that checks for states and then executes the "after-reboot" part of your script, but these solutions all require the scripts being locally on the Pi, if I understood them correctly. 现在,我知道您可以编写一个cronjob来执行一个脚本@reboot或在您的脚本中编写一个检查状态的函数,然后执行脚本的“重启动后”部分,但是这些解决方案都要求脚本在本地如果我正确理解它们,请在Pi上进行。 But I have to run my scipts remotely via ssh from my office PC with sourcing my config and handover parameters and such. 但是我必须从办公室PC上通过ssh远程运行scipts,并提供配置和切换参数等。

This is what I run in my start script: 这是我在启动脚本中运行的内容:

#!/bin/bash
CONFIG=/home/user/Schreibtisch/config.sh
source $CONFIG
echo "Release AutoTest V0.7 on $DEVICE_ID"
echo "Make sure an external WLAN chip is plugged in"
read -p "Press ENTER to start"
ssh root@$DEVICE_IP "bash -s" -- < /home/user/Schreibtisch/auto_test.sh "$PMD" "$BTDMD" "$AND TEN MORE PARAMETERS..."

exit 0

The "auto_test.sh" is the actual script that runs on the Pi. “ auto_test.sh”是在Pi上运行的实际脚本。

So is there a way to "tell" my local script is has to wait for the reboot and then start the next portion or anything? 那么,有没有一种方法可以“告诉”我的本地脚本以等待重新启动,然后开始下一部分或其他操作? Or just being able to go back to my "auto_start.sh" for which I could write an after reboot part and giving the Pi a second script after a sleep of 40 or something. 或者只是能够回到我的“ auto_start.sh”,为此我可以编写一个重启后的部分,并在睡眠40左右后给Pi提供第二个脚本。 (Or better yet a detection when the Pi is running again, but that is a thing I can work on my self.) (或者更好的是当树莓派再次运行时进行检测,但这是我可以自己进行的工作。)

After executing the script on the Raspberry Pi you can ping the Pi until it responds: 在Raspberry Pi上执行脚本后,您可以对Pi进行ping操作,直到响应为止:

#!/bin/bash
CONFIG=/home/user/Schreibtisch/config.sh
source $CONFIG
echo "Release AutoTest V0.7 on $DEVICE_ID"
echo "Make sure an external WLAN chip is plugged in"
read -p "Press ENTER to start"
ssh root@$DEVICE_IP "bash -s" -- < /home/user/Schreibtisch/auto_test.sh "$PMD" "$BTDMD" "$AND TEN MORE PARAMETERS..."
while ! ping -c 1 -n -w 1 DEVICE_IP &> /dev/null; do :; done

# Execute whatever you want after the reboot

exit 0

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM