You are Here:
Linux Lite 4.4 Final has been released. See the Release Announcements section for more information.



[SOLVED]cronjob for clamav

Author (Read 507 times)

0 Members and 1 Guest are viewing this topic.

[SOLVED]cronjob for clamav
« on: May 05, 2019, 03:41:37 AM »
 

Osamu Morozumi

  • KoFi Supporter
  • New to Forums
  • *****
  • 18
    Posts
  • Country: au
  • Reputation: 1
    • Perth Custom Websites

  • Linux Lite: 4.4 64bit

  • CPU: Celeron Dual-Core CPU T3500 @ 2.095G

  • MEMORY: 4Gb
Hi,
I'm trying to create a cron job for clamav to do a scan of the home directory once a week. I made this script in /etc/cron.weekly/ :
Code: [Select]
#!/bin/sh
clamscan -r /home/osamu/ | grep FOUND >> /home/osamu/virus-scan-reports/virus-scan-report.txt
following instructions from https://askubuntu.com/questions/749129/how-to-schedule-clamav-to-perform-a-daily-scan.  I looked in crontab but can't see any evidence of a new job there:
Code: [Select]
# m h dom mon dow user command
17 * * * * root    cd / && run-parts --report /etc/cron.hourly
25 6 * * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
47 6 * * 7 root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )
52 6 1 * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )
#

Am I missing a step?  Is there a better way to achieve automatic weekly scans?

**edit:
I deleted the script in /etc/cron.weekly and instead added this cronjob to /etc/crontab
Code: [Select]
0 18 * * SUN root rm -rf /var/log/clamav/freshclam.log
1 18 * * SUN root freshclam
2 18 * * SUN root clamscan -r -i / | grep FOUND >> /home/osamu/virus-scan-reports/virus-scan-report.txt

This should update the malware database and scan  the entire system every sunday at 6pm and write it to a text file I hope.  Have I done this correctly and is there a way to dynamically append the current date to the name of the virus-scan text file?


Last Edit: May 05, 2019, 07:21:26 AM by Osamu Morozumi
 


Re: [SOLVED]cronjob for clamav
« Reply #1 on: May 05, 2019, 04:45:23 AM »
 

Jerry

  • Linux Lite Creator
  • Administrator
  • Platinum Level Poster
  • *****
  • 6896
    Posts
  • Country: nz
  • Reputation: 640
  • Linux Lite Member
    • Linux Lite OS

  • Linux Lite: 3.8 64bit

  • CPU: Intel Xeon Dual CPU's E5645 2.4GHz 12 Cores

  • MEMORY: 16Gb

  • VIDEO CARD: nVidia GeForce GTX 960
Try:

Code: [Select]
0 18 * * SUN clamscan -r -i / | grep FOUND >> /home/osamu/virus-scan-reports/virus-scan-report.txt; mv /home/osamu/virus-scan-reports/virus-scan-report.txt /home/osamu/virus-scan-reports/virus-scan-report-`date +"%d-%m-%Y"`.txt
or whatever date variables you want to include.
 

Re: [SOLVED]cronjob for clamav
« Reply #2 on: May 05, 2019, 05:48:26 AM »
 

Osamu Morozumi

  • KoFi Supporter
  • New to Forums
  • *****
  • 18
    Posts
  • Country: au
  • Reputation: 1
    • Perth Custom Websites

  • Linux Lite: 4.4 64bit

  • CPU: Celeron Dual-Core CPU T3500 @ 2.095G

  • MEMORY: 4Gb
Thanks again Jerry. Now just have to wait until 6pm to see if the job works!
 

Re: [SOLVED]cronjob for clamav
« Reply #3 on: May 05, 2019, 07:19:00 AM »
 

Osamu Morozumi

  • KoFi Supporter
  • New to Forums
  • *****
  • 18
    Posts
  • Country: au
  • Reputation: 1
    • Perth Custom Websites

  • Linux Lite: 4.4 64bit

  • CPU: Celeron Dual-Core CPU T3500 @ 2.095G

  • MEMORY: 4Gb
It took a bit of tweaking but it now works.  Here is the final script:

Code: [Select]
0 18 * * SUN root rm -rf /var/log/clamav/freshclam.log
1 18 * * SUN root freshclam
22 18 * * SUN root clamscan -r -i / | grep FOUND >> /home/osamu/virus-scan-reports/virus-scan-report-`date +"\%d-\%m-\%Y"`.txt

'%' symbols need to be escaped or they're interpreted as new lines.
 

Re: [SOLVED]cronjob for clamav
« Reply #4 on: May 05, 2019, 08:10:22 AM »
 

Jerry

  • Linux Lite Creator
  • Administrator
  • Platinum Level Poster
  • *****
  • 6896
    Posts
  • Country: nz
  • Reputation: 640
  • Linux Lite Member
    • Linux Lite OS

  • Linux Lite: 3.8 64bit

  • CPU: Intel Xeon Dual CPU's E5645 2.4GHz 12 Cores

  • MEMORY: 16Gb

  • VIDEO CARD: nVidia GeForce GTX 960
Nice :)

Sent from my Mobile phone using Tapatalk

 


Tags: cron virus clamav clamscan 
 


Linux Lite 4.4 Final has been released. See the Release Announcements section for more information.