How to run MAGMI from a shell script - php

I try to run MAGMI from a shellscript, but I get allways the same message:
/bin/sh: /is/htdocs/XXXXXXXXX/magento/magmi/cli/XXXXXXX.sh: /bin/bash^M: bad interpreter: No such file or directory
My script:
#!/bin/bash
FILES=/is/htdocs/XXXXXXXXX/magento/var/import/XXXXXXXXX.csv
for f in $FILES
do
echo "Running Magmi update with file: $f"
php magmi.cli.php -profile=XXXX -mode=update -CSV:filename="${f}"
wait
done
The script is in the same directory as magmi.cli.php
Thanks for hints and solutions !

Please use dos2unix linux command to remove above error like:
dos2unix scriptfilename.sh scriptfilename.sh
it generally occurs when we written something in WINDOW eniv. & then transfer to Linux platform

Related

php\r nu such file or directory when trying to run phpunit

I'm trying to run phpunit in my vagrant server in virtualbox(Ubuntu) for a school project, but I'm unable to.
I'm certain that my that phpunit is located in vendor/bin/phpunit and my test project is also in the right directory and everything is spelled correctly so I don't understand why I get this error.
I try to do:
vendor/bin/phpunit test/model/PDOGameModelTest.php
the error that I get is:
usr/bin/env: 'php\r': No such file or directory
Your file uses DOS file ending (CR+LF) and Ubuntu uses Unix one (LF). You have to convert your file with the command dos2unix :
Install it with :
sudo apt install dos2unix
Convert it with :
dos2unix test/model/PDOGameModelTest.php
Then :
vendor/bin/phpunit test/model/PDOGameModelTest.php
Edit : Another solution
awk '{ sub("\r$", ""); print }' test/model/PDOGameModelTest.php > test/model/PDOGameModelTest_converted.php
I have the same problem, but in my case it was a file
\vendor\bin\phpunit
it used DOS file ending (CR+LF) and Ubuntu uses Unix one (LF).
So I changed this file with NetBeans and the issue was fixed.
To change End Of File (EOF) in NetBeans just right click on the "file ending name" on a main window status bar.

Using PHP to build gradle Android Project

I'm developing a php function for execute a command that's build gradle project Android.
But to be clear I want to create a small system can modify a android project source and generate the APK project by build the gradle.
I do a lot of search about it and I found some close question but not with this command.
This is my function. It's really simple, I have already installed gradle tools in my server, and the command runs successfully in my terminal
function generator(){
exec('cd /home/my/AndroidStudioProjects/BetaProject/;./gradlew assembleDebug 2>&1',$out,$err);
var_dump($out);
var_dump($err);
}
But, when I execute it with php it's gives me this :
string(955) "Exception in thread "main" java.lang.RuntimeException:
java.io.FileNotFoundException:
/usr/sbin/.gradle/wrapper/dists/gradle-2.4-all/3i2gobhdl0fm2tosnn15g540i0/gradle-2.4-all.zip.lck
(No such file or directory) at
org.gradle.wrapper.ExclusiveFileAccessManager.access(ExclusiveFileAccessManager.java:78)
at org.gradle.wrapper.Install.createDist(Install.java:47) at
org.gradle.wrapper.WrapperExecutor.execute(WrapperExecutor.java:129)
at
org.gradle.wrapper.GradleWrapperMain.main(GradleWrapperMain.java:48)
Caused by: java.io.FileNotFoundException:
/usr/sbin/.gradle/wrapper/dists/gradle-2.4-all/3i2gobhdl0fm2tosnn15g540i0/gradle-2.4-all.zip.lck
(No such file or directory) at java.io.RandomAccessFile.open0(Native
Method) at java.io.RandomAccessFile.open(RandomAccessFile.java:316) at
java.io.RandomAccessFile.(RandomAccessFile.java:243) at
org.gradle.wrapper.ExclusiveFileAccessManager.access(ExclusiveFileAccessManager.java:49)
... 3 more "
If there's any solution or some advice, I will be so glad.
Thanks
try this:
function generator(){
exec('sh /home/my/AndroidStudioProjects/BetaProject/gradlew assembleDebug 2>&1',$out,$err);
var_dump($out);
var_dump($err);
}
I was facing the same issue, and I fixed it just by giving apache permission to execute these scripts by changing the owner of the directory where these files reside
It's going to be something like this:
sudo chown -R www-data your-directory/
I hope this is going to work for you.

Not able to run wkhtmltopdf commad through shell_exec() function in php but same command works on command line

I'm in trouble and that much confused about a php shell_exec command.
When the command is execute by PHP I have no error but the execution fails. If I use exactly the same command from a terminal it works.
Here's the command :
/usr/bin/wkhtmltopdf --lowquality --dpi 300 --encoding utf-8 "/tmp/knplabs_snappyxa9otq.html" "/tmp/knplabs_snappyv3pD7h.pdf"
When I lauch this from a terminal :
$ /usr/bin/wkhtmltopdf --lowquality --dpi 300 --encoding utf-8 "/tmp/knplabs_snappyWG9XTd.html" "/tmp/knplabs_snappyv3pD7h.pdf"
Loading page (1/2)
Printing pages (2/2)
Done
But from my php script :
// Construct the previous command
$command = $this->buildCommand($url, $path);
../..
shell_exec($command);
../..
$content = file_get_contents($path);
../..
I've test the output of shell_exec, it's empty.
The log :
Warning: file_get_contents(/tmp/knplabs_snappyv3pD7h.pdf): failed to open stream: No such file or directory in /*****/lib/snappy/SnappyMedia.class.php on line 64
No permission pb in the /tmp directory :
$ ls -la /tmp
total 448
drwxrwxrwt 16 root root 4096 mars 12 21:51 .
../..
I've tried avec the PHP exec() function to get error informations, I just get an "1" error code in return_var and nothing in output.
For information this issue appear on my test server, my desktop computer but not on my notebook. All the 3 are with sames PHP, Apache, Mysql versions.
I don't understand anything ...
Thanks for any help, I'm loosing my mind.
David.
I've found the solution here : Executing wkhtmltopdf from PHP fails
Thanks to Krzychu.
First to get information from the shell_exec command add " 2>&1" at the end of the command. In that way you will get information in return of the command :
$no_output = shell_exec($command);
echo $no_output; // nothing
$output = shell_exec($command . ' 2>&1');
echo $output; // in my case : "cannot connect to X server"
The solution :
Not use the wkhtmltopdf ubuntu package (0.9.9-4)
Use the official package from the Wkhtmltopdf download page
So no need to install xvfb ! (I've seen this advice many times)
Looks like a user's permissions issue.
When you run the command from the terminal, it is the user account, currently used, which does have the right permissions, to run a command in /usr/bin, and execute the specific file.
When you run it from the php script, it is the http server account on your system, which needs the permission to execute the file in /usr/bin. Usually this is the apache user.
How you should setup permissions depends on your system. Just remember that what is allowed for apache, is allowed for anyone accessing your http server.
I have had this problem for ages and adding . ' 2>&1' after the $command has somehow solved the problem.
this:
$output = shell_exec($command . ' 2>&1');
instead of:
$output = shell_exec($command);
No idea why but it works and I'm grateful.
Is it a shared hosting? It seems like shell_exec is a restricted function. Try running error_reporting(E_ALL); ini_set('display_errors', 1); before calling shell_exec.
I stumbled upon the same Problem, in my case an absolut Path in the exec Command like /var/www did not work, I had to use relative Paths from the point where I executed the php File.
I also wanted to notice, that it did not work using shell_exec, however it worked using normal exec command, not sure wheres the difference here.

Running PhantomJS from PHP with exec()

I've got the following script:
#!/bin/sh
export DISPLAY=:0
phantomjs --version
It try to run it from the following PHP script:
<?php
$result = shell_exec('sh test.sh');
echo $result;
?>
This script return the following error:
[Thu Jun 19 10:31:31 2014] [error] [client] test.sh: line 3: phantomjs: command not found
I tried to run phantomjs -v by hand in a console, and it runs fine. I checked the PATH, and phantomjs is correctly defined and found.
The execution environment is a virtual Server with LiveConfig.
Can someone help me understand what I'm doing wrong ?
It could be an issue with shell_exec() and line breaks,
try adding "2>&1" to the string you are passing:
$result = shell_exec('sh test.sh 2>&1');
this worked for me, found it in the top comment here, naturally ;)
Your PATH probably lacks the location for the phantomjs executable. PhantomJS is probably installed in /usr/local/bin so you need to add this to your PATH variable:
#!/bin/sh
export DISPLAY=:0
PATH=$PATH:/usr/local/bin
phantomjs --version
To check what the current PATH is, you could begin the shell script with:
#!/bin/sh
echo $PATH
<?php
exec('/usr/local/bin/phantomjs path/somescript.js');
?>
Yes. Sometimes phantomjs don't need full path in some environment without generate any error. However, sometimes it does.
Always use the full path for all argument in the php command.
Did you use the fullpath for hello.js?
Do not use exec(). Never. It's a bad way.
Use the php-phantomjs and PhantomJS Runner instead.

PHP shell_exec() - having problems running command

Im new to php shell commands so please bear with me. I am trying to run the shell_exec() command on my server. I am trying the below php code:
$output = shell_exec('tesseract picture.tif text_file -l eng');
echo "done";
I have the picture.tif in the same directory as the php file. In my shell I can run this without a problem.
It takes a while to run the code, then it doesnt make the text_file like it does when I run it in command prompt.
Per your comment:
Should I write a loop in shell
instead?
You can write a very simple shell script to run the command in a loop. Create the script file first:
touch myscript.sh
Make the script executable:
chmod 700 myscript.sh
Then open it with a text editor such as vim and add this:
for (( i = 0 ; i <= 5; i++ ))
do
tesseract picture.tif text_file -l eng
done
Thats the very basics of it (not sure what else you need), but that syntax should help get you started. To run the script, do this if you're in the same directory as the script:
./myscript.sh
Or specify the full path to run it from anywhere:
/path/to/mydir/myscript.sh
Could this be a permissions issue? My guess is that PHP isn't running with the same permissions that you do when you execute the command directly from the command prompt. What OS are you running on?

Categories