using
xls2csv -x /usr/share/nginx/html/price_list_EN.xls -s cp1252 -d 8859-1 > /usr/share/nginx/html/price_list_EN.csv
in linux commandline it works and exports it correctly, but if I use it on php
$transf2 = "xls2csv -x /usr/share/nginx/html/price_list_EN.xls -s cp1252 -d 8859-1 > /usr/share/nginx/html/price_list_EN.csv";
exec($transf2);
a file named price_list_EN.csv appears but it remains empty...
Try to execute your command like this from shell
su -s /bin/bash -c "xls2csv -x /usr/share/nginx/html/price_list_EN.xls -s cp1252 -d 8859-1 > /usr/share/nginx/html/price_list_EN.csv" www-data(your webserver user name)
then you debug the error
Related
I have a cron issue with curl:
curl -w "%{time_total}\n" -o /dev/null -s http://myurl.com >> ~/log
works great and add a line in log file with total_time.
But the same line with cron doesn't do anything.
It's not a path problem because curl http://myurl.com >> ~/log works.
% is a special character for crontab. From man 5 crontab:
The "sixth" field (the rest of the line) specifies the command to be
run. The entire command portion of the line, up to a newline or a
"%" character, will be executed by /bin/sh or by the shell specified
in the SHELL variable of the cronfile. A "%" character in the
command, unless escaped with a backslash (\), will be changed into
newline characters, and all data after the first % will be sent to
the command as standard input.
So you need to escape the % character:
curl -w "%{time_total}\n" -o /dev/null -s http://myurl.com >> ~/log
to
curl -w "\%{time_total}\n" -o /dev/null -s http://myurl.com >> ~/log
^
Im making a webscript starting a minecraft server and i have a problem with shell_exec executing command on screen:
$output = shell_exec('screen -d -m -S ServerOne');
$output2 = shell_exec('screen -S ServerOne -p 0 -X stuff "cd /var/www/html/servers/asd/ && java -Xmx1024M -Xms1024M -jar server.jar nogui > /screenlog ^M"');
It creates a screen with name ServerOne but didnt happened nothing after it!
I want to execute on it:
cd /var/www/html/servers/asd/ && java -Xmx1024M -Xms1024M -jar server.jar nogui > /screenlog ^M
I tried a lot of things and nothing worked, please help! :)
Sorry for my bad English.
I'm trying to use jarun's "googler" in a PHP script in order to search YouTube and find the URL of the first result. The command I'm executing is googler --np --json -C -n 1 -w youtube.com -x <name of youtube video>, and it works perfectly on my local machine. Here is my code:
<?php
exec("googler --np --json -C -n 1 -w youtube.com -x thomas the dank engine", $results);
var_dump($results);
?>
When I execute this in the command line, it works perfectly as it should, but when I do it via a web browser or a GET request, it does not work. I am aware that it is being executed as another user. In my case, it's the user www-data, so I gave that user full sudo permissions without a password, and did the following commands:
sudo -u pi googler --np --json -C -n 1 -w youtube.com -x thomas the dank engine
as well as
su - pi -c 'googler --np --json -C -n 1 -w youtube.com -x thomas the dank engine'
neither of these worked. Does it have to do with googler? What am I doing wrong?
When adding 2>&1 to the command, I get the following error message:
stdout encoding 'ascii' detected. googler requires utf-8 to work properly. The wrong encoding may be due to a non-UTF-8 locale or an improper PYTHONIOENCODING. (For the record, your locale language is and locale encoding is ; your PYTHONIOENCODING is not set.) Please set a UTF-8 locale (e.g., en_US.UTF-8) or set PYTHONIOENCODING to utf-8.
Try putting:
putenv("PYTHONIOENCODING=utf-8");
in the script before calling exec(). googler apparently requires the locale or this environment variable to be set.
You must remove exec from the disable_functions parameter in the php.ini file for your server module installation of PHP (which is separate from your CLI installation). It is typically disabled by default for the server module.
I try to restore a database (".backup" file) with pg_restore with cmd launch with PHP code but it doesn't work.
1- I give to my PHP variable all the cmd code
$cmd="cmd /c C:/Program Files/PostgreSQL/9.1/bin/pg_restore.exe -d ".$_POST['data2']." -i -h localhost -p 5432 -U ********** D:/backup/voirie.backup";
2- I launch it
exec($cmd);
My php work without result
On my server the process is launched
Other informations
In place of exec() I tested with system() and passthru()
I tested to create a batchfile from my php. This batchfile, work fine when launch him on the server but not from my PHP file
The generate code in $cmd was tested directly from CMD on the server and it works
For other codes on this server I use this who work fine: system("cmd /c C:/Python35-32/python.exe D:/python/serpent.py");
I tested with this quotes without result : $cmd='cmd /c "C:/Program Files/PostgreSQL/9.1/bin/pg_restore.exe" -d '.$_POST['data2'].' -i -h localhost -p 5432 -U ********** D:/backup/voirie.backup';
Here is my code:
$pdf = '/Users/macbookpro/Desktop/q.pdf';
$swf = '/Users/macbookpro/Desktop/q.swf';
$command2 = 'pdf2swf -o '.$swf.' -T -z -t -f '.$pdf.' -s flashversion=9';
exec($command2,$out,$status);
var_dump($output);
The output is NULL and no SWF is generated. However, if I output the command and copy it to terminal, it works. How do I solve this?
exec runs as the user running the script. Apache user likely doesn't have the PATH variable telling it where to look for programs, so instead of
$command2 = 'pdf2swf -o '.$swf.' -T -z -t -f '.$pdf.' -s flashversion=9';
Try adding the location of pdf2swf, something like:
$command2 = '/bin/pdf2swf -o '.$swf.' -T -z -t -f '.$pdf.' -s flashversion=9';
And make sure that the apache user has permission to get to the executable, and permission to execute it.
chmod a+x /bin/pdf2swf
Of course replace /bin/ with where ever pdf2swf really lives for all the example code in this answer.