I want to edit cron tab daily to delete / add some jobs .. so I added cron job ( helper job ) to run php script to handle these edits.
When I run this script by browser works fine .. but when it runs using the helper job not running and I receive notification mail from cpanel with this error :
Please note I am on shared hosting plan with C-Panel so I have no root access .. but the code working fine when run from browser.
Error:
You (dcfn35c8st1b) are not allowed to use this program (crontab)
See crontab(1) for more information
You (dcfn35c8st1b) are not allowed to use this program (crontab)
See crontab(1) for more information
You (dcfn35c8st1b) are not allowed to use this program (crontab)
See crontab(1) for more information
You (dcfn35c8st1b) are not allowed to use this program (crontab)
See crontab(1) for more information
You (dcfn35c8st1b) are not allowed to use this program (crontab)
See crontab(1) for more information
PHP Script:
exec('crontab -l', $crontab);
$record_found = false;
foreach($crontab as $key => $value){
if(strpos($value, 'record_extra.php') !== false){
//echo $key . ' ' . $value . '<br>';
unset($crontab[$key]);
$record_found = true;
}
if(strpos($value, 'record.php') !== false){
//echo $key . ' ' . $value . '<br>';
unset($crontab[$key]);
}
}
if($record_found){
file_put_contents('/tmp/crontab.txt', arrayToString($crontab) . $firstJob.PHP_EOL);
if(exec('crontab /tmp/crontab.txt')){
//echo 'success <br>';
} else {
//echo 'error <br>';
}
$output = shell_exec('crontab -l');
file_put_contents('/tmp/crontab.txt', $output . $secondJob.PHP_EOL);
if(exec('crontab /tmp/crontab.txt')){
//echo 'success <br>';
} else {
//echo 'error <br>';
}
} else {
$output = shell_exec('crontab -l');
file_put_contents('/tmp/crontab.txt', $output . $firstJob.PHP_EOL);
if(exec('crontab /tmp/crontab.txt')){
//echo 'success <br>';
} else {
//echo 'error <br>';
}
$output = shell_exec('crontab -l');
file_put_contents('/tmp/crontab.txt', $output . $secondJob.PHP_EOL);
if(exec('crontab /tmp/crontab.txt')){
//echo 'success <br>';
} else {
//echo 'error <br>';
}
}
Need your help.
Thanks in advance.
Seems like the user isn't allowed to run crontab. Look into the files "/etc/cron.allow" and "/etc/cron.deny". If cron.allow exists, then only users in that list can use crontab. Users in cron.deny, can't use. If neither exist then only root user can use crontab.
I've looked at numerous "can't run crontab" posts and none of them addressed my problem. I want to report my unique solution.
My service provider copied my system to another place, and apparently they literally used the "cp" command to do it, which meant that no setuid bits were preserved. /usr/bin/crontab was one of several files for which I had to restore the setuid bit.
You can't run crontab if it doesn't have the setuid bit set.
Related
I want to do connection between php and scilab, this my code
try {
$path = 'C:\\wamp64\\apps\\scilab-5.5.2\\bin\\Scilex.exe';
$path_script = "ea=loadfls('C:\\wamp64\\www\\scilab\\estilosaprendizaje.fls');res=evalfls([-11,11],ea); disp(res);exit;";
$command = $path . ' -nb -e "' . $path_script.'"';
echo $command;
exec($command, $output);
foreach ($output as $line) {
print_r($line);
echo "<br />";
}
} catch (Exception $e) {
echo 'Excepción capturada: ', $e->getMessage();
}
but when I run the php, it does not work, it keeps loading, I do not have error messages or anything.
In scilab my code it works.
My output in scilab
Try adding -nw to $command to lauch scilab in console mode. It may be because scilab try to launch itself in graphical mode. I dont have php nor fuzzy toolbox, so I could not test it.
I'm developing a new portal for my business.. I have to start many batch files for different pc names.. so I try to run my batch with one parameter..
$path = $db->givePath($service);
$path = $path . " " . "PCNAME";
if(exec("cmd /c" . $path)){
echo "Successful sent";
} else {
echo "Error";
}
But if I run this command, nothing happens..
The old version worked:
$path = $db->givePath($service);
if(exec("cmd /c" . $path)){
echo "Successful sent";
} else {
echo "Error";
}
Can someone assist me here?
You are likely encountering issues when passing the PCNAME as an argument because it has characters that need to be escaped. You can read more on escapeshellarg the TL;DR is it escapes any control characters that would cause the execution to exit in an unexpected way. Using something like UNC path for PCNAME withouth using escapshellarg() would trick windows into thinking there was another argument being specified.
$path = $db->givePath($service);
$batchCmd = "C:\{$path} " . escapeshellarg('PCNAME');
if(exec("cmd /c {$batchCmd}")) {
echo 'Successfully sent';
} else {
echo 'Error';
}
You can to use cmd shell:
system("cmd /c C:" . $path_to_file);
I have been trying to execute a shell script that executes a perl program and i am doing that using the shell_exec() in php.
I have given all the permissions to the folders as well as the executables. Also, shell_exec() is not disabled in the php.ini. I have even tried using the 2>&1 after the command. Kindly help.
Following is the code.
<?php
if(isset($_POST['EI']) && isset($_POST['OP']) && isset($_POST['GC']) && isset($_POST['PA']) && isset($_POST['HT']) && isset($_POST['AB'])) {
$data = 'Option entered by user :'.$_POST['OP'] . "\n" . 'The Threshold for GC is :'.$_POST['GC'] . "\n" . 'The Threshold for PA is :'.$_POST['PA'] . "\n" . 'The Threshold for HT is :'.$_POST['HT'] . "\n" . 'The Threshold for AB is :'.$_POST['AB'] . "\n" . 'The email id of the user is :'.$_POST['EI'] . "\n";
$ret = file_put_contents('/..path../out.txt', $data);
if($ret === false) {
die('There was an error writing this file');
} else {
echo "$ret bytes written to file";
}
} else {
die('no post data to process');
}
$output=shell_exec("./testing.sh");
?>
I'm trying to automate my testing. As a smoke test I would like to check my PHP code with PHPMD before continuing with the actual Unit tests. Sounds sensible enough right?
Thing is that PHPMD seems to crash when fatal errors arise in my PHP files. For a test I added an extra accolade at a function definition like so:
function foo() {{
// Stuff
}
Were I expected a 1 exit code, PHPMD seems to crash completely and instead returns a 0 exit code. Rendering my automated script useless. Is there a way to suppress these errors and return the expected exit code? For PHPUnit the --process-isolation option solved this problem but I can't seem to find such option for PHPMD.
Relevant automated testing code
#!/usr/bin/php
<?php
exec('meta/phpmd', $output, $returnCode);
if ($returnCode == 1) {
echo '[Fail] PHP code is breaking', PHP_EOL;
exit(1);
} elseif ($returnCode == 2) {
echo '[Warn] PHP code is unclean', PHP_EOL;
} else {
echo '[OK] Code is clean! ', PHP_EOL;
}
As a workaround (and possible solution) one could check the syntax before passing it to PHPMD. I changed my testing code to this:
#!/usr/bin/php
<?php
$dir_root = dirname(dirname(__DIR__));
$dir_php = $dir_root . DIRECTORY_SEPARATOR . 'api' . DIRECTORY_SEPARATOR . 'App';
exec('find ' . $dir_php . ' -iname *.php | xargs -n1 php -l 2>/dev/null', $output, $returnCode);
if ($returnCode != 0) {
echo '[Fail] PHP contains syntax errors', PHP_EOL,
implode(PHP_EOL, $output), PHP_EOL;
exit($returnCode);
}
exec('meta/phpmd', $output, $returnCode);
if ($returnCode == 1) {
echo '[Fail] PHP code is breaking', PHP_EOL;
exit(1);
} elseif ($returnCode == 2) {
echo '[Warn] PHP code is unclean', PHP_EOL;
}
Credits to Winglian at Reddit for the mass php -l code
https://www.reddit.com/r/PHP/comments/2t7mvc/lint_an_entire_directory_of_php_files_in_parallel/
i am trying to run a file sytem for dropbox ff4d ( from github) in background using php
the purpose if that user will get his dropbox files mount on the server and then i will give the path to a web based explorer (like eXtplorer) so user can manage his file
the script is working fine when using command shell
but when i using the exec function it working printing out the last line of the command shell
and that it . i can not get the folder mount
here the code in php :
$folder = $_POST['foldername'];
$oldumask = umask(0000);
$path = "/var/www/cloudsite/" . $folder;
if(mkdir($path, 0777, true)) {
echo $path . " success directory created ";
} else {
echo $path . "error directory not created ";
}
umask($oldumask);
#$command = '/usr/bin/python /var/www/cloudsite/ff4d/./ff4d.py '. $path .'c7ZYof8Bl0YAAAAAAAAAARThZwAUexbukmv3rMEprPJWFcoQSKGWtWHQBYM40OgC';
$result = exec($command);
if ($result){
echo " </br> execution success";
}else{
echo "</br> error not success";
}
echo $result;
and here what i get in the browser it seems like it working but just hang here nothing mount in the created directory :
var/www/cloudsite/chao success directory created
execution successStarting FUSE...
Within the latest release of my ff4d.py script I've added a "background" switch (-bg).
https://github.com/realriot/ff4d
BTW: Please remove your access key (and revoke it afterwards) because it holds your personal information and ALL your data...