shell-exec

How To Execute SSH Commands Via PHP

十年热恋 提交于 2019-11-26 15:11:09
I am looking to SSH out via PHP. What is the best/most secure way to go about this? I know I can do: shell_exec("SSH user@host.com mkdir /testing"); Anything better? That feels so 'naughty' :). I would use phpseclib, a pure PHP SSH implementation . An example: <?php include('Net/SSH2.php'); $ssh = new Net_SSH2('www.domain.tld'); if (!$ssh->login('username', 'password')) { exit('Login Failed'); } echo $ssh->exec('pwd'); echo $ssh->exec('ls -la'); ?> Do you have the SSH2 extension available? Docs: http://www.php.net/manual/en/function.ssh2-exec.php $connection = ssh2_connect('shell.example.com',

List of &#39;if&#39; switches anywhere?

余生颓废 提交于 2019-11-26 13:44:41
Is there a list of all the if switches for use in bash scripting? Sometimes I see someone using it and I wonder what the switch they're using actually does. Example is the -z in this one. I know how to use it, but I don't know where it was derived from. if [ -z "$BASH_VERSION" ]; then echo -e "Error: this script requires the BASH shell!" exit 1 fi Any references, guides, posts, answers would be appreciated. SheetJS Look at the bash manpage ( man bash ). The options are specified in the CONDITIONAL EXPRESSIONS section: CONDITIONAL EXPRESSIONS Conditional expressions are used by the [[ compound

Passing multiple PHP variables to shell_exec()?

不想你离开。 提交于 2019-11-26 11:08:31
问题 I am calling test.sh from PHP using shell_exec method. $my_url=\"http://www.somesite.com/\"; $my_refer=\"http://www.somesite.com/\"; $page = shell_exec(\'/tmp/my_script.php $my_url $my_refer\'); However, the command line script says it only received 1 argument: the /tmp/my_script.php When i change the call to: Code: $page = shell_exec(\'/tmp/my_script.php {$my_url} {$my_refer}\'); It says it received 3 arguments but the argv[1] and argv[2] are empty. When i change the call to: Code: $page =

Pinging an IP address using PHP and echoing the result

£可爱£侵袭症+ 提交于 2019-11-26 08:46:37
I have the following function that I doesn't work so far. I would like to ping an IP address and then to echo whether the IP is alive or not. function pingAddress($ip){ $pingresult = shell_exec("start /b ping $ip -n 1"); $dead = "Request timed out."; $deadoralive = strpos($dead, $pingresult); if ($deadoralive == false){ echo "The IP address, $ip, is dead"; } else { echo "The IP address, $ip, is alive"; } } When I call this function using the example: pingAddress("127.0.0.1") The echo result is always 'dead' - no matter what. Could someone please help me where I'm going wrong? And/OR is there a

How To Execute SSH Commands Via PHP

余生长醉 提交于 2019-11-26 04:39:14
问题 I am looking to SSH out via PHP. What is the best/most secure way to go about this? I know I can do: shell_exec(\"SSH user@host.com mkdir /testing\"); Anything better? That feels so \'naughty\' :). 回答1: I would use phpseclib, a pure PHP SSH implementation. An example: <?php include('Net/SSH2.php'); $ssh = new Net_SSH2('www.domain.tld'); if (!$ssh->login('username', 'password')) { exit('Login Failed'); } echo $ssh->exec('pwd'); echo $ssh->exec('ls -la'); ?> 回答2: Do you have the SSH2 extension

List of &#39;if&#39; switches anywhere?

大憨熊 提交于 2019-11-26 02:38:24
问题 Is there a list of all the if switches for use in bash scripting? Sometimes I see someone using it and I wonder what the switch they\'re using actually does. Example is the -z in this one. I know how to use it, but I don\'t know where it was derived from. if [ -z \"$BASH_VERSION\" ]; then echo -e \"Error: this script requires the BASH shell!\" exit 1 fi Any references, guides, posts, answers would be appreciated. 回答1: Look at the bash manpage ( man bash ). The options are specified in the

Pinging an IP address using PHP and echoing the result

你离开我真会死。 提交于 2019-11-26 02:00:44
问题 I have the following function that I doesn\'t work so far. I would like to ping an IP address and then to echo whether the IP is alive or not. function pingAddress($ip){ $pingresult = shell_exec(\"start /b ping $ip -n 1\"); $dead = \"Request timed out.\"; $deadoralive = strpos($dead, $pingresult); if ($deadoralive == false){ echo \"The IP address, $ip, is dead\"; } else { echo \"The IP address, $ip, is alive\"; } } When I call this function using the example: pingAddress(\"127.0.0.1\") The