PsExec from PHP does not run me - php

Executing the PsExce command from the shell_exce or exce does not generate any action on the machine that sent the command
My php code is
$execute = "C:\\pstools\\PsExec.exe \\\\".$ip." -u ".$user." -p xxxxxxxx -i -h -d C:\\app\\ejecutar.bat 1";
exec($execute,$out);
print_r($out);
The message that comes back to me is this
If that command is executed from the console if you run it on the remote machine

Related

PHP: shell_exec rejects password for a shell command but works in shell

Following code executes in php,
shell_exec('echo '.$passkey.' | sudo -u '.$user.' -S sh '.$shellfile.' 2>&1');
Basic shell file,
#!/bin/sh
echo "hello"
The shell command alone returns Password:hello as expected on the first run (returns "hello" after "Password" prompt).
shell_exec return the following error,
Password:Sorry, try again.
Password:
sudo: no password was provided
sudo: 1 incorrect password attempt
Need help to understand where or what the issue is.

Launch pg_restore via CMD with PHP doesn't work

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';

Run php server through shell_exec and save its output to variable

When I try to run shell_exec("php -S localhost:8000"), it runs the server but it freezes the terminal.
I tried running $result = shell_exec('php -S localhost:8000 -t public/ &> /dev/null 2>&1') but it doesn't store the output to the variable.
The idea is so that I can customize the output message once server successfully boots up.

Run a command on a SSH screen through SSH with phpseclib

I have a PHP script that starts a detached screen through SSH:
$ssh->exec("screen -m -d -S ".$user);
I now need to execute a command in that screen without being in that screen. I have the code that does that, which I have tested through a SSH client, but when I try to use it with the phpseclib exec command, it does not work. This is the code that works:
screen -S ".$user." -X stuff "cd minecraft/servers/".$user."/;sh start.sh $(printf '\r')"
And this is it in the PHP script:
$ssh->exec("screen -S ".$user." -X stuff \"cd minecraft/servers/".$user."/;sh start.sh $(printf '\r')\"");
I attempted to escape the extra double quotes in the code.
Is there anything I can do to make this work through PHP? Thanks
Hmmm...
create please two bash script, first: create screen with user parameter with name f.e. run_screen, second: tester for SSH client with user parameter with name f.e. run_test.
Run first script:
$ssh->exec('[full_path]/run_screen ' . $user);
and second:
$ssh->exec('[full_path]/run_test ' . $user);
bash syntax is here bash syntax
Sure that the user of server (f.e. Apache) has permissions to run scripts.

Pass php variable to exec

I need to get dimm info using ipmitool as follows:
exec("/usr/bin/ipmitool -I lan -H $spip -U root -P '$thepassword' sunoem cli 'show System/Memory/DIMMs/$a' | grep -i location", $dimm_loc, $ipmiretval);
$a is previously defined as:
$a=$dimm[$i]
The return value for the above exec command is 1. If I replace $a with its vaule, i.e
exec("/usr/bin/ipmitool -I lan -H $spip -U root -P '$thepassword' sunoem cli 'show System/Memory/DIMMs/D5' | grep -i location", $dimm_loc, $ipmiretval);
The exec command executes as expected. So it looks like $a cannot be used in the above example. How else can I pass the variable to the exec command?
Thanks!!
Run var_dump($a) and see what actualy it contains. Also dump the executed command as a string to see if command is formated properly.
One more tip. Instead of doing an exec("some very long command line"), put your command line in a variable, then both LOG and exec() the variable. For example:
$fmt="/usr/bin/ipmitool -I lan -H %s -U root -P '%s' sunoem cli 'show System/Memory/DIMMs/%s' | grep -i location";
$cmd=sprintf($fmt, $spip, $thepassword, $a);
exec($cmd, $dimm_loc, $ipmiretval);
syslog(LOG_DEBUG, "Running: $cmd");
if ($ipmiretval > 0) {
syslog(LOG_ERR, "exec FAILED: $cmd");
} else {
syslog(LOG_DEBUG, "exec: $cmd");
}

Categories