title: Bash Script - Daemon
body: <p>I'm not a programmer, nor a security expert. I work with CheckPoint and I have the following code, developed by me for use with CheckPoint Logs management:</p>
  
  <pre><code>#!/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&lt;&amp;- 1&gt;&gt; /var/log/LOG 2&gt;&amp;1 &amp;
  
  # 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]" &gt;&amp;2
      exit 1
  }
  
  do_launch() {
      if [ "$CHECK" -eq 2 ] ; then
          set -x
          #exec &gt;&gt; /var/log/LOG 2&gt;&amp;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 $SCP_USR@$SCP_IP:$SCP_DEST_DIR &amp;&amp; rm $i || break 1;
      done
  }
  
  # Work
  if [ "$#" -ne 1 ]
  then
      usage
  else
      case "$@" 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
  </code></pre>
  
  <p>The script runs fine when run manually, but when I put in crontab <code>nohup /etc/scripts/log start 0&lt;&amp;- 1&gt;&gt; /var/log/LOG 2&gt;&amp;1 &amp;</code> or even run from terminal and logout and login, the script fail to loop/run but it is still runnning from <code>ps</code>.</p>
  
  <p>Can someone help me?</p>
  
  <p>Also, the bash version is 2.05b from CheckPoint, but if everything is fine from manual, I don't think the version is the reason.</p>