How to use shell_exec method of pts_client class

Best Phoronix-test-suite code snippet using pts_client.shell_exec

pts_network.php

Source:pts_network.php Github

copy

Full Screen

...367 $dev = '';368 // try and get the device with the default route369 if ($ip = pts_client::executable_in_path('ip'))370 {371 $out = shell_exec("$ip route 2>&1");372 $start = strpos($out, ' dev ');373 if($start !== false)374 {375 $start += 5; // length of ' dev '376 if(($xx = strpos($out, ' ', $start)) !== false)377 {378 $dev = substr($out, $start, $xx - $start);379 }380 }381 }382 // we grab the last field of the `netstat -nr` output, betting on *bsd not expiring it's default route383 if(empty($dev) && $netstat = pts_client::executable_in_path('netstat')) {384 $out = shell_exec("$netstat -rn 2>&1");385 $lines = explode("\n", $out);386 foreach ($lines as $line) {387 $start = substr($line,0,7);388 if ($start == '0.0.0.0' || $start === 'default') {389 $dev = trim(substr(trim($line),strrpos($line,' ')));390 return $dev;391 }392 }393 }394 return $dev;395 }396 public static function get_local_ip()397 {398 $local_ip = false;399 $interface = self::get_active_network_interface();400 if(($ifconfig = pts_client::executable_in_path('ifconfig')))401 {402 $ifconfig = shell_exec($ifconfig . " $interface 2>&1");403 $offset = 0;404 while(($ipv4_pos = strpos($ifconfig, 'inet addr:', $offset)) !== false)405 {406 $ipv4 = substr($ifconfig, $ipv4_pos + strlen('inet addr:'));407 $ipv4 = substr($ipv4, 0, strpos($ipv4, ' '));408 $local_ip = $ipv4;409 if($local_ip != '127.0.0.1' && $local_ip != null)410 {411 break;412 }413 $offset = $ipv4_pos + 1;414 }415 if($local_ip == null)416 {417 while(($ipv4_pos = strpos($ifconfig, 'inet ', $offset)) !== false)418 {419 $ipv4 = substr($ifconfig, $ipv4_pos + strlen('inet '));420 $ipv4 = substr($ipv4, 0, strpos($ipv4, ' '));421 $local_ip = $ipv4;422 if($local_ip != '127.0.0.1' && $local_ip != null)423 {424 break;425 }426 $offset = $ipv4_pos + 1;427 }428 }429 }430 else if(phodevi::is_windows())431 {432 $ipconfig = shell_exec('ipconfig');433 $offset = 0;434 while(($ipv4_pos = strpos($ipconfig, 'IPv4 Address.', $offset)) !== false)435 {436 $ipv4 = substr($ipconfig, $ipv4_pos);437 $ipv4 = substr($ipv4, strpos($ipv4, ': ') + 2);438 $ipv4 = substr($ipv4, 0, strpos($ipv4, "\n"));439 $local_ip = trim($ipv4);440 if($local_ip != '127.0.0.1' && $local_ip != null && strpos($local_ip, '169.254') === false)441 {442 break;443 }444 $offset = $ipv4_pos + 3;445 }446 }447 else if(pts_client::executable_in_path('hostname'))448 {449 $hostname_i = explode(' ', trim(shell_exec('hostname -I 2>&1')));450 $hostname_i = array_shift($hostname_i);451 if(count(explode('.', $hostname_i)) == 4)452 {453 $local_ip = $hostname_i;454 }455 }456 if(empty($local_ip) && function_exists('net_get_interfaces'))457 {458 // The below code should work as of net_get_interfaces() as of PHP 7.3 in cross-platform manner459 $net_interfaces = net_get_interfaces();460 foreach($net_interfaces as $interface => $interface_info)461 {462 if(isset($interface_info['unicast'][1]['address']) && !empty($interface_info['unicast'][1]['address']) && $interface_info['unicast'][1]['address'] != '127.0.0.1')463 {464 $local_ip = $interface_info['unicast'][1]['address'];465 break;466 }467 }468 }469 return $local_ip;470 }471 public static function get_network_mac()472 {473 $mac = false;474 if(phodevi::is_linux())475 {476 if($interface = self::get_active_network_interface())477 {478 $addr = "/sys/class/net/$interface/address";479 if(is_file($addr))480 {481 $mac = pts_file_io::file_get_contents($addr);482 }483 }484 if(empty($mac))485 {486 foreach(pts_file_io::glob('/sys/class/net/*/operstate') as $net_device_state)487 {488 if(pts_file_io::file_get_contents($net_device_state) == 'up')489 {490 $addr = dirname($net_device_state) . '/address';491 if(is_file($addr))492 {493 $mac = pts_file_io::file_get_contents($addr);494 break;495 }496 }497 }498 }499 }500 else if(phodevi::is_windows())501 {502 $getmac = shell_exec('getmac');503 $getmac = trim(substr($getmac, strpos($getmac, "\n", strpos($getmac, '======='))));504 $getmac = substr($getmac, 0, strpos($getmac, ' '));505 if(strlen($getmac) <= 17)506 {507 $mac = str_replace('-', ':', $getmac);508 }509 }510 if(empty($mac) && ($ifconfig = pts_client::executable_in_path('ifconfig')))511 {512 $ifconfig = shell_exec($ifconfig . ' 2>&1');513 $offset = 0;514 while(($hwaddr_pos = strpos($ifconfig, 'HWaddr ', $offset)) !== false || ($hwaddr_pos = strpos($ifconfig, 'ether ', $offset)) !== false)515 {516 $hw_addr = substr($ifconfig, $hwaddr_pos);517 $hw_addr = substr($hw_addr, (strpos($hw_addr, ' ') + 1));518 $hw_addr = substr($hw_addr, 0, strpos($hw_addr, ' '));519 if(($x = strpos($hw_addr, PHP_EOL)) != false)520 {521 $hw_addr = substr($hw_addr, 0, $x);522 }523 $mac = $hw_addr;524 if($mac != null)525 {526 break;527 }528 $offset = $hwaddr_pos + 1;529 }530 }531 if(empty($mac) && ($netstat = pts_client::executable_in_path('netstat')))532 {533 // Needed on at least OpenBSD as their `ifconfig` does not expose the MAC address534 $netstat = shell_exec($netstat . ' -in 2>&1');535 foreach(explode(PHP_EOL, $netstat) as $line)536 {537 $line = explode(' ', $line);538 foreach($line as $i => $r)539 {540 if($r == null)541 unset($line[$i]);542 }543 $line = array_values($line);544 if(!isset($line[3]))545 {546 continue;547 }548 $address = explode(':', $line[3]);549 if(count($address) == 6 && $address[0] != '00' && $address[5] != '00')550 {551 foreach($address as $seg)552 {553 if(strlen($seg) != 2)554 {555 continue;556 }557 }558 $mac = $line[3];559 }560 }561 }562 return $mac;563 }564 public static function get_network_wol()565 {566 static $wol_support = null;567 if($wol_support === null)568 {569 $wol_support = array();570 if(is_dir('/sys/class/net'))571 {572 if(pts_client::executable_in_path('ethtool'))573 {574 foreach(pts_file_io::glob('/sys/class/net/*') as $net_device)575 {576 if(!is_readable($net_device . '/operstate') || trim(file_get_contents($net_device . '/operstate')) != 'up')577 {578 continue;579 }580 $net_name = basename($net_device);581 $ethtool_output = shell_exec('ethtool ' . $net_name . ' 2>&1');582 if(($x = stripos($ethtool_output, 'Supports Wake-on: ')) !== false)583 {584 $ethtool_output = substr($ethtool_output, $x + strlen('Supports Wake-on: '));585 $ethtool_output = trim(substr($ethtool_output, 0, strpos($ethtool_output, PHP_EOL)));586 $wol_support[$net_name] = $net_name . ': ' . $ethtool_output;587 }588 }589 }590 if(empty($wol_support) && pts_client::executable_in_path('nmcli'))591 {592 foreach(pts_file_io::glob('/sys/class/net/*') as $net_device)593 {594 if(!is_readable($net_device . '/operstate') || trim(file_get_contents($net_device . '/operstate')) != 'up')595 {596 continue;597 }598 $net_name = basename($net_device);599 $ethtool_output = shell_exec('nmcli c show ' . $net_name . ' 2>&1');600 if(($x = stripos($ethtool_output, '.wake-on-lan:')) !== false)601 {602 $ethtool_output = substr($ethtool_output, $x + strlen('.wake-on-lan:'));603 $ethtool_output = trim(substr($ethtool_output, 0, strpos($ethtool_output, PHP_EOL)));604 if(strpos($ethtool_output, '1') || strpos($ethtool_output, 'default'))605 {606 shell_exec('nmcli connection modify ' . $net_name . ' 802-3-ethernet.wake-on-lan magic 2>&1'); // TODO this really needed?607 $wol_support[$net_name] = $net_name . ': g';608 }609 }610 }611 }612 }613 }614 return $wol_support;615 }616 public static function send_wol_packet($ip_address, $mac_address)617 {618 $hwaddr = null;619 foreach(explode(':', $mac_address) as $o)620 {621 $hwaddr .= chr(hexdec($o));622 }623 $packet = null;624 for($i = 1; $i <= 6; $i++)625 {626 $packet .= chr(255);627 }628 for($i = 1; $i <= 16; $i++)629 {630 $packet .= $hwaddr;631 }632 $sock = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);633 if($sock)634 {635 $options = socket_set_option($sock, 1, 6, true);636 if($options >= 0)637 {638 $sendto = socket_sendto($sock, $packet, strlen($packet), 0, $ip_address, 7);639 socket_close($sock);640 return $sendto;641 }642 }643 return false;644 }645 public static function find_zeroconf_phoromatic_servers($find_multiple = false)646 {647 $hosts = $find_multiple ? array() : null;648 if(!pts_network::network_support_available())649 {650 return $hosts;651 }652 if(PTS_IS_CLIENT && pts_client::executable_in_path('avahi-browse'))653 {654 $avahi_browse = explode(PHP_EOL, shell_exec('avahi-browse -p -r -t _http._tcp 2>&1'));655 foreach(array_reverse($avahi_browse) as $avahi_line)656 {657 if(strrpos($avahi_line, 'phoromatic-server') !== false)658 {659 $avahi_line = explode(';', $avahi_line);660 if(isset($avahi_line[8]) && ip2long($avahi_line[7]) !== false && is_numeric($avahi_line[8]))661 {662 $server_ip = $avahi_line[7];663 $server_port = $avahi_line[8];664 //echo $server_ip . ':' . $server_port;665 if($find_multiple)666 {667 $hosts[] = array($server_ip, $server_port);668 }...

Full Screen

Full Screen

toggle_screensaver.php

Source:toggle_screensaver.php Github

copy

Full Screen

...55 self::$gnome_gconftool = $gt;56 }57 if(self::$gnome_gconftool != false)58 {59 $is_gnome_screensaver_enabled = trim(shell_exec(self::$gnome_gconftool . ' -g /apps/gnome-screensaver/idle_activation_enabled 2>&1'));60 if($is_gnome_screensaver_enabled == 'true')61 {62 // Stop the GNOME Screensaver63 shell_exec(self::$gnome_gconftool . ' --type bool --set /apps/gnome-screensaver/idle_activation_enabled false 2>&1');64 self::$gnome2_screensaver_halted = true;65 }66 $sleep_display_ac = trim(shell_exec(self::$gnome_gconftool . ' -g /apps/gnome-power-manager/timeout/sleep_display_ac 2>&1'));67 if($sleep_display_ac != 0)68 {69 // Don't sleep the display when on AC power70 shell_exec(self::$gnome_gconftool . ' --type int --set /apps/gnome-power-manager/timeout/sleep_display_ac 0 2>&1');71 self::$sleep_display_ac = $sleep_display_ac;72 }73 }74 if(pts_client::executable_in_path('qdbus'))75 {76 // KDE Screensaver?77 $is_kde_screensaver_enabled = trim(shell_exec('qdbus org.freedesktop.ScreenSaver /ScreenSaver org.freedesktop.ScreenSaver.GetActive 2>&1'));78 if($is_kde_screensaver_enabled == 'true')79 {80 // Stop the KDE Screensaver81 shell_exec('qdbus org.freedesktop.ScreenSaver /ScreenSaver SimulateUserActivity 2>&1');82 self::$kde_screensaver_halted = true;83 }84 }85 if(self::$gnome2_screensaver_halted == false && pts_client::executable_in_path('gsettings'))86 {87 // GNOME 3.x Screensaver?88 $is_gnome3_screensaver_enabled = trim(shell_exec('gsettings get org.gnome.desktop.session idle-delay 2>&1'));89 if(stripos($is_gnome3_screensaver_enabled, 'no such key') === false && pts_strings::last_in_string($is_gnome3_screensaver_enabled) > 0)90 {91 // Stop the GNOME 3.x Screensaver92 shell_exec('gsettings set org.gnome.desktop.session idle-delay 0 2>&1');93 self::$gnome3_screensaver_halted = pts_strings::last_in_string($is_gnome3_screensaver_enabled);94 }95 // GNOME 3.x Lock-Screen96 $is_gnome3_lockscreen_enabled = trim(shell_exec('gsettings get org.gnome.desktop.lockdown disable-lock-screen 2>&1'));97 if(stripos($is_gnome3_lockscreen_enabled, 'no such key') === false && pts_strings::last_in_string($is_gnome3_lockscreen_enabled) == 'false')98 {99 // Stop the GNOME 3.x Lock Screen100 shell_exec('gsettings set org.gnome.desktop.lockdown disable-lock-screen true 2>&1');101 self::$gnome3_lockscreen_disabled = true;102 }103 // This GNOME3 GSettings method is deprecated on distributions like GNOME 3.8 with Fedora 19104 $is_gnome3_screensaver_enabled_old = trim(shell_exec('gsettings get org.gnome.desktop.screensaver idle-activation-enabled 2>&1'));105 if($is_gnome3_screensaver_enabled_old == 'true')106 {107 // Stop the GNOME 3.x Screensaver108 shell_exec('gsettings set org.gnome.desktop.screensaver idle-activation-enabled false 2>&1');109 self::$gnome3_screensaver_halted_old = true;110 }111 // GNOME 3.x Sleep Dispaly?112 $is_gnome3_sleep = trim(shell_exec('gsettings get org.gnome.settings-daemon.plugins.power sleep-display-ac 2>&1'));113 if($is_gnome3_sleep > 0)114 {115 // Stop the GNOME 3.x Display Sleep116 shell_exec('gsettings set org.gnome.settings-daemon.plugins.power sleep-display-ac 0 2>&1');117 self::$sleep_display_ac = $is_gnome3_sleep;118 }119 }120 if(pts_client::executable_in_path('xfconf-query'))121 {122 $is_xfce_screensaver_enabled = stripos(shell_exec('xfconf-query -c xfce4-session -p /startup/screensaver/enabled 2>&1'), 'false') !== false;123 if($is_xfce_screensaver_enabled)124 {125 shell_exec('xfconf-query -c xfce4-session -n -t bool -p /startup/screensaver/enabled -s false 2>&1');126 self::$xfce_screensaver_halted = true;127 }128 }129 if(getenv('DISPLAY') != false && (self::$xset = pts_client::executable_in_path('xset')))130 {131 shell_exec('xset s off 2>&1');132 }133 else if(getenv('DISPLAY') == false && pts_client::executable_in_path('setterm'))134 {135 shell_exec('setterm -powersave off -blank 0 2>&1');136 }137 if(self::$gnome2_screensaver_halted || self::$gnome3_screensaver_halted || self::$gnome3_screensaver_halted_old || self::$kde_screensaver_halted || self::$xfce_screensaver_halted)138 {139 self::$screensaver_halted = true;140 }141 if(($xdg = pts_client::executable_in_path('xdg-screensaver')) == false)142 {143 self::$xdg_screensaver_available = $xdg;144 }145 if(($xscreensaver = pts_client::executable_in_path('xscreensaver-command')))146 {147 shell_exec($xscreensaver . ' -exit 2>&1');148 }149 }150 public static function __shutdown()151 {152 if(self::$sleep_display_ac)153 {154 // Restore the screen sleep state when on AC power155 if(pts_client::executable_in_path('gsettings'))156 {157 shell_exec('gsettings set org.gnome.settings-daemon.plugins.power sleep-display-ac ' . self::$sleep_display_ac . ' 2>&1');158 }159 else160 {161 shell_exec(self::$gnome_gconftool . ' --type int --set /apps/gnome-power-manager/timeout/sleep_display_ac ' . self::$sleep_display_ac . ' 2>&1');162 }163 }164 if(self::$gnome2_screensaver_halted == true)165 {166 // Restore the GNOME Screensaver167 shell_exec(self::$gnome_gconftool . ' --type bool --set /apps/gnome-screensaver/idle_activation_enabled true 2>&1');168 }169 if(self::$gnome3_screensaver_halted)170 {171 // Restore the GNOME Screensaver172 shell_exec('gsettings set org.gnome.desktop.session idle-delay ' . self::$gnome3_screensaver_halted . ' 2>&1');173 }174 if(self::$gnome3_lockscreen_disabled)175 {176 // Restore the lock screen177 shell_exec('gsettings set org.gnome.desktop.lockdown disable-lock-screen false 2>&1');178 }179 if(self::$gnome3_screensaver_halted_old == true)180 {181 // Restore the GNOME Screensaver182 shell_exec('gsettings set org.gnome.desktop.screensaver idle-activation-enabled true 2>&1');183 }184 if(self::$xfce_screensaver_halted)185 {186 shell_exec('xfconf-query -c xfce4-session -n -t bool -p /startup/screensaver/enabled -s true 2>&1');187 }188 if(self::$kde_screensaver_halted == true)189 {190 // Restore the KDE Screensaver191 shell_exec('qdbus org.freedesktop.ScreenSaver /ScreenSaver org.freedesktop.ScreenSaver.SetActive true 2>&1');192 }193 if(self::$xset)194 {195 shell_exec('xset s default 2>&1');196 }197 if(getenv('DISPLAY') == false && pts_client::executable_in_path('setterm'))198 {199 shell_exec('setterm -reset 2>&1');200 }201 }202 public static function xdg_screensaver_reset()203 {204 if(!self::$screensaver_halted && self::$xdg_screensaver_available)205 {206 shell_exec(self::$xdg_screensaver_available . ' reset 2>&1');207 }208 if(($xscreensaver = pts_client::executable_in_path('xscreensaver-command')))209 {210 shell_exec($xscreensaver . ' -deactivate 2>&1');211 }212 }213 public static function __pre_option_process()214 {215 self::xdg_screensaver_reset();216 }217 public static function __pre_run_process()218 {219 self::xdg_screensaver_reset();220 }221 public static function __pre_test_run()222 {223 self::xdg_screensaver_reset();224 }...

Full Screen

Full Screen

shell_exec

Using AI Code Generation

copy

Full Screen

1$pts = new pts_client();2$pts->shell_exec($cmd, $output, $retval);3$pts = new pts_client();4$pts->exec($cmd, $output, $retval);5$pts = new pts_client();6$pts->system($cmd, $output, $retval);7$pts = new pts_client();8$pts->passthru($cmd, $output, $retval);9$pts = new pts_client();10$pts->popen($cmd, $output, $retval);11$pts = new pts_client();12$pts->proc_open($cmd, $output, $retval);13$pts = new pts_client();14$pts->proc_nice($cmd, $output, $retval);15$pts = new pts_client();16$pts->proc_terminate($cmd, $output, $retval);17$pts = new pts_client();18$pts->proc_terminate($cmd, $output, $retval);19$pts = new pts_client();20$pts->proc_close($cmd, $output, $retval);21$pts = new pts_client();22$pts->proc_get_status($cmd, $output, $retval);23$pts = new pts_client();24$pts->proc_nice($cmd, $output, $retval);25$pts = new pts_client();26$pts->proc_terminate($cmd, $output, $retval);

Full Screen

Full Screen

shell_exec

Using AI Code Generation

copy

Full Screen

1include_once('pts_client.php');2$pts_client = new pts_client();3$pts_client->shell_exec('ls -l');4$output = $pts_client->shell_exec('ls -l');5echo $output;6include_once('pts_client.php');7$pts_client = new pts_client();8$pts_client->shell_exec('ls -l', 'client');9$output = $pts_client->shell_exec('ls -l', 'client');10echo $output;11include_once('pts_client.php');12$pts_client = new pts_client();13$pts_client->shell_exec('ls -l', 'client');14$output = $pts_client->shell_exec('ls -l', 'client');15echo $output;

Full Screen

Full Screen

shell_exec

Using AI Code Generation

copy

Full Screen

1include "pts_client.php";2$pts = new pts_client();3$pts->shell_exec("ls -l");4include "pts_client.php";5$pts = new pts_client();6$output = $pts->shell_exec("ls -l");7echo $output;8include "pts_client.php";9$pts = new pts_client();10$output = $pts->shell_exec("ls -l");11print_r($output);12include "pts_client.php";13$pts = new pts_client();14$output = $pts->shell_exec("ls -l");15print_r($output);

Full Screen

Full Screen

shell_exec

Using AI Code Generation

copy

Full Screen

1include("pts_client.php");2$pts = new pts_client();3$pts->shell_exec("ls -la");4include("pts_client.php");5$pts = new pts_client();6$pts->shell_exec("ls -la");7include("pts_client.php");8$pts = new pts_client();9$pts->shell_exec("ls -la");10include("pts_client.php");11$pts = new pts_client();12$pts->shell_exec("ls -la");13include("pts_client.php");14$pts = new pts_client();15$pts->shell_exec("ls -la");16include("pts_client.php");17$pts = new pts_client();18$pts->shell_exec("ls -la");19include("pts_client.php");20$pts = new pts_client();21$pts->shell_exec("ls -la");22include("pts_client.php");23$pts = new pts_client();

Full Screen

Full Screen

shell_exec

Using AI Code Generation

copy

Full Screen

1require_once 'pts_client.php';2$pts = new pts_client();3$cmd = 'ls -l';4$pts->shell_exec($cmd);5require_once 'pts_client.php';6$pts = new pts_client();7$cmd = 'ls -l';8$pts->shell($cmd);9require_once 'pts_client.php';10$pts = new pts_client();11$cmd = 'ls -l';12$pts->shell($cmd);13require_once 'pts_client.php';14$pts = new pts_client();15$cmd = 'ls -l';16$pts->shell($cmd);17require_once 'pts_client.php';18$pts = new pts_client();19$cmd = 'ls -l';20$pts->shell($cmd);21require_once 'pts_client.php';22$pts = new pts_client();23$cmd = 'ls -l';24$pts->shell($cmd);25require_once 'pts_client.php';26$pts = new pts_client();27$cmd = 'ls -l';28$pts->shell($cmd);29require_once 'pts_client.php';30$pts = new pts_client();31$cmd = 'ls -l';32$pts->shell($cmd);

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Phoronix-test-suite automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Trigger shell_exec code on LambdaTest Cloud Grid

Execute automation tests with shell_exec on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.

Test now for Free

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful