Forum Discussion

Craig_T_232390's avatar
Craig_T_232390
Icon for Nimbostratus rankNimbostratus
Nov 03, 2015

Using Plink to run multiple commands

I have a fairly complex script which is trying to consolidate data into a text file using the following command:

 

c:\tools\plink.exe -batch ltmops@%IP% -pw ******* -m a.txt >tempA.txt

 

a portion of the a.txt file is as follows:

 

show ltm virtual a* show ltm virtual b* show ltm virtual c* show ltm virtual d* ...

 

Obviously, I'm trying to pull all of the VIP names. How can I suppress the prompt for "Display all 1014 items? (y/n) " ? I was trying to use "show ltm virtual *" but was being prompted for the same so I broke them out into individual commands, but this resulted in an undesirable high number of authentication requests in the logs. So now, I'm trying to implement the feature of using a file containing multiple commands that may be run under a single session. Thanks in advance for any guidance.

 

5 Replies

  • When run from bash you can suppress the prompt with -q and run multiple commands with -c. Shown below with and without -q. Sounds like you just need to connect to bash prompt and run tmsh -q "show ltm virtual" and pull out what you need.

    cheers

      tmsh -c "show sys clock; show sys connection"
    -----------------------------
    Sys::Clock
    -----------------------------
    Wed Nov 04 09:41:18 NZDT 2015
    
    
    Really display all connections? (y/n)
    
    
      tmsh -q -c "show sys clock; show sys connection"
    -----------------------------
    Sys::Clock
    -----------------------------
    Wed Nov 04 09:41:33 NZDT 2015
    
    Sys::Connections
    10.10.10.19:49332    10.11.11.11:8080    10.12.12.12:49332   10.13.13.13:8080    tcp   307   (slot/tmm: 1/1)  none
    
  • Thanks so much for the quick answer. Having some trouble though, and it's probably due to lack of experience with F5. This is the prompt when I log directly in using Plink:

     

    ltmops@***********(Active)(tmos)

     

    When I try to use "tmsh -q..." I get an error msg. Is it rights related, by chance?

     

    Syntax Error: unexpected argument "tmsh"

     

    Trying just "-q show..." gives a similar unexpected argument "-q" error.

     

  • that's because you are connecting to the TMSH shell and not bash. The easiest solution would be to allow the ltmops user to connect to advanced shell (bash) in System-Users but this assumes local auth, if you are using remote auth it may be a bit more difficult.

     

    cheers

     

  • Thanks, but I believe it would be like twisting teeth to get any changes to the account implemented. So, if I'm getting this correctly, there is no way to suppress the prompt with this type of access?

     

    • LoyalSoldier's avatar
      LoyalSoldier
      Icon for Altostratus rankAltostratus

      If you only have access to tmsh you can run bash commands from that as well, assuming the account is allowed bash access. To do so:

      run /util bash -c 'tmsh -q -c "show sys clock; show sys connection"'

      Note this ends with a double, then single, quote.