in Interesting, Performance, Security

Disable or detect Minute cron / crontab job runs

So how does one detect (and eventually prevent) crontab jobs on a server from running every minute? First of all, why would one ever want to control crontab? Long story short, an aggressive cron job can cripple a shared server and affect all users on such paltform.

Here’s a script that crawls cron jobs and reports non-root scripts that run at 5 minute frequency or less. Let’s beautify the code & pack it into a runnable file script:

#!/bin/bash
admin="admin@example.com";
ls -1 /var/spool/cron/| grep -v '^root'|while read u;
do
        cat /var/spool/cron/${u}|\
        awk '{print $1":"$2":"$3":"$4":"$5":"$NF}'|\
        while read entry;
        do
                mn=$(echo ${entry}|awk -F':' '{print $1}');
                if [[ ${mn} == "*" || ${mn} =~ "\*\/[0-5]$" ]];
                then
                        echo "Minutely script found -> ${u}";
                fi;
        done;
done | mail -s "Minutely script search - report" ${admin};

Be sure to change the email address. You’ll need to set this to run as root as a crontab job every 10 minutes or so.
That’s all folks. Enjoy!

Write a Comment

Comment

Comment moderation is enabled. Your comment may take some time to appear.

Webmentions

  • designer ray ban black friday cyber monday active lifestyle rb3460 sunglasses red white frame tawny lens garden fresh produce

    designer ray ban black friday cyber monday active lifestyle rb3460 sunglasses red white frame tawny lens garden fresh produce

    Researcher Discovers Risky shoes dependence

  • Download Free Money Making Websites

    I Must Admit That:…

    […]The information mentioned in this website are some of the best available[…]…

  • Handsfree Website Profit

    Superb Website

    […]please visit the sites we follow, including this one, as it represents our picks from the web[…]…

  • Online Millionaires Club

    Gems Form The Internet…

    […]very few websites that happen to be from our point of view are undoubtedly well worth checking out[…]…