在linux中如何在给定时间关闭firefox?
挑战在于能够在给定的时间关闭firefox,保护一个人不受其“网瘾”的影响,并确保夜间休息 在这种情况下,我的搭档要求在22点关闭firefox,因为她晚上熬夜,第二天又累了。 当她碰巧想在22点后打开firefox时,在她打开firefox 15分钟后自动关闭它 编辑 我已经写了这个问题并给出了答案,在这里我创建了一个shell脚本,然后与linux文件集成 代码中有一个错误,即如果时间在22点之前,它仍然会增加15分钟在linux中如何在给定时间关闭firefox?,linux,firefox,Linux,Firefox,挑战在于能够在给定的时间关闭firefox,保护一个人不受其“网瘾”的影响,并确保夜间休息 在这种情况下,我的搭档要求在22点关闭firefox,因为她晚上熬夜,第二天又累了。 当她碰巧想在22点后打开firefox时,在她打开firefox 15分钟后自动关闭它 编辑 我已经写了这个问题并给出了答案,在这里我创建了一个shell脚本,然后与linux文件集成 代码中有一个错误,即如果时间在22点之前,它仍然会增加15分钟 now=$(date +'%R') KILL_DATE=$(date
now=$(date +'%R')
KILL_DATE=$(date -d "22:00 today" +'%R')
if [ "$now" > "$KILL_DATE" ]; then
KILL_DATE=$(date -d "$now today + 15 minutes" +'%R')
fi
exec echo "pkill -f firefox" | at $KILL_DATE
exec $MOZ_PROGRAM "$@"
我找到的解决方案是:
/usr/bin/
上的firefox文件复制到firefox\u now=$(date +'%R')
kill_date=$(date -d "22:00 today" +'%R')
if [ $now -gt $kill_date ]; then
kill_date=$(date -d "$now today + 15 minutes" +'%R')
fi
exec echo "pkill -f firefox" | at $kill_date
exec $MOZ_PROGRAM "$@"
可以在新文件的最后几行找到
/usr/bin/firefox\u白天
#!/bin/sh
#
# ***** BEGIN LICENSE BLOCK *****
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
#
# The contents of this file are subject to the Mozilla Public License Version
# 1.1 (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
# http://www.mozilla.org/MPL/
#
# Software distributed under the License is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
# for the specific language governing rights and limitations under the
# License.
#
# The Original Code is mozilla.org Code.
#
# The Initial Developer of the Original Code is
# Netscape Communications Corporation.
# Portions created by the Initial Developer are Copyright (C) 1998
# the Initial Developer. All Rights Reserved.
#
# Contributor(s):
# Wolfgang Rosenauer <wolfgang.rosenauer@suse.de>
# <wr@rosenauer.org>
#
# Alternatively, the contents of this file may be used under the terms of
# either the GNU General Public License Version 2 or later (the "GPL"), or
# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
# in which case the provisions of the GPL or the LGPL are applicable instead
# of those above. If you wish to allow use of your version of this file only
# under the terms of either the GPL or the LGPL, and not to allow others to
# use your version of this file under the terms of the MPL, indicate your
# decision by deleting the provisions above and replace them with the notice
# and other provisions required by the GPL or the LGPL. If you do not delete
# the provisions above, a recipient may use your version of this file under
# the terms of any one of the MPL, the GPL or the LGPL.
#
# ***** END LICENSE BLOCK *****
##
## Usage:
##
## $ mozilla [args]
##
## This script is meant to run a mozilla program from the mozilla
## rpm installation.
##
## The script will setup all the environment voodoo needed to make
## mozilla work.
cmdname=`basename $0`
##
## Variables
##
MOZ_DIST_BIN="/usr"
MOZ_DIST_LIB="/usr/lib64/firefox"
MOZ_APPNAME="firefox"
MOZ_PROGRAM="$MOZ_DIST_LIB/$MOZ_APPNAME"
MOZ_APP_LAUNCHER="$MOZ_DIST_LIB/$MOZ_APPNAME.sh"
if [ "$0" = "$MOZ_APP_LAUNCHER" ]; then
[ -h "/usr/bin/$MOZ_APPNAME" ] && \
_link=$(readlink -f "/usr/bin/$MOZ_APPNAME")
if [ "$_link" = "$MOZ_APP_LAUNCHER" ]; then
export MOZ_APP_LAUNCHER="/usr/bin/$MOZ_APPNAME"
fi
else
export MOZ_APP_LAUNCHER="/usr/bin/$MOZ_APPNAME"
fi
mozilla_lib=`file $MOZ_PROGRAM`
LIB=lib
echo $mozilla_lib | grep -q -E 'ELF.64-bit.*(x86-64|S/390|PowerPC)' && LIB=lib64
BROWSER_PLUGIN_DIR=/usr/$LIB/browser-plugins
if [ ! -d $BROWSER_PLUGIN_DIR ]; then
BROWSER_PLUGIN_DIR=/opt/netscape/plugins
fi
MOZILLA_FIVE_HOME="$MOZ_DIST_LIB"
export MOZILLA_FIVE_HOME
LD_LIBRARY_PATH=$MOZ_DIST_LIB${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}
export LD_LIBRARY_PATH
# needed for SUN Java under Xorg >= 7.2
export LIBXCB_ALLOW_SLOPPY_LOCK=1
##
if [ -z "$MOZ_PLUGIN_PATH" ]; then
export MOZ_PLUGIN_PATH=$BROWSER_PLUGIN_DIR
else
# make sure that BROWSER_PLUGIN_DIR is in MOZ_PLUGIN_PATH
echo "$MOZ_PLUGIN_PATH" | grep "$BROWSER_PLUGIN_DIR" 2>&1 >/dev/null
_retval=$?
if [ ${_retval} -ne 0 ]; then
export MOZ_PLUGIN_PATH=$MOZ_PLUGIN_PATH:$BROWSER_PLUGIN_DIR
fi
fi
# disable Gnome crash dialog (doesn't make sense anyway)
export GNOME_DISABLE_CRASH_DIALOG=1
moz_debug=0
script_args=""
pass_arg_count=0
while [ $# -gt $pass_arg_count ]
do
case "$1" in
-d | --debugger)
moz_debugger=$2;
if [ "${moz_debugger}" != "" ]; then
shift 2
moz_debug=1
else
echo "-d requires an argument"
exit 1
fi
;;
*)
# Move the unrecognized argument to the end of the list.
arg="$1"
shift
set -- "$@" "$arg"
pass_arg_count=`expr $pass_arg_count + 1`
;;
esac
done
if [ $moz_debug -eq 1 ]; then
tmpfile=`mktemp /tmp/mozargs.XXXXXX` || { echo "Cannot create temporary file" >&2; exit 1; }
trap " [ -f \"$tmpfile\" ] && /bin/rm -f -- \"$tmpfile\"" 0 1 2 3 13 15
echo "set args ${1+"$@"}" > $tmpfile
echo "run" >> $tmpfile
echo "$moz_debugger $MOZ_PROGRAM -x $tmpfile"
exec $moz_debugger "$MOZ_PROGRAM" -x $tmpfile
else
now=$(date +'%R')
kill_date=$(date -d "22:00 today" +'%R')
if [ $now -gt $kill_date ]; then
kill_date=$(date -d "$now today + 15 minutes" +'%R')
fi
exec echo "pkill -f firefox" | at $kill_date
exec $MOZ_PROGRAM "$@"
fi
#/垃圾箱/垃圾箱
#
#******开始许可证阻止*****
#版本:MPL 1.1/GPL 2.0/LGPL 2.1
#
#此文件的内容以Mozilla公共许可证版本为准
#1.1(“许可证”);除非符合以下要求,否则不得使用此文件
#执照。您可以通过以下方式获得许可证副本:
# http://www.mozilla.org/MPL/
#
#根据许可证分发的软件按“原样”分发,
#无任何明示或暗示的担保。看到许可证了吗
#适用于本协议项下权利和限制的具体语言
#执照。
#
#原始代码是mozilla.org代码。
#
#原始代码的初始开发人员是
#网景通讯公司。
#最初开发人员创建的部分为版权所有(C)1998
#最初的开发者。版权所有。
#
#投稿人:
#沃尔夫冈·罗森纳
#
#
#或者,本文件的内容可根据以下条款使用:
#GNU通用公共许可证版本2或更高版本(“GPL”),或
#GNU Lesser通用公共许可证2.1版或更高版本(“LGPL”),
#在这种情况下,GPL或LGPL的规定适用
#上面的那些。如果您希望仅允许使用此文件的版本
#根据GPL或LGPL的条款,不允许其他人
#根据MPL条款使用此文件的版本,并指出您的
#决定删除上述规定,并以通知取代
#以及GPL或LGPL要求的其他规定。如果不删除
#根据上述规定,收件人可在以下情况下使用您的本文件版本:
#MPL、GPL或LGPL中任何一项的条款。
#
#******结束许可证阻止*****
##
##用法:
##
##$mozilla[args]
##
##此脚本用于从mozilla运行mozilla程序
##rpm安装。
##
##该脚本将设置所需的所有伏都教环境
##mozilla工作。
cmdname=`basename$0`
##
##变数
##
MOZ_DIST_BIN=“/usr”
MOZ_DIST_LIB=“/usr/lib64/firefox”
MOZ_APPNAME=“firefox”
MOZ_程序=“$MOZ_DIST_LIB/$MOZ_APPNAME”
MOZ_APP_LAUNCHER=“$MOZ_DIST_LIB/$MOZ_APPNAME.sh”
如果[“$0”=“$MOZ_应用程序启动器”];然后
[-h”/usr/bin/$MOZ_APPNAME“]&&\
_link=$(readlink-f”/usr/bin/$MOZ\u APPNAME)
如果[“$\u链接”=“$MOZ\u应用程序启动器”];然后
export MOZ_APP_LAUNCHER=“/usr/bin/$MOZ_APPNAME”
fi
其他的
export MOZ_APP_LAUNCHER=“/usr/bin/$MOZ_APPNAME”
fi
mozilla_lib=`file$MOZ_程序`
LIB=LIB
echo$mozilla|u lib | grep-q-E'ELF.64位。*(x86-64 | S/390 | PowerPC)&&lib=lib64
浏览器插件目录=/usr/$LIB/浏览器插件
如果[!-d$BROWSER\u PLUGIN\u DIR];然后
浏览器\插件\目录=/opt/netscape/plugins
fi
MOZILLA_FIVE_HOME=“$MOZ_DIST_LIB”
导出MOZILLA_FIVE_主页
LD_LIBRARY_PATH=$MOZ_DIST_LIB${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}
导出LD_库路径
#Xorg>=7.2下的SUN Java需要
导出LIBXCB\u ALLOW\u SLOPPY\u LOCK=1
##
如果[-z“$MOZ_PLUGIN_PATH”];然后
导出MOZ_PLUGIN_PATH=$BROWSER_PLUGIN_DIR
其他的
#确保BROWSER_PLUGIN_DIR位于MOZ_PLUGIN_路径中
echo“$MOZ_PLUGIN_PATH”| grep“$BROWSER_PLUGIN_DIR”2>&1>/dev/null
_retval=$?
如果[${u retval}-ne 0];然后
导出MOZ_插件路径=$MOZ_插件路径:$BROWSER_PLUGIN_DIR
fi
fi
#禁用Gnome崩溃对话框(无论如何都没有意义)
导出GNOME\u禁用\u崩溃\u对话框=1
moz_debug=0
script_args=“”
通过参数计数=0
而[$#-gt$pass\u arg\u count]
做
案件“$1”
-d |——调试器)
moz_调试器=$2;
如果[“${moz_debugger}”!=”;然后
班次2
moz_debug=1
其他的
echo“-d需要一个参数”
出口1
fi
;;
*)
#将无法识别的参数移到列表的末尾。
arg=“$1”
转移
设置--“$@”$arg
pass_arg_count=`expr$pass_arg_count+1`
;;
以撒
完成
如果[$moz_debug-eq 1];然后
tmpfile=`mktemp/tmp/mozargs.XXXXXX`| |{echo“无法创建临时文件”>&2;退出1;}
陷阱“[-f\”$tmpfile\”]&&&/bin/rm-f--“$tmpfile\”0112 3 13 15
echo“set args${1+”$@“}”>$tmpfile
回显“运行”>$tmpfile
echo“$moz_调试器$moz_程序-x$tmpfile”
exec$moz_调试器“$moz_程序”-x$tmpfile
其他的
现在=$(日期+'%R')
kill_date=$(日期-d“今天22:00”+“%R”)
如果[$now-gt$kill_date];然后
kill_date=$(日期-d“$now today+15分钟”+'%R')
fi
exec echo“pkill-f firefox”|在$kill|u日期
exec$MOZ_程序“$@”
fi
Stack Overflow是一个关于编程和开发问题的网站。这个问题似乎离题了,因为它与编程或开发无关。请参见帮助中心中的。也许或者会是一个更好的提问的地方。不是关于编程?设置shell脚本称为什么