glob - Perl: How capture the outputs of Expect.pm? -


I wrote a piece of Perl code to create an SSH key using expect.pm. Can make code key as expected but I do not know how to capture fingerprint from the output.

  Expect to use; My $ passwd = "abcdefg"; My $ keyfile = './mykey'; My $ cmd = qq / ssh-keygen -t RSA-B2048-C "My comments" -f $ file /; Print "\ nCMD: $ cmd \ n \ n"; My @ output; My $ session = hope-gt; Spawn ($ cmd) or die "Error calling external program: $! \ N"; As long as ($ session-> expect (5, "Enter passphrase (not left for a passphrase):")) {}; Print $ session "$ passwd \ r"; As long as (@output = $ session- & gt; hopefully (5, "enter the same passphrase again:")) {}; # Capture the output print $ session "$ passwd \ r"; $ Session- & gt; Soft_close (); My $ i = 1; Do my $ E (@Edit) before (if ($ E) {print "$$$$" = $ i, type \ $ e: # "ref ($ E)" #, the value \ $ e: # $ E # \ n ";} Else {print" $ i, NULL element! \ N ";} $ I ++;} Exit;   

Below is the output:

 % ./test.pl CMD: SSH-Keyjan-R RSA-B2048-C "My comments" - F. / Maki generating public / private RSA key pair Enter passphrase (for any passphrase Empty): Enter the same passphrase: your identity saved in / mykey Your public key is saved in ./Mykey.pub. ** The key fingerprint is: df: aa: 35: 19: 28: 06: 0e: 97: ec: 6d: 83: 26: B 9: 01: 4 F: 50 ** My comments are the random image of the key: + - - [RSA 2048] ---- + | ..E | | | | | | | O = | | + * + | | = = * S. | | = OO + | |. =. | | O.O. | ... | + + ----------------- $ i = 1, $ e's Type: ##, Value of $ e: # 1 # 2, zero element! $ I = 3, type of $ e: ##, $ e value: # Enter the same passphrase: # $ i = 4, $ E Type: ##, Value of $ e: # 5, zero element! $ I = 6, $ e type: # Hope #, value $ E: # hope = globe (0x1e74b38) #   

I think the information is in the globe? But how to parse the globe? Thanks for the help.

This should do the following or at least you should be able to modify it in the suite you need I'm waiting for the "my comment" string which is printed after fingerprint and then read fingerprint using the * exp_before * method.

  Use strict; Hope to use; My $ passwd = "abcdefg"; My $ keyfile = './mykey'; My $ cmd = qq / ssh-keygen -t RSA-B2048-C "My comments" -f $ keyFile /; My $ session = hope-gt; Spawn ($ cmd) or die "Error calling external program: $!"; My $ output; $ Session- & gt; Expect (10, [qr / passphrase / i, sub {my $ self = shift} $ self-> send ("$ passwd \ n"); exp_continue;}], [qr / my comments / sub, (sub) My $ self = shift; $ output = $ self-> exp_before; exp_continue;}],); print output $; $ session-> soft_close;    

Comments

Popular posts from this blog

excel vba - How to delete Solver(SOLVER.XLAM) code -

github - Teamcity & Git - PR merge builds - anyway to get HEAD commit hash? -

ios - Replace text in UITextView run slowly -