已经过去很长时间了,我对自己的命令已经生疏了。
我使用脚本来进行提醒。我运行的一个会显示“流星雨发生在午夜之后”。3小时后。
有没有办法防止我意外关闭正在运行计时器脚本的终端?
更新:
这是我的脚本。
#!/bin/bash
#
# Sound alarm after specifying time and message
# Must input time delay AND message in double quotes !!
#
#
# ** sleep can also accept intergers ex. sleep 7.63
# Made alias for it type al
# Print a trace of simple commands, for commands, case commands, select commands,
# and arithmetic for commands and their # arguments or associated word lists after they are expanded
# and before they are executed. The value of the PS4 variable is # expanded and the resultant value is printed before the # command and its expanded arguments.
Red='\e[0;31m'
BRed='\e[1;31m'
BIRed='\e[1;91m' # ${BIRed} this works
Gre='\e[0;32m'
BGre='\e[1;32m'
BBlu='\e[1;34m' # ${BBlu}
BWhi='\e[1;37m'
Black='\e[0;30'
BWhite='\e[0m 1;37'
# This defines a variable containing the ANSI escape sequence to clear
# the effect of all previous ANSI escape sequences that define formatting (colors, underlining, etc).
RCol='\e[0m';
soundfile="/usr/share/sounds/My_Sounds/Alarm_Clock_Sound.mp3"
clear
amixer -D pulse sset Master 40% > /dev/null 2>&1
if [ -f "$soundfile" ];
then
echo -e "${BGre}Soundfile is present."
else
echo "File $soundfile does NOT exist."
echo
echo "Program will now exit."
exit
fi
[ -z "$2" ] && {
echo
echo -e " ${BIRed}Error!! No time value given and/or message specified !!"
echo
echo -e " ${BBlu}Alarm Program 2018 ${RCol}"
echo
echo -e " alarm.sh [time value in seconds] Message in double Quotes";
echo -e " alarm 5m = 5 minute alarm"
echo -e " alarm 5h = 5 hour alarm"
echo -e " alarm 5d = 5 day alarm"
echo -e " alarm 1.5m = 1 minute 30 seconds alarm"
echo
echo -e " alarm.sh 1m "\"Take bread out of oven."\""
echo
exit 1; }
echo -e "\033[32;5mTIMER COUNTING DOWN to $1 \033[0m"
sleep $1
{
for ((volume = 15; volume <= 35; volume += 2)); do
# 2> /dev/null suppresses messages for amixer AND (c)vlc
amixer -D pulse sset Master ${volume}% > /dev/null
sleep .5
done
} &
mpg123 $soundfile > /dev/null 2>&1
#set back to original volume
amixer -D pulse sset Master %30
gxmessage -fg blue -font 'sans 20' -timeout 2 ' Tea is ready. !!'
您可以使用以下命令将脚本作为守护进程运行
daemon
,该命令在后台运行脚本:要停止守护进程:
要安装守护进程:
您需要做的唯一一件事是修改脚本以通过以下方式发送消息
notify-send
(如您的问题中所述):notify-send -u critical -t 0 "Meteor shower occurs after midnight."
当您使用
-u critical -t 0
选项时,通知将保留在屏幕上,直到您单击它。或者,您可以使用
nohup
:nohup ./yourscript &
您仍然需要修改脚本以通过
notify-send
上述方式发送消息。根据您显示文本的方式,这可能适合您,也可能不适合您。但更一般地说,这是保持某些东西运行的有效方法。
您可以使用tmux。您需要使用 来安装它
sudo apt update && sudo apt install tmux
。tmux
安装后,您可以通过在 shell 中运行来启动 tmux 会话。进入会话后,您可以运行命令,然后执行Ctrl+B操作D以隐藏会话。但是,一旦隐藏,即使关闭终端,您也可以通过tmux a
从 shell 运行来返回到会话。您可以从 tmux 会话中运行exit
,然后退出它。这实际上并不能阻止它被关闭。但是,即使您关闭终端窗口,它也会保持运行,因此这可能足以满足您的用例。