我不是程序员,也不是安全专家。我与保点工作,我有以下代码,由我制定了使用与检查点日志管理:Bash脚本 - 守护进程
#!/bin/bash -
# Necessario carregar as variaveis do CheckPoint:
. /etc/profile.d/CP.sh
# Description:
# Log management
# Crontab:
#0 */1 * * * nohup /etc/scripts/log start 0<&- 1>> /var/log/LOG 2>&1 &
# Vars:
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/etc/scripts
FILE=/var/log/LOG
SLEEP=600
RUN_TIME=01
LOG_DIR=$FWDIR/log
GZIP_RET=1
SCP_RET=1
SCP_USR=openssh
SCP_DEST_DIR=LOGS_RJ
SCP_IP=192.168.1.41
TIME=$(clock | awk {'print $4'} | cut -d ':' -f 1)
CHECK=$(ps aux | grep 'log start' | grep -v grep | wc -l)
DATE=$(date +%y%m%d)
# Functions:
usage() {
echo "Usage: $0 [start|stop]" >&2
exit 1
}
do_launch() {
if [ "$CHECK" -eq 2 ] ; then
set -x
#exec >> /var/log/LOG 2>&1
else
exit
fi
}
do_compression() {
SEARCH=`find "$LOG_DIR" -name '20*' -daystart -follow -mtime +$GZIP_RET | grep -v gz`
for i in $SEARCH ; do
gzip -f -9 $i ;
done
}
do_scp() {
SEARCH=`find "$LOG_DIR" -name '20*' -daystart -follow -mtime +$SCP_RET`
for i in $SEARCH ; do
scp $i [email protected]$SCP_IP:$SCP_DEST_DIR && rm $i || break 1;
done
}
# Work
if [ "$#" -ne 1 ]
then
usage
else
case "[email protected]" in
start)
while true ; do
do_launch
while true ; do
if [ "$TIME" -eq "$RUN_TIME" ] ; then
do_scp
else
do_compression
fi
sleep $SLEEP
done
done
;;
stop)
pkill -x log
;;
*)
usage
esac
fi
exit
脚本手动运行时运行正常,但是当我把在crontab中nohup /etc/scripts/log start 0<&- 1>> /var/log/LOG 2>&1 &
甚至来自终端和退出运行和登录,脚本无法循环/运行,但它仍然从ps
运行。
有人可以帮助我吗?
此外,bash版本是CheckPoint的2.05b版本,但如果手册中的内容一切正常,我认为版本不是原因。
通过手动模式,您的意思是您正在终端运行'/ etc/scripts/log start 0 <&- 1>>/var/log/LOG 2>&1'并且正在运行,那么它也应该与'nohup'一起工作。你如何得出它*不工作*? –
我得出这样的结论,因为我看不到日志增加,日志压缩等完成工作,所以没有运行。感谢你的回答 !!! –
请参阅下面的@ jonathan's asnwer。一旦你解决了这些问题,脚本就可以工作。虽然我怀疑你的说法,它是从终端工作.. –