OVH CRON: How to execute a Symfony command? - php

How to execute a Symfony command with OVH cron?
I created a command on my symfony project:
php bin/console cron:test
I defined my Cron in the OVH table "Scheduled Tasks - Cron":
Command: cron/test.sh
Language: Other
test.sh is executable (chmod 700).
In test.sh I do not know what to write.
I tested several code found on the internet without success, including this one (with a php file):
OVH cron jobs / Symfony Command
I am using php 7.1.
What is the logic that applies to find this code? Thanks in advance for the help.

I got my answer. Thank you #Tomasz for your help.
phpinfo() showed me the way.
The solution:
#!/bin/bash
/usr/local/php7.1/bin/php /homez.ovhNumber/myWebsite/symphonyProject/bin/console cron:test

In command field you should be able to enter command you want to execute. But because you don't know from where it will be executed you have to specify full path to command for example:
php /var/www/my-project/bin/console cron:test
But, I'm not familiar with OVH Tools so if you need to create bash file which will be run by cron, then your file should like like this:
#!/bin/bash
php /var/www/my-project/bin/console cron:test
Here is the same principal with the full path to your bin/console file.

Related

Executing Php scripts in Airflow worker

I am a newbie to Airflow. I am working on a project , where i need to execute a php script in Airflow worker node.I am using S3 bucket to fetch the said scripts , but when i trigger them using bash command , I get php command not found error.Also there is no operator to execute php scripts like the PythonOperator
{things I've tried so far but didn't work}:
tried installing php compiler/interpreter -> you need root privileges error
tried the same using sudo -> sudo command not found error
P.S. tbh I very close to punching my monitor , plwease help!!

start a program from cmd with full permission

i have an application called app.exe it's create a file called account.txt in the same folder c:\ , the problem is that when i run the program from php exec function or cmd the account.txt file is not creating
i think the problem is from the permissions.
Run From: What happened
Manualy Executed and created the file account.txt
PHP exec Executed but it did't create account.txt
CMD Executed but it did't create account.txt
for php i use:
exec("C:\\windows\\system32\\cmd.exe /c START c:\app.exe");
for cmd i use:
START C:\app.exe
A program that requires elevation should specify so in its manifest. This would not help with the PHP issue though, especially if this is a web server using PHP. It is not possible to elevate without showing the UAC UI.
I'm not aware of a simple way to request elevation when executing something in Cmd. You might just have to start Cmd elevated (Right-click and "Run as Administrator").
PHP might be running as a different user but you gave us zero information about your setup so I don't know.
Without knowing anything about app.exe nor your Windows version or general configuration it is hard to give specific advise.
If you want to confirm that it as a permissions problem you can try running Process Monitor so you can see why the file operation fails.
You should be able to use the runas command
runas /profile /user:*admin user here* “*path to program here*”
you will then be prompted for that users password and after that it should run as admin.

how to execute a source command from php in a server

I am unable to execute a source command in linux using php.All other commands are working except this one. I need to execute the following command.
source /root/Envs/ate/bin/activate
This activates the ate-Automatic Test Equipment.Once I activate it then I need to run a python script as the script accesses the remote server.
I am able to manually run it but I am creating a tool which will automatically do it.
<?php
exec("source /root/Envs/ate/bin/activate", $output, $return);
echo "Command returned $return, and output:\n";
echo exec("python box_upgrade-pradeepa.py");
?>
The above commands returns 1 which means there is an error.But I am not sure how to run the 'source command'. The python script will run only if the source command is successful.(the python command is correct as I replaced hello.py and it ran fine.)
Could you pls help me as I am really stuck for a week?
Thanks a lot..
I found out the error. Since I am doing it using php (for a web tool) the user is Apache. 'Apache' user is unable to access the script in root folder. Moving it to another directory, I am able to run the script fine.
Thanks all..

Using PHP to run ANT Build.xml file on Server

I'm trying to run a Ant build.xml file via a cronjob. I have seen that i can run system commands with php and wondered whether these could be used to run the ant build file? If so i can then setup a cron job to run the php file every night?
Does anyone know whether this is possible?
For instance i have the following in my php file:
system("ant ./build/cronjob/build.xml");
Although this produces output it doesn't appear to be working?
Has anyone else come across this?
First step is to ensure you can run ant ./build/cronjob/build.xml from command prompt. Creating cron entry will be then straight forward.
I prefer creating a wrapper script, say $HOME/scripts/callant.sh. The script could be like
#!bash
#setup variables
BUILD_FILE=/build/cronjob/build.xml
ANT_CMD=/pathtoant/bin/ant
JAVA_HOME=<path to jdk>
#setup path
#setp LD_LIBRARY_PATH ..
$ANT_CMD -f $BUILD_FILE > /tmp/$$out.log 2>/tmp/$$err.log

Cannot execute crontab command from a php script...from shared host

I'm running an application where I need to execute the cron job, once a form is submitted,contains more than 1 lac records in a loop(its on-demand execution of cron job and deletes the job once finished).
I'm using php, I tried to configure the job through cpanel as a test and it works...the command was.."/ramdisk/bin/php5 -f /home/user/public_html/domain/cron.php -q", it worked fine.
But when I tried to run the same job with the exec() of php, like I wrote this whole command to a file (I do not know where the original crontab file is located otherwise could have written to it, please suggest a way to find its location) and ran that file like "exec("crontab /home/user/cron/Feed_cron"); ", in this cron is not working...
I doubted whether the crontab command will not work for particular user.. I tried it from the "root" user....which is the root user....tried the command via SSH or Putty and the response was "command not found". Please find a solution for this, also please give me an idea whether my concept works fine...
please suggest a way to find its location
Try
whereis crontab

Categories