• Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Search
  • Register
  • Login
Netgate Discussion Forum
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Search
  • Register
  • Login

[Resolved] Crontab task not running.

Scheduled Pinned Locked Moved General pfSense Questions
3 Posts 2 Posters 776 Views
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F
    fabricioguzzy
    last edited by fabricioguzzy May 13, 2019, 2:48 PM May 10, 2019, 9:32 PM

    Hello Everyone,
    I am trying hard to make a script to run under crontab but for some reason, it doesn't work.

    Here the crontab entry (using GUI)

    1	*	*	*	*	root	/usr/bin/nice -n20 /etc/LCDmonitor.sh
    

    and here the script:

    -rwxr-xr-x  1 root  wheel  1277 May 10 18:28 /etc/LCDmonitor.sh
    
    #!/usr/bin/env sh
    
    # Cheking if LCDd daemon service is installed.
    if [ ! -d /usr/local/share/pfSense-pkg-LCDproc ]; then {
    echo "Service not installed"; 
    exit;
    }
    fi
    
    #Checking if LCDd Daemon service is Running
    if [ ! `/bin/pgrep -x "LCDd"` ]; then echo "LCD Daemon is not running - Start it from GUI"; exit
    else
    echo "The LCDd Daemon is running"
    fi
    
    # Checking if we have duplicated client processes
    NOP=`/bin/ps -ax | /usr/bin/grep -I lcdproc_client.php | /usr/bin/grep -v "grep" |wc -l`
    # If there are more than 1 process, then print message
    if [ $NOP -gt 1 ] ; then echo "More than 1 process is running - Killing Processes and restarting the service";
    /bin/ps -A | /usr/bin/grep lcdproc_client.php | /usr/bin/grep -v "grep" | /usr/bin/awk '{print $1}' | /usr/bin/xargs kill -9 $1 
    /bin/sleep 2
    #Restating the LCDd client
    /usr/local/bin/php -f /usr/local/pkg/lcdproc_client.php &
    fi
    
    # If there is no client started, We start a single one.
    if [ $NOP -eq 0 ] ; then echo "No client process is running - Starting one";
    #Starting the LCDd client
    /usr/local/bin/php -f /usr/local/pkg/lcdproc_client.php &
    echo "A single LCDd client was started"
    fi
    
    # If there is a single client process then print message
    if [ $NOP -eq 1 ] ; then echo "OK - A single client process is running";
    fi
    

    Everything works fine using the Shell, but not under cron.
    I have checked an re-checked the paths for the commands. Just don't know what to do anymore.

    Any help is very welcome!

    Thanks
    Fabricio.

    1 Reply Last reply Reply Quote 0
    • K
      KOM
      last edited by May 11, 2019, 1:20 AM

      Try running your script from /usr/local/bin instead of /etc. I can get it to work from there with a 1/* for the minute instead of just 1.

      F 1 Reply Last reply May 13, 2019, 2:47 PM Reply Quote 0
      • F
        fabricioguzzy @KOM
        last edited by May 13, 2019, 2:47 PM

        @KOM hello KOM, ... Nice. that did the trick! Not sure why, but it worked.
        Also, I got another issue on my script. I was missing the full path for the wc command.
        Thanks!! Appreciate the tip!

        Fabricio.

        1 Reply Last reply Reply Quote 0
        1 out of 3
        • First post
          1/3
          Last post
        Copyright 2025 Rubicon Communications LLC (Netgate). All rights reserved.
          This community forum collects and processes your personal information.
          consent.not_received