bigbot has asked for the wisdom of the Perl Monks concerning the following question:
I have used Perl threading in quite a few scripts, but I'm banging my head against a wall with this issue. What happens is, the output gets mangled up and breaks the Bash term (which I then need to reset in many cases). The lock is indeed working (as far as keeping multiple threads from printing out at once). I have narrowed down the problem to the ssh/tcpdump line. Without this line, I can output anything and there are no issues. With this line, I can literally print anything after the lock and the output will get mangled up 50% of the time. Specifically, the output appears to indent further every line. If I print entire packets every packet line is further indented. After the script is done running the Bash term is all screwed up, sometimes newlines don't process, and sometimes the text is invisible.
Example Output:use threads; use threads::shared; my $lock:shared; foreach my $server (@servers) { chomp $server; push (@threads, threads->create (\&dumpServer, $server)); } foreach (@threads) { $_->join(); } sub dumpServer { my $server = shift; my $net = `ssh -tt $server '/usr/local/bin/tcpdump -c10 -nntttt port + 80 2>/dev/null' 2>/dev/null`; ## This is the line that causes the i +ssue lock($lock); print "TEST - $server\n"; ## Want to print $net output here, but pr +inting even a simple string gives me the issue }
Thanks for your time.TEST - Server1 TEST - Server2 TEST - Server3 TEST - Server4 Bash Prompt (now need to reset term)
|
|---|