Please whitelist cPanel in your adblocker so that you’re able to see our version release promotions, thanks!

The Community Forums

Interact with an entire community of cPanel & WHM users!

Cron Job

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

  1. keat63

    keat63 Well-Known Member

    Joined:
    Nov 20, 2014
    Messages:
    1,013
    Likes Received:
    45
    Trophy Points:
    28
    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:
    168
    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
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  3. cPanelMichael

    cPanelMichael Technical Support Community Manager
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    44,802
    Likes Received:
    1,895
    Trophy Points:
    363
    cPanel Access Level:
    Root Administrator
    Twitter:
    Hello :)

    Yes, the previous post is accurate, and you should edit the root cron with the "crontab -e" command as mentioned.

    Thank you.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  4. keat63

    keat63 Well-Known Member

    Joined:
    Nov 20, 2014
    Messages:
    1,013
    Likes Received:
    45
    Trophy Points:
    28
    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 Technical Support Community Manager
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    44,802
    Likes Received:
    1,895
    Trophy Points:
    363
    cPanel Access Level:
    Root Administrator
    Twitter:
    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.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
Loading...

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice