linux开机在rc.local中执行程序并利用log4c记录日志在/var/log/下的问题

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了linux开机在rc.local中执行程序并利用log4c记录日志在/var/log/下的问题相关的知识,希望对你有一定的参考价值。

我用log4crc设定每个日志文件大小为2M,并可以最多记录3个,即应该开机执行到rc.local执行代码后开始在/var/log/下记录程序的日志并命名为a.0,应该到2M自动变成a.1然后新的日志继续记录在一个新的a.0中,但是我碰到的情况是a.1没出现,a.0清空又重新开始记录了,应该如何解决?我把程序进程kill掉再重启就很正常了,a.0日志到了2M就变成a.1然后最新的日志内容又会记录在新建的a.0中,为什么开机执行就不行了?该如何解决?请大神指教!谢谢!

是不是开机脚本运行有问题,或者说这个程序需要再某些程序启动后执行,你开机的时候执行早了追问

先谢谢您的答案 不过我在rc2.d设定的rc.local已经是S99最后一个启动的啦 不知道有没有说法就是/var/log/在什么时候才开始生效...系统的问题有时候真是很头疼...

参考技术A 呢逗你玩

linux开机自动执行命令或自动启动程序(rc.local)

linux开机的最后会执行/etc/rc.local,因此可以在此脚本里面添加shell命令自动执行或者自动启动某个进程。
比如

自动输出信息:

#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.

echo "hello world!"

exit 0

另一个例子

#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.

/usr/local/bin/gen-friendlyelec-release   #执行程序
. /etc/friendlyelec-release               #执行程序
if [ ! -f /etc/firstuse ]; then           #-f作用是判断/etc/firstuse是否为一般文件 !作用是取反
    /bin/echo $BOARD > /etc/hostname
    /bin/sed -i "s/\\(127.0.1.1\\s*\\).*/\\1$BOARD/g" /etc/hosts
    /bin/hostname $BOARD
    /bin/echo "0" > /etc/firstuse
fi

if [ -e /usr/bin/setqtenv ]; then         #-e作用是判断/usr/bin/setqtenv是否存在  
. /usr/bin/setqtenv
/usr/bin/lcd2usb_print "CPU: CPU" "Mem: MEM" "IP: IP" "LoadAvg: LOADAVG" 2>&1 > /dev/null&
#/opt/QtE-Demo/run.sh&
fi

exit 0

自动执行另一个shell脚本

#!/bin/sh

sh /etc/init.d/S100auto_wifi_link.sh
echo "wifi finish!!"

以上是关于linux开机在rc.local中执行程序并利用log4c记录日志在/var/log/下的问题的主要内容,如果未能解决你的问题,请参考以下文章

Linux系统中设置开机自动执行的命令

Linux开机启动文件rc.local无法执行怎么办?

Linux开机启动程序rc.local

linux开机自动执行命令或自动启动程序(rc.local)

linux 怎么开机 执行命令

centos 7 rc.local 不启动