sh/bash/dash/ksh/zsh等Shell脚本
-
费升格
- 帖子: 14
- 注册时间: 2010-02-27 23:00
#1
帖子
由 费升格 » 2012-12-23 14:32

最近一直在研究服务器。接触了很多。
不过 我开启的java程序经常会有内存泄漏。所以,我想要一个脚本来定时重启。
不过有一个难题。
1.我是通过screen 来建立一个后台java程序。 运行后,输入框会成为该java程序。就是说,只能输入java程序的命令。
2.如果我直接重启的话,后台运行着的java会因为没有保存,会导致数据丢失。
所以问题是。。。。
如果在脚本执行重启命令前,脚本可否在 该java程序输入 stop 命令?。。。
这点就像win下,我用按键精灵之类,录制好过程。再将该脚本添加上计划任务,就可以实现定时 保存重启了。
-
tusooa
- 帖子: 6548
- 注册时间: 2008-10-31 22:12
- 系统: 践兔
-
联系:
#2
帖子
由 tusooa » 2012-12-23 20:54
信号处理嘛。
代码: 全选
● bash -c 'help trap'
trap: trap [-lp] [[arg] signal_spec ...]
Trap signals and other events.
Defines and activates handlers to be run when the shell receives signals
or other conditions.
ARG is a command to be read and executed when the shell receives the
signal(s) SIGNAL_SPEC. If ARG is absent (and a single SIGNAL_SPEC
is supplied) or `-', each specified signal is reset to its original
value. If ARG is the null string each SIGNAL_SPEC is ignored by the
shell and by the commands it invokes.
If a SIGNAL_SPEC is EXIT (0) ARG is executed on exit from the shell. If
a SIGNAL_SPEC is DEBUG, ARG is executed before every simple command. If
a SIGNAL_SPEC is RETURN, ARG is executed each time a shell function or a
script run by the . or source builtins finishes executing. A SIGNAL_SPEC
of ERR means to execute ARG each time a command's failure would cause the
shell to exit when the -e option is enabled.
If no arguments are supplied, trap prints the list of commands associated
with each signal.
Options:
-l print a list of signal names and their corresponding numbers
-p display the trap commands associated with each SIGNAL_SPEC
Each SIGNAL_SPEC is either a signal name in <signal.h> or a signal number.
Signal names are case insensitive and the SIG prefix is optional. A
signal may be sent to the shell with "kill -signal $$".
Exit Status:
Returns success unless a SIGSPEC is invalid or an invalid option is given.
bash是这样。不会java。应该也类似。最好用perl.