Reputation: 1
Every cron job in my system runs twice. once by apache and once by root. How to stop the duplicate execution of the cron by root ?
The cron user "gns" executes once. Another cron user "root" executed the same cron job again. The Process ID is different for the two cron jobs.
My server is CentOS 5.6 (Final) My Parallels panel is Panel version 11.0.9 Update #60
Upvotes: 0
Views: 248
Reputation: 2492
I would not know the solution but I can advise a workaround till you find a solution .
If your cron job is a bash script you could add small code at the top to check the user to decide weather to exit or continue further :
In the if
statement change the gns
to whichever user you would require it to be :
if [ "$(whoami)" != "gns" ]; then
echo "Wrong user . Exiting ..."
exit 1
fi
echo "Correct user . Continuing ..."
# Put the actual code below
If your cron job are PHP script you could append an argument to evaluate the user :
0 0 * * * php /path/to/php/script.php --$(whoami)
Then in your PHP script get the user from the argument to decide weather to exit or continue further :
In the if
statement change the gns
to whichever user you would require it to be preceded by --
:
$user = isset( $_SERVER['argv'][1] ) ? $_SERVER['argv'][1] : '';
if( $user != '--gns' )
{
echo "Wrong user . Exiting ...";
exit;
}
echo "Correct user . Continuing ...";
// Put the actual code below
Upvotes: 1