exec linux command via php - php

I'm working with a multimedia router with Linux Linaro as OS. I'm having problems when I try to make a red monitorization with iptraf. If I use iptraf in shell, it works perfectly. The problem appears when I try to run the same command through a php script.
This is the line:
shell_exec("iptraf -i wlan0 -L ../../../mnt/web0/mantenimientoV2/log2.txt");
As I said, this command works perfectly in shell and creates the log, but if I execute it with php, it doesn't create the log. I need this log, what can I do?

Related

Run MTProxy remotely by PHP exec on Windows server

I installed PM2 and node.js on the Windows server to run JSMTProxy-master script.
The command for the run proxy is: (pm2 start "JSMTProxy-master\mtproxy.js" -i max) and it executed successfully in the CMD window with no problem.
Now I want to execute this command by PHP and exec.
I tried this:
exec ('pm2 start "JSMTProxy-master\mtproxy.js" -i max');
Or this: (just showed up cmd.exe in taskmgr)
exec ('c:\WINDOWS\system32\cmd.exe /c START "pm2 start c:\mypath\JSMTProxy-master\mtproxy.js -i max"');
Or this:
exec ('c:\WINDOWS\system32\cmd.exe /c START "JSMTProxy-master\mtp-run.bat"');
These don't work and nothing happens. no error, no process showed up in taskmgr.
How is it supposed to be to run by exec?
Note. I have PHP installed and working perfectly.
After trying different ways many times, Finally i found the problem.
"PM2" doesn't execute under PHP exexc. It has to be with full path of exe files.
I changed my command as below and it worked:
shell_exec('C:\Users\Administrator\AppData\Roaming\npm\pm2.cmd start "C:\mypath\JSMTProxy-master\mtproxy.js" -i max')

Running Linux DAEMON PHP files, does not execute exec, but does when ran from console

I have a php script that works perfectly when ran form command line; including the exec().
The exec I do are calling some .sh scripts.
These .sh script are of type bash
So I call them:
exec('/bin/bash /home/user/soft/bin/mybash.sh > /dev/null');
It works great when I run my php from command line I see all the instructions; works also when use with an alias. but when I it via a daemon:
sudo -u myuser php -f /home/user/bin/serverwait.php eveything that should be done in the .sh are not being done. but the rest of the file is doing what it is suppose to do (it checks for open ports and write to a log file)
I tried looking at my php.ini for cli and all seems right.

running docker request from php

I have encapsulated pdftk (PDF tool kit) as program that can be run inside of a fedora docker image. This allows me to run pdftk on a newer AWS AMI image that does not support pdftk. When replacing pdftk in our PHP program with the docker run command, it works great when running the PHP program from the command line, but when running it as a cron job or as a mailbox command, docker will not run. I have made the cron and mailbox users part of the docker group, checked permissions and paths, but still no joy.
The exec PHP command looks like:
$command = 'docker run -i -t --privileged -v /var/www/mbx/forms/inbox:/workdir -w /workdir/ brnlab/aultman-pdftk ./'.basename($files[$i]).' burst output ./pg_%03d.pdf';
Oddly the return on the $command when running this as a cron or mailbox command is blank, so I am not sure if there is an error or not. It does not appear to hang up. Any ideas on the best way to diagnose the issue further?

PHP execute asyncronous php script in shell command doesn't work on bitnami LAMP AWS

on my local machine I execute the following:
exec('sudo nohup '.PHP_BINDIR.'/php '.ROOT.'/index.php controller=imports action=import id=12 > /dev/null 2>&1 &');
where "ROOT" is a constant with the complete path.
Everything works fine and the script is executed asyncronously with no problems.
When I run the same script on production environment (a bitnami LAMP stack running on AWS) instead: if I run it directly from the terminal it works, when I run it from php it doesn't.
I have nothing in the apache error_log and if I run it with shell_exec the returned value is NULL.
If I try to execute a different script from php (like exec('whoami')) it works, so I don't think is a permissions thing.
I also tried replacing php command with php-cli, nothing changes.
Hope someone can help.
Thanks in advance.

Running wget with PHP and apache (MAMP)

I have trouble running wget through php exec or system functions. The configuration is with MAMP.
I successfully run basic commands like ('whoami', 'pwd', etc.).
I even changed the apache user to the root user and still nothing. In the error log it output "wget: command not found".
I can run with the terminal and it works fine. The wget is installed through Macports.
What should I do?
Regards!
From a terminal, run which wget, and use the full path in the call to exec/system.

Categories