分类 Linux 相关 下的文章

tomcat 配置在linux上, 机器重启后 自动启动

#!/bin/bash

### BEGIN INIT INFO
# Provides:        tomcat7
# Required-Start:  $network
# Required-Stop:   $network
# Default-Start:   2 3 4 5
# Default-Stop:    0 1 6
# Short-Description: Start/Stop Tomcat server
### END INIT INFO

PATH=/sbin:/bin:/usr/sbin:/usr/bin

start() {
 sh /opt/apache-tomcat-7.0.59/bin/startup.sh
}

stop() {
 sh /opt/apache-tomcat-7.0.59/bin/shutdown.sh
}

case $1 in
  start|stop) $1;;
  restart) stop; start;;
  *) echo "Run as $0 <start|stop|restart>"; exit 1;;
esac

chmod 755 /etc/init.d/tomcat7
update-rc.d tomcat7 defaults

另外一种写法

 #!/bin/sh
 #tomcat auto-start
 case $1 in
        start)
            sh /opt/apache-tomcat-7.0.59/bin/startup.sh;;
        stop)
            sh /opt/apache-tomcat-7.0.59/bin/shutdown.sh;;
        restart)
            sh /opt/apache-tomcat-7.0.59/bin/shutdown.sh
            sh /opt/apache-tomcat-7.0.59/bin/startup.sh;;
        *)
            echo 'Usage:tomcat7 start|stop|restart';;
    esac
    exit 0

从这里抄过来的: http://askubuntu.com/questions/223944/how-to-automatically-restart-tomcat7-on-system-reboots

Bash Pocket Reference - History

1979 年 随Unix V7 发布的 Bourne Shell变成了shell 脚本的标准, 如今许多商用 Unix 上还可以发现 /bin/sh.

因为 Berkeley C shell (csh) 提供了更多用于交互的特性, 如 command history, job control, 很长一段时间, Unix 上Bourne shell 都用作编程, Berkeley C shell 用作交互;
贝尔实验室的 David Korn 不断的给 Bourne Shell 提供增强的特性, 最后超过了 Bourne Shell 和 Berkeley C shell, 并且兼容前二者;
如今 POSIX 定义的 标准Shell 基于 Bourne Shell, 并且从 Korn Shell 中提取一部分特性;

The Free Software Foundation, in keeping with its goal to produce a complete Unix work-alike system, developed a clone of the Bourne shell, written from scratch, named “Bash,” the Bourne-Again SHell. Over time, Bash has become a POSIX-compliant version of the shell with many additional features overlapping those of the Korn shell, but Bash is not an exact Korn shell clone. Today, Bash is arguably the most widely used Bourne-derived shell.

linux 命令行中的 - 和 --

我们经常见到类似下面的:

 ls -a        #short option
 ls --all     #long  option

有些程序使用short options, 有些使用long options, 有些既有short, 又有long.
据说一开始都是使用short options, 后来有些程序的选项特别多,以至于short options 都不够了, 或者有些options的首字母是一样的, 就产生了long options.
一般来说short options用来日常的敲命令, long options 一般使用在脚本里面, 可读性更好.

但是, 有时候, 你可能也会看到下面的这2种:

 tar -cvf - .
 ls -- $FILE_NAME  #before:  export FILE_NAME='--version'

第一个tar 命令看似不好理解, 让我们先看一个正常的:
tar -cvf a.tar file1 file2 #archive file1, file2 成a.tar
对比上面的命令, "-" 相当于 a.tar, 后面的 "." 相当于要archive的文件.
在一些命令行命令中, "-" 用来指代 stdin, 或者stdout.
所以上面的命令意思是: 把当前路径下的文件archive的包输出到stdout. (当然你可以用管道接着处理).
但是注意, 这个不是bash规定的, 而是应用程序自己设置的.

第二个ls命令中间有2个横线 -- (两边都有空格).
英文称: double dash, bare double dash, double hyphen.
这个ls命令的意思是: 列出文件 "--version"的信息, 这里有个文件名字偏偏叫做: "--version".
或者你使用git的时候, 会遇到 git diff origin master -- path/to/file
为什么这里会有2个横线呢? 其实这2个横线是告诉命令行, 后面的字符不是命令行选项, 可以作为一般的字符理解
如果不用 "--":

  • ls 那个命令将变为 ls --vesion, 只能打印ls的版本信息, 不能显示文件 "--version"的信息.
  • git diff 命令可能会遇到 git diff origin master master (后一个master是一个文件名).