简单地说,我在BASH中使用Dialog来生成消息并拥有一个交互式菜单,但有一个步骤需要等待用户插入硬件设备,因此我运行了一个"尾箱",其中包含一个回显函数。
现在我只是让它回显"请退出对话框",但为了简化,我想自己关闭对话框。我已经添加了一个超时,但它是为了确保用户不会停留在该屏幕上,所以它很长。
有没有办法让它在脚本结束时,对话框休眠2 - 3秒,然后关闭?
任何帮助是非常感谢!
function initRPI { # Wait for carrier Board to be plugged in, then initialize CM Unit
echo -e "Plug in carrier board with compute module attached.\n"
pkill "rpiboot"
sleep 0.5
$FILE # Run rpiboot from where it's installed
echo -e "\nCompute Module Initialized - Exit Now."
}
function writeImage { # Find proper image and write it to device
if [[ " ${boxTypes[*]} " =~ "$boxType" ]]; then
initRPI > _temp &
dialog --backtitle "$backTitle" --fb --title "Image Writer" --timeout 60 --tailbox _temp 15 70
if pgrep -f rpiboot &> /dev/null 2>&1; then
pkill "rpiboot"
dialogMsg FAILED "Compute Module was not initialized."
else
devCM="/dev/sda"
if [ ! -d "/mnt/firmware" ]; then
mkdir /mnt/firmware
fi
mount -t nfs $nasIP/firmware /mnt/firmware
(pv -n "/mnt/firmware/${unitSerial:2:4}.img" | dd of="$devCM" bs=4M conv=notrunc,noerror) 2>&1 | dialog --gauge "Running cloning $imageName to device $1, please wait..." 10 70 0
sleep 0.5
if kill -0 "$pid" ; then
dialogMsg SUCCESS "Image $imageName written to device $1."
else
dialogMsg FAILED "Image $imageName failed to write to device $1."
fi
fi
else
dialogMsg ERROR "Can't find $boxType in the model list."
fi
}
我让它分叉rpiboot进程,所以tail只读取一个temp变量,但我必须等待用户输入在rpiboot完成时退出。
编辑:我意识到我把--timeout放在了--tailbox参数里面,所以很快地移动了一下。
1条答案
按热度按时间zd287kbt1#
我想通了。我基本上可以只删除退出按钮,用pkill "dialog"强制杀死对话框窗口。
希望这对某人有帮助!