I am creating this cron as apache user and want to run this cron as root, below is my code snippet:
# Create a cron job to restart apache
cron_file="/etc/cron.d/restart_apache_crontab"
cron_job="*/1 * * * * root condrestart-apache.sh"
echo "$cron_job" > $cron_file
chmod 777 $cron_file
exit 0
Provided sufficient privileges to cron.d directory (changes directory group to apache user) and script generated a cron file restart_apache_crontab at /etc/cron.d/ using the above script
condrestart-apache.sh contains below code and has sufficient access permissions for apache user:
rm -f /etc/cron.d/restart_apache_crontab
/sbin/service httpd restart > restart-apache.log
This will first remove cron and then restart apache (means cron will run only for 1 time)
I am able to create cron as apache user but not able to execute it as root user.
Please help me on this.. code snippet will be really helpful..