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 apachecron_file=/etc/cron.d/restart_apache_crontabcron_job=*/1 * * * * root condrestart-apache.shecho $cron_job > $cron_filechmod 777 $cron_fileexit 0Provided 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 scriptcondrestart-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.logThis 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..
Create cron as a apache user and run as root user
cron;apache httpd;root;services
In the cronjob */1 * * * * root condrestart-apache.sh I would expect an absolute path to your restart script e.g. /usr/local/sbin/condrestart-apache.sh.And  condrestart-apache.sh must be an executable (e.g. chmod 755) shell script and of course include something like #!/bin/sh  which is missing from your snippet.The primary reason to restart Apache would be to effect a configuration change, so checking if the syntax is correct before trying to restart your webserver and killing it may be a good idea as well...#!/bin/sh# /usr/local/sbin/condrestart-apache.shrm -f /etc/cron.d/restart_apache_crontabRETVAL=0/usr/sbin/apachectl configtestRETVAL=$?if [ $RETVAL -ne  0 ]; then   echo Configuration file invalid   exit 1fi/sbin/service httpd restart RETVAL=$?if [ $RETVAL -ne  0 ]; then   echo Restart Failed   exit 1fi