linux rc.local 添加日志,Linux rc.d路径下文件执行时候把日志输出到log

有时我们自己在/etc/rc.d/rc.local里面增加的随机器启动的脚本和指令总是不能自动加载和启动,类似的还有/etc/rc.d/init.d里面的各种系统启动项,

机器启动后手动执行脚本又能成功,经常被搞得晕头转向的。经过测试和查找资料,终于解决了这问题,解决方式如下

/etc/rc.d/rc.local文件的文件头是#!/bin/sh ,我们把这修改成#!/bin/sh -x,这样系统启动后就会把/etc/rc.d/rc.local里面的指令或脚本不能执行的日志写入/var/log/messages

,我们查看messages文件内容就知道具体的问题出在哪里了

--

例如 /etc/rc.d/init.d/tomcat8   的出错日志如下

Oct  8 15:54:49 iZ23psiz6rgZ tomcat8: ++ expr 'lrwxrwxrwx 1 root root 59 Oct  8 15:18 /etc/rc.d/init.d/tomcat8 -> /usr/programfile/tomcat/apache-tomcat-8.0.27/bin/startup.sh' : '.*-> \(.*\)$'

Oct  8 15:54:49 iZ23psiz6rgZ systemd: Started OpenSSH server daemon.

Oct  8 15:54:49 iZ23psiz6rgZ tomcat8: + link=/usr/programfile/tomcat/apache-tomcat-8.0.27/bin/startup.sh

Oct  8 15:54:49 iZ23psiz6rgZ tomcat8: + expr /usr/programfile/tomcat/apache-tomcat-8.0.27/bin/startup.sh : '/.*'

Oct  8 15:54:49 iZ23psiz6rgZ tomcat8: + PRG=/usr/programfile/tomcat/apache-tomcat-8.0.27/bin/startup.sh

Oct  8 15:54:49 iZ23psiz6rgZ tomcat8: + '[' -h /usr/programfile/tomcat/apache-tomcat-8.0.27/bin/startup.sh ']'

Oct  8 15:54:49 iZ23psiz6rgZ tomcat8: ++ dirname /usr/programfile/tomcat/apache-tomcat-8.0.27/bin/startup.sh

Oct  8 15:54:49 iZ23psiz6rgZ tomcat8: + PRGDIR=/usr/programfile/tomcat/apache-tomcat-8.0.27/bin

Oct  8 15:54:49 iZ23psiz6rgZ tomcat8: + EXECUTABLE=catalina.sh

Oct  8 15:54:49 iZ23psiz6rgZ tomcat8: + false

Oct  8 15:54:49 iZ23psiz6rgZ tomcat8: + '[' '!' -x /usr/programfile/tomcat/apache-tomcat-8.0.27/bin/catalina.sh ']'

Oct  8 15:54:49 iZ23psiz6rgZ tomcat8: + exec /usr/programfile/tomcat/apache-tomcat-8.0.27/bin/catalina.sh start start

Oct  8 15:54:49 iZ23psiz6rgZ tomcat8: Neither the JAVA_HOME nor the JRE_HOME environment variable is defined

Oct  8 15:54:49 iZ23psiz6rgZ tomcat8: At least one of these environment variable is needed to run this program

说明在tomcat8里面需要定义JAVA_HOME 环境变量(此时系统还未启动完毕,JAVA_HOME尚未被定义)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值