CPUG: The Check Point User Group

Resources for the Check Point Community, by the Check Point Community.


First, I hope you're all well and staying safe.
Second, I want to give a "heads up" that you should see more activity here shortly, and maybe a few cosmetic changes.
I'll post more details to the "Announcements" forum soon, so be on the lookout. -E

 

Results 1 to 9 of 9

Thread: Cron Job to automate deletion of /var/log files

  1. #1
    Join Date
    2015-06-23
    Posts
    11
    Rep Power
    0

    Default Cron Job to automate deletion of /var/log files

    Hello. I am looking for an automated way to delete log files from the /var/log directory. We have our log files being sent to the management server. Our end goal is to keep the last 90 days worth of log files. I am not completely familiar with crontab command syntax or switches to use but came across some suggestions through Google searches.
    This is what I have come up with for a job to run Every Sunday at 3 am to remove .log files older than 90 days. I am unsure about the switches -r and the {} along with \; at the end.

    0 3 * * 0 /var/log/opt/CPsuite-R77/fw1/log -mtime +90 -name "*.log" -exec rm -r {} \;

    Thanks in advance.

  2. #2
    Join Date
    2011-08-02
    Location
    http://spikefishsolutions.com
    Posts
    1,659
    Rep Power
    10

    Default Re: Cron Job to automate deletion of /var/log files

    Quote Originally Posted by fasteddye View Post
    Hello. I am looking for an automated way to delete log files from the /var/log directory. We have our log files being sent to the management server. Our end goal is to keep the last 90 days worth of log files. I am not completely familiar with crontab command syntax or switches to use but came across some suggestions through Google searches.
    This is what I have come up with for a job to run Every Sunday at 3 am to remove .log files older than 90 days. I am unsure about the switches -r and the {} along with \; at the end.

    0 3 * * 0 /var/log/opt/CPsuite-R77/fw1/log -mtime +90 -name "*.log" -exec rm -r {} \;

    Thanks in advance.
    Are you on Gaia or Splat? (or something else?).

    If its Gaia you wouldn't edit the crontab file directly. There is a clish command to add cron jobs. Its fairly friendly.

    I think its

    add cron job name some_name

    or something like that. Then i think you use the set command to set the time and command you want to run.

    You look like your missing the find command. I added type f so it only matches files. Should work

    find /var/log/opt/CPsuite-R77/fw1/log -mtime +90 -name "*.log" -type f -exec rm -r {} \;

    Can also do it like this (a litte more efficient but maybe not enough to matter). -exec creates a sub process for each file it matches

    source /etc/profile ; find $FWDIR/log -mtime +90 -name "*.log" -type f -print0 | xargs -0 rm -r

    this just creates a long list separated by nulls and passes it to a single rm command.

  3. #3
    Join Date
    2015-06-23
    Posts
    11
    Rep Power
    0

    Default Re: Cron Job to automate deletion of /var/log files

    We are on SPLAT.

    I did have find command but left it out of my post, thanks for catching that.

    Aside from adding the -type f it looks good? What is the function of the {} and \; in the command?

    I am not familiar with the source command suggested. Would that be done in crontab as well?

    Thanks so much for the help!

  4. #4
    Join Date
    2011-08-02
    Location
    http://spikefishsolutions.com
    Posts
    1,659
    Rep Power
    10

    Default Re: Cron Job to automate deletion of /var/log files

    Quote Originally Posted by fasteddye View Post
    We are on SPLAT.

    I did have find command but left it out of my post, thanks for catching that.

    Aside from adding the -type f it looks good? What is the function of the {} and \; in the command?

    I am not familiar with the source command suggested. Would that be done in crontab as well?

    Thanks so much for the help!
    Ah splat, yup your command looks good. I think your only running on sun at 3am right?

    the {} is where each item matched from the find command goes. I think the \; tells find this is the end of the -exec arguments. Its really just ";" but you have to escape it so the shell doesn't think oh you mean a 2nd command to run.
    Last edited by jflemingeds; 2016-07-11 at 12:08.

  5. #5
    Join Date
    2015-06-23
    Posts
    11
    Rep Power
    0

    Default Re: Cron Job to automate deletion of /var/log files

    Yes I am running it Sunday at 3am.

    It ran successfully this past Sunday at 3am and deleted the log files greater than 90 days.

    Thanks so much for the help.

  6. #6
    Join Date
    2012-07-19
    Posts
    108
    Rep Power
    8

    Default Re: Cron Job to automate deletion of /var/log files

    If you have smart log enabled, you'll want to do similar job for the smart log index files (found in $SMARTLOGDIR/data/).

    Also, newer releases of find have a -delete switch which is much more readable than the -exec stuff. At least on GAIA -delete works.

    Lastly, the -r switch to rm does not do anything as you are explicitly delete files, so no need to be recursive.

  7. #7
    Join Date
    2011-08-02
    Location
    http://spikefishsolutions.com
    Posts
    1,659
    Rep Power
    10

    Default Re: Cron Job to automate deletion of /var/log files

    Quote Originally Posted by Jejerod View Post
    If you have smart log enabled, you'll want to do similar job for the smart log index files (found in $SMARTLOGDIR/data/).

    Also, newer releases of find have a -delete switch which is much more readable than the -exec stuff. At least on GAIA -delete works.

    Lastly, the -r switch to rm does not do anything as you are explicitly delete files, so no need to be recursive.
    Very good points. I was also thinking about maxdepth 0, but after a few searches I wasn't %100 on 0 vs 1. I think 1 will match hidden files where 0 won't. I think maybe because a hidden file is in ".".

  8. #8
    Join Date
    2006-07-28
    Location
    San Francisco, USA
    Posts
    2,494
    Rep Power
    16

    Default Re: Cron Job to automate deletion of /var/log files

    Quote Originally Posted by Jejerod View Post
    If you have smart log enabled, you'll want to do similar job for the smart log index files (found in $SMARTLOGDIR/data/).
    I prefer to control those settings through SmartLog, where you can set either min space required, or retention settings. That way it's kept with the Check Point settings, and should survive moves/upgrades/etc.

  9. #9
    Join Date
    2006-04-27
    Location
    Twillight zone
    Posts
    1,010
    Rep Power
    16

    Default Re: Cron Job to automate deletion of /var/log files

    Quote Originally Posted by northlandboy View Post
    I prefer to control those settings through SmartLog, where you can set either min space required, or retention settings. That way it's kept with the Check Point settings, and should survive moves/upgrades/etc.
    Second that....I use it for regular log files as well ($FWDIR/log)...it takes care of itself :)

Similar Threads

  1. Route deletion no reflecting in CLI
    By udupik in forum Check Point VSX/VSX-1 Appliances
    Replies: 0
    Last Post: 2014-12-02, 08:14
  2. Automate Install
    By cpuer1 in forum R75.40 (GAiA)
    Replies: 0
    Last Post: 2012-10-08, 11:21
  3. Automate 100's of user's updates
    By uusec in forum SmartDashboard
    Replies: 1
    Last Post: 2008-01-04, 06:39
  4. Automate object creation
    By robori in forum Miscellaneous
    Replies: 2
    Last Post: 2007-02-16, 16:43
  5. How do I automate a SecuRemote Configuration?
    By Barry J. Stiefel in forum SecureClient/SecuRemote
    Replies: 0
    Last Post: 2005-08-12, 21:53

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •