The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Cron Job

Discussion in 'Security' started by keat63, Jul 29, 2015.

  1. keat63

    keat63 Well-Known Member

    Joined:
    Nov 20, 2014
    Messages:
    765
    Likes Received:
    20
    Trophy Points:
    18
    cPanel Access Level:
    Root Administrator
    I want to configure a cron job for ClamV to run at say 5am.
    I understand that I might need to modify /var/spool/cron/root, and I found the following command in the help pages.

    Code:
    for i in `awk '!/nobody/{print $2 | "sort | uniq" }' /etc/userdomains | sort | uniq`; do /usr/local/cpanel/3rdparty/bin/clamscan -i -r /home/$i 2>>/dev/null; done >> /root/infections&
    
    Is it just a matter of dropping the time schedule in front of this, so:

    Code:
    0 5 * * * for i in `awk '!/nobody/{print $2 | "sort | uniq" }' /etc/userdomains | sort | uniq`; do /usr/local/cpanel/3rdparty/bin/clamscan -i -r /home/$i 2>>/dev/null; done >> /root/infections&
    
    or is it more complex ??
     
  2. ModServ

    ModServ Well-Known Member

    Joined:
    Oct 17, 2006
    Messages:
    332
    Likes Received:
    5
    Trophy Points:
    18
    Location:
    Egypt
    cPanel Access Level:
    Root Administrator
    Just to be more organized, make a file let's say it's name will be "virscan" and put this in it:
    Code:
    #!/bin/bash
    
    for i in `awk '!/nobody/{print $2 | "sort | uniq" }' /etc/userdomains | sort | uniq`; do /usr/local/cpanel/3rdparty/bin/clamscan -i -r /home/$i 2>>/dev/null; done >> /root/infections&
    
    Make it executable:
    Code:
    chmod 755 virscan
    
    Move it to let's say "/usr/local/bin" then add this line in Cron:
    Code:
    0 5 * * * /bin/bash /usr/local/bin/virscan
    BTW, you can reach cron by this command:
    Code:
    crontab -e
     
  3. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    30,762
    Likes Received:
    662
    Trophy Points:
    113
    cPanel Access Level:
    Root Administrator
  4. keat63

    keat63 Well-Known Member

    Joined:
    Nov 20, 2014
    Messages:
    765
    Likes Received:
    20
    Trophy Points:
    18
    cPanel Access Level:
    Root Administrator
    I looked at crontab -e yesterday, and thought it looked a bit fiddly.
    Is it not easier to modify the file using CS Explorer ?

    I'm away from the office for a few weeks after today, so i'll look at implimenting this when i get back (just in case something breaks)

    Thanks
     
  5. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    30,762
    Likes Received:
    662
    Trophy Points:
    113
    cPanel Access Level:
    Root Administrator
    You can edit the file manually if you prefer. The "e" flag opens it with the default text editor as defined in your bash profile.

    Thank you.
     
Loading...

Share This Page