1

Have you found solution any on how to ssh using expect with threads?

sub thDoWork {

    #variables

    my $thread_number = $_[0];
    my $PassStoreQueue = $_[1];

    my $Thread_Die = '';
    my $My_Print_Bucket = '';

    while ($Thread_Die ne 'KILL_THREAD') {

        my $temp_Store_Number_Working_On = $PassStoreQueue->dequeue();

        my $name;
        my $ip;
        my $Device_Exist;
        my $TempDeviceName;
        my $DNS_Results;

        # I need to ssh inside many threads, I can ssh from the main
        # thread just fine but not a sub thread. 

        $ssh = Expect->spawn("ssh -l $username1 $temp_ssh_device " .
                             "-o UserKnownHostsFile=/dev/null " .
                             "-o StrictHostKeyChecking=no")
            or return "Couldn't spawn ssh session";

        # this is unable to login to device.
}

I have read a thread that expect is not working correctly in threads, is that still true?

pynexj
  • 15,152
  • 5
  • 24
  • 45
  • Create an `expect` object beforehand and pass it to a thread. See [this post](https://stackoverflow.com/a/43879540/4653379). This may be a duplicate. – zdim Jul 12 '17 at 05:26
  • Possible duplicate of [ssh "permissions are too open" error](https://stackoverflow.com/questions/9270734/ssh-permissions-are-too-open-error) – Andy Developer Jul 12 '17 at 07:02

0 Answers0