Aerosol Posted December 16, 2014 Report Posted December 16, 2014 Permissions for www-data userwww-data ALL=(ALL) NOPASSWD: /usr/bin/crontab, /bin/mv, /bin/sh, /bin/cp, /bin/rm, /usr/bin/phpfunction createCronJob($min,$hour,$dayofMonth,$month,$dayOfweek,$command,$commented){ $realpath_var = realpath(__FILE__); $realpath_arr = explode('/',$realpath_var); $FullPathRoot = "/".$realpath_arr[1]."/".$realpath_arr[2]."/".$realpath_arr[3]; if($commented!="") { $commented="#"; } if($min=="") { $min="*"; } if($hour=="") { $hour="*"; } if($dayofMonth=="") { $dayofMonth="*"; } if($month=="") { $month="*"; } if($dayOfweek=="") { $dayOfweek="*"; } $CronJobs = shell_exec("sudo crontab -l"); $CronJobs_arr= explode("#***\n",$CronJobs) or die("ERROR"); $CronJobs_arr = array_filter($CronJobs_arr); $NewCron = $CronJobs_arr[0]."#***\n"; if($command!="") { $command_file = "#!/bin/bash\n"; $command_file.= $command."\n\n"; $command_file.= 'echo '.'"Scheduled Backup: Backup performed at '.'`date '."'+%d-%m-%Y %H:%M:%S'`".'\n<br/>---------------------------------------------------------------------------------\n" >> '.$FullPathRoot."/logSchedule/".date("Y-m-d").".log" ; file_put_contents($FullPathRoot."/bash/ExecCron.sh",$command_file); $NewCron.= $commented.$min." ".$hour." ".$dayofMonth." ".$month." ".$dayOfweek."\t".$FullPathRoot."/bash/ExecCron.sh"."\r\n#***\n"; } $file = $FullPathRoot."/InstallNewCron.txt"; file_put_contents($file,$NewCron); $ClearCronJob = shell_exec("sudo crontab -r"); $reinstall_cronJob = shell_exec("sudo crontab ".$file); unlink($file); $Body="The Original Cronjob was changed \n\n\nOriginal:\n\n****************\n\n".$CronJobs."\n****************\n\n\nModfied To:\n\n".$NewCron."\n\n"; return $Body} Quote