print results after each command
Results 1 to 4 of 4

Thread: print results after each command

  1. #1
    Junior Member
    Join Date
    Nov 2016
    Posts
    3

    print results after each command

    I am using this to send a command to multiple Linux computers via ssh. It prints the results after it has processed all computers. How can I see the results after each computer is finished, so I don't have to wait for all computers to finish?
    HTML Code:
    <form action="commands.php" method="post" target="main">
        <input type="checkbox" name="clients[]" value="192.168.1.11">Client001<br>
        <input type="checkbox" name="clients[]" value="192.168.1.12">Client002<br>
        <br/>
         <select name="commands">
    <option value="">Select Command</option>
    <option value="uptime | sed 's/.*up \([^,]*\), .*/\1/'">Uptime</option>
    <option value="printf $(free | grep -e-/+ | awk '{print $3/($3+$4) * 100.0 ''}' | cut -d '.' -f1)%%">Memory Usage</option>
         </select>
      <br>
      <br/>
      <input type="submit" value="Submit" />
      </form>
    PHP Code:
    <?php
      
    include('Net/SSH2.php');
      
    $user "user";
      
    $pass "pass";
      
    $ip $_POST['clients'];
      
    $ssh = new Net_SSH2($ip);
      
    $cmds $_POST['commands'];
      
      if(!empty(
    $_POST['clients'])) {
          foreach(
    $_POST['clients'] as $ip) {
              
    $ssh = new Net_SSH2($ip);
              if (!
    $ssh->login($user$pass)) {exit('Login Failed');}
              echo 
    " " $ssh->exec($cmds) . "<br>";
          }
      }
     
    ?>

  2. #2
    Pedantic Curmudgeon Weedpacket's Avatar
    Join Date
    Aug 2002
    Location
    General Contact Unit "Coping Mechanism"
    Posts
    22,342
    Since you are telling the script to generate output after each command, there's probably an issue with buffering going on: putting flush after echoing the response may help with that.



    A complete rearchitecting might use more JavaScript control on the client side and server push on the server side, or maybe have the client generate multiple asynchronous requests (one for each selected IP) and display the responses as they come back.
    Last edited by Weedpacket; 11-19-2016 at 08:40 PM.
    THERE IS AS YET INSUFFICIENT DATA FOR A MEANINGFUL ANSWER
    FAQs! FAQs! FAQs! Most forums have them!
    Search - Debugging 101 - Collected Solutions - General Guidelines - Getting help at all

  3. #3
    Junior Member
    Join Date
    Nov 2016
    Posts
    3
    This is very strange. If I am running a simple script that just echoes something, it's working as expected. For example:
    HTML Code:
    <option value="/home/user/test.sh">Test echo</option>
    /home/user/test.sh
    PHP Code:
    echo this is test1
    echo this is test2
    echo this is test3 
    This shows the 3 echoes just fine.

    But when I start testing a bit more complicated scripts, it doesn't show anything. For example:
    PHP Code:
    #!/bin/bash

    # import variables
    source "${BASH_SOURCE%/*}/variables"

    if [ -n "$(ls -A $localaudiomedia)" ]
    then
        if [[ $omxplayer_local_audio_status == *"#"* ]]
        then
          echo "remounting rw"
          mount -o remount,rw /
          echo "disabling services"
          sed -i '/^#/!s/\(.*\)/#\1/g' $display
          echo "enabling local audio"
          sed -i '/omxplayer-local-audio/s/^#//g' $display
          echo "restarting"
          reboot
        else
          echo "local audio is already enabled";
        fi
    else
      echo "local audio folder is empty"
    fi 
    This echoes nothing.

  4. #4
    Junior Member
    Join Date
    Nov 2016
    Posts
    3
    by the way flush worked!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •