是否可以通过 mint 自动重启 5 个循环?
Is it possible to auto reboot for 5 loops through mint?
我目前正在使用以下命令运行重启
sudo shutdown -r now
然而,我需要在执行其他一些程序之前和之后 运行 它进行 5 个循环。想知道是否可以在 MINT 环境中执行此操作?
首先是免责声明:我还没有尝试过这个,因为我现在不想重新启动我的机器...
无论如何,我们的想法是制作一个脚本,可以按照@david-c-rankin 的建议跟踪它对文件的迭代进度。这个 bash 脚本可能看起来像这样(我测试过这个):
#!/bin/sh
ITERATIONS="5"
TRACKING_FILE="/path/to/bootloop.txt"
touch "$TRACKING_FILE"
N=$(cat "$TRACKING_FILE" | wc -c)
if [ "$N" -lt "$ITERATIONS" ]; then
printf "." >> "$TRACKING_FILE"
echo "rebooting (iteration $N)"
# TODO: this is where you put the reboot command
# and anything you want to run before rebooting each time
else
rm "$TRACKING_FILE"
# TODO: other commands to resume anything required
fi
然后在启动时 运行 所在的位置添加对此脚本的调用。例如。 cron (@reboot) 或 systemd。不要忘记在完成或下次重新启动时从 startup/boot 命令中删除它,它将重新启动 N 次。
不确定您打算如何使用它,但一般工作流程如下:
- 将脚本保存到
/path/to/reboot_five_times.sh
- 在启动时将脚本添加到 运行(cron 等)
- 做事(手动或在脚本中)
- 调用脚本
- 计算机重启 5 次
- 脚本第二个 TODO 部分中的任何内容都是 运行
- 返回第 3 步,或者如果已完成,请从 cron/systemd 中删除,这样它就不会在您不希望重新启动时重新启动。
首先在你想要的地方创建一个文本文档,我在桌面上创建了一个,
然后用这个文件作为物理计数器,写一个守护进程文件到运行 things at startup
例如:
#!/bin/sh
var=$(cat a.txt)
echo "$var"
if [ "$var" != 5 ]
then
var=$((var+1))
echo "$var" > a.txt
echo "restart here"
sudo shutdown -r now
else
echo "stop restart"
echo 0 > a.txt
fi
希望对您有所帮助
我找到了一种在启动时为我的重启脚本创建文件的方法。我将它与 swalladge 和 shubh 提供的答案结合起来。非常感谢!
#!/bin/bash
#testing making a startup application
echo "
[Desktop Entry]
Type=Application
Exec=notify-send success
Hidden=false
NoDisplay=false
X-GNOME-Autostart-enabled=true
Name[en_CA]=This is a Test
Name=This is a Test
Comment[en_CA]=
Comment=" > ~/.config/autostart/test.desktop
我目前正在使用以下命令运行重启
sudo shutdown -r now
然而,我需要在执行其他一些程序之前和之后 运行 它进行 5 个循环。想知道是否可以在 MINT 环境中执行此操作?
首先是免责声明:我还没有尝试过这个,因为我现在不想重新启动我的机器...
无论如何,我们的想法是制作一个脚本,可以按照@david-c-rankin 的建议跟踪它对文件的迭代进度。这个 bash 脚本可能看起来像这样(我测试过这个):
#!/bin/sh
ITERATIONS="5"
TRACKING_FILE="/path/to/bootloop.txt"
touch "$TRACKING_FILE"
N=$(cat "$TRACKING_FILE" | wc -c)
if [ "$N" -lt "$ITERATIONS" ]; then
printf "." >> "$TRACKING_FILE"
echo "rebooting (iteration $N)"
# TODO: this is where you put the reboot command
# and anything you want to run before rebooting each time
else
rm "$TRACKING_FILE"
# TODO: other commands to resume anything required
fi
然后在启动时 运行 所在的位置添加对此脚本的调用。例如。 cron (@reboot) 或 systemd。不要忘记在完成或下次重新启动时从 startup/boot 命令中删除它,它将重新启动 N 次。
不确定您打算如何使用它,但一般工作流程如下:
- 将脚本保存到
/path/to/reboot_five_times.sh
- 在启动时将脚本添加到 运行(cron 等)
- 做事(手动或在脚本中)
- 调用脚本
- 计算机重启 5 次
- 脚本第二个 TODO 部分中的任何内容都是 运行
- 返回第 3 步,或者如果已完成,请从 cron/systemd 中删除,这样它就不会在您不希望重新启动时重新启动。
首先在你想要的地方创建一个文本文档,我在桌面上创建了一个, 然后用这个文件作为物理计数器,写一个守护进程文件到运行 things at startup
例如:
#!/bin/sh
var=$(cat a.txt)
echo "$var"
if [ "$var" != 5 ]
then
var=$((var+1))
echo "$var" > a.txt
echo "restart here"
sudo shutdown -r now
else
echo "stop restart"
echo 0 > a.txt
fi
希望对您有所帮助
我找到了一种在启动时为我的重启脚本创建文件的方法。我将它与 swalladge 和 shubh 提供的答案结合起来。非常感谢!
#!/bin/bash
#testing making a startup application
echo "
[Desktop Entry]
Type=Application
Exec=notify-send success
Hidden=false
NoDisplay=false
X-GNOME-Autostart-enabled=true
Name[en_CA]=This is a Test
Name=This is a Test
Comment[en_CA]=
Comment=" > ~/.config/autostart/test.desktop