Here is my problem. I'm developping a Symfony project which acces to telephony and emails data from OVH API. For that, I use cron job (from Ovh board).
I have php files ( home/mySite/www/command.php) which contains :
<?php
shell_exec("sh mycommand.sh");
?>
And my bash file ( home/mySite/mycommand.sh) :
#!/bin/bash
cd /homez.mynumber/mysite/www
/usr/local/php5.6/bin/php bin/console converseo:updateTelephony
I'm sure that the path is good cause I get error line 2: cd: /homez.mynumber/mysite/www: No such file or directory
So I removed line 2 :
#!/bin/bash
/usr/local/php5.6/bin/php bin/console converseo:updateTelephony
And get error No such file or directory
I actually don't know how to make it works. Thanks for yout help !
What is the name of your command? Does it end with "Command" as mentioned in symfony doc: http://symfony.com/doc/current/console.html
Related
My system is :
Ubuntu 20.04
Php 7.4
Nginx
I have a php file with following content in /var/www/hamrah.com/create.php path :
<?php
$output = shell_exec('bash flutter create test');
echo "<pre>$output</pre>";
i run this command in terminal and And this command executes correctly (creates a flutter project for me)
cd /var/www/hamrah.com && php /var/www/hamrah.com/create.php
BUT !
But when I put this command in Crontab, the command is not executed properly and gives an error
In Crontab :
* * * * * cd /var/www/hamrah.com && php /var/www/hamrah.com/create.php
Note: If I put shell_exec(' bash ls') instead of shell_exec('bash flutter creat test') in the php file, it will run well and some commands like the flutter create command will not be executed.
error : bash: flutter: No such file or directory
You can test
<?php
$output = shell_exec('bash /opt/flutter/bin/flutter create test');
echo "<pre>$output</pre>";
Cron doesn't read user's environment variables, the default value of PATH is /usr/bin:/bin, usually your flutter SDK won't be located in these 2 folders, so you need explictly specify the location of the flutter SDK. Add this line to the crontab.
PATH=/usr/bin:/bin:/path-to-flutter-sdk-bin
Use the following command if you don't know where flutter is.
which flutter
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.
I'm developing a Symfony project and I've 4 commands which allows me to update telephony and emails data thanks to OVH' Api. When I use my terminal on local ( php bin/console converseo:updateTelephony ) the command works fine.
Now, I want to put these commands in crontab with the cron interface from Ovh. I made a php file test.php :
<?php
shell_exec("sh test.sh");
?>
And test.sh :
#!/bin/bash
/usr/local/php5.6/bin/php /homez.number/mysite/www/bin/console converseo:updateBilling
And I get the error :
[Symfony\Component\Console\Exception\CommandNotFoundException]
Command "converseo:updateBilling" is not defined.
Did you mean one of these?
converseo:updateBilling
converseo:updateEmailCount
converseo:updateTelephony
converseo:updateEmail
The lines are EXACTLY the sames, I don't understand why I get this error.
Thanks a lot for yours answers !
I have written simple php script to help me update site contents when the commit is sent to bitbucket. I have following problem with it.
<?php
$repo_dir = '/var/www/vhosts/my_full_path';
$output = shell_exec('cd '.$repo_dir.' && hg --config auth.rc.prefix=https://bitbucket.org/XXXXX --config auth.rc.username=my_username --config auth.rc.password=my_pass pull -u https://bitbucket.org/XXXXXXX &');
echo $output;
?>
When I type it to web browser it doesn't work. The output of script is:
pulling from https://bitbucket.org/XXXXXXXXXXXXXX
but when I try to execute it under console on the server it works like a charm:
php myscript.php
generates following output:
pulling from https://bitbucket.org/XXXX
searching for changes
adding changesets
adding manifests
adding file changes
added 2 changesets with 2 changes to 1 files
1 files updated, 0 files merged, 0 files removed, 0 files unresolved
See the oupt is full and correct! in concole I'm using root user in web browser data-www? Is there any difference in this case?
I have found the solution. I hope it helps someone.
There were two problems:
Permissions to my repo dir
Authentication for user www-data for this repo
The problem occured because web browser doesn't flush warnings and abort messages while executing command shell_exec. If you want to test your script, you have to lgoin to console by SSH (as root for example) then execute script / command as apache user:
sudo -u www-data php /path-to-your-script/script.php
In console you will see all problems which following user generates.
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