Finding Cronjobs created for 1 and 5 min

Vs Nu

Well-Known Member
Jul 17, 2015
178
12
68
India
cPanel Access Level
Root Administrator
How to check the user cronjobs who created 1 min or 5 min on the server

i had an script which detect 1 min cron jobs please someone help me to find out the cronjob created 5 min


#!/bin/bash
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} {$entry}";
fi;
done;
done;

 

cPRex

Jurassic Moderator
Staff member
Oct 19, 2014
15,275
2,432
363
cPanel Access Level
Root Administrator
Hey there! If I'm reading that script properly, it looks like this will already do this for you. That script is already detecting any cron that runs in 1, 2, 3, 4, or 5 minute intervals. We can see this from the following lines:

mn=$(echo ${entry}|awk -F':' '{print $1}');

That pulls the first column, which is the time. And then this:

if [[ ${mn} == "*" || ${mn} =~ "\*\/[0-5]$" ]];

Which gives you output if there is anything with the numbers 1 through 5 in that first column.

So you should not need to do anything additional to get crons that are set for ever 5 minutes on the machine.
 

Vs Nu

Well-Known Member
Jul 17, 2015
178
12
68
India
cPanel Access Level
Root Administrator
Hey there! If I'm reading that script properly, it looks like this will already do this for you. That script is already detecting any cron that runs in 1, 2, 3, 4, or 5 minute intervals. We can see this from the following lines:

mn=$(echo ${entry}|awk -F':' '{print $1}');

That pulls the first column, which is the time. And then this:

if [[ ${mn} == "*" || ${mn} =~ "\*\/[0-5]$" ]];

Which gives you output if there is anything with the numbers 1 through 5 in that first column.

So you should not need to do anything additional to get crons that are set for ever 5 minutes on the machine.
If i change [0-15] will it show crons of 15 min ?