Cron Job Newbie help - Checkpoint Firewall mgmt server cleaning up logs

superman100superman100 Member Posts: 8 ■□□□□□□□□□
Can someone help me finalize this cron job. The goal is to have fully automated cron job which runs weeknights @ 4am doing a search for any logs older than 50 days and larger than 1mb and deletes them. 0 4 * * 1,2,3,4,5 find /opt/CPsuite-R77/fw1/log -size +1000k -mtime +50 -name "*.log" -exec rm -r {} \; Logs are located in the following directory /opt/CPsuite-R77/fw1/log

Comments

  • VeritiesVerities Member Posts: 1,162
    So if you want to create a cron job for a specific user (other than yourself) you can do:

    sudo crontab -e -u username

    If you look at the man pages you can see some explanations on how to configure times/dates:

    man 5 crontab

    You can do a simple 1-5 to cover weekdays:

    0 4 * * 1-5 find /opt/CPsuite-R77/fw1/log -size +1000k -mtime +50 -name "*.log" -exec rm -r {} \;

    If you want to add a user its just:

    useradd username

    To set the password

    passwd username

    Never used "Gai", can't help you there.
  • JockVSJockJockVSJock Member Posts: 1,118
    xargs is replacing exec, so you could write something like this under whatever user's crontab
    0 4 * * 1,2,3,4,5 find /opt/CPsuite-R77/fw1/log -size +1000K -mtime +50 -name ".log" | xargs rm -r 
    
    

    Less code, if your into that.

    IMO, run it from the CLI first, and once you are satisfied, then place it into a cron job.


    http://www.thegeekstuff.com/2013/12/xargs-examples/

    xargs: How To Control and Use Command Line Arguments
    ***Freedom of Speech, Just Watch What You Say*** Example, Beware of CompTIA Certs (Deleted From Google Cached)

    "Its easier to deceive the masses then to convince the masses that they have been deceived."
    -unknown
  • VeritiesVerities Member Posts: 1,162
    Did you not read my post? Its literally in the second line.
  • JockVSJockJockVSJock Member Posts: 1,118
    You can either
    crontab -l 
    

    To list current cron jobs tied to what user you are logged in as...

    and
    crontab -e 
    

    To them modifications to that user's crontab.

    However depending on who is administering that system, crontab maybe blocked by either cron.allow or cron.deny.
    ***Freedom of Speech, Just Watch What You Say*** Example, Beware of CompTIA Certs (Deleted From Google Cached)

    "Its easier to deceive the masses then to convince the masses that they have been deceived."
    -unknown
Sign In or Register to comment.