Register
It is currently Thu Oct 23, 2014 11:10 am

Handling fgets errors from subprocesses


All times are UTC - 6 hours


Post new topic Reply to topic  [ 3 posts ] 
Author Message
 PostPosted: Fri Apr 02, 2010 3:15 pm   

Joined: Tue Mar 16, 2010 7:16 pm
Posts: 3
I'm not sure if my terminology is correct, but here goes: sometimes when running whois I'll get an error that says "fgets: Connection reset by peer." How can I suppress that message and instead run the command again?

I've been trying something like this:

Code:
while [ 1 ]
do
    result=$(whois asdf.com 2>&1)
    if [[ $? == 0 ]]
    then
        break
    fi
    sleep 5
done

echo $result

but I guess the fgets message isn't a numerical error (no exit code?), because it still shows up?


Top
 Profile  
 PostPosted: Fri Apr 02, 2010 6:01 pm   

Joined: Mon Mar 02, 2009 3:03 am
Posts: 550
I can't reproduce the error :(

is that all that contains $result : "fgets: Connection reset by peer." ?

you could try like this:
Code:
while [ -z "$result" ]
do result=$( whois asdf.com 2>/dev/null)
done

if the error still appears, try something like:
Code:
while [[ -z $result ]] || [[ $result =~ "fgets: Connection reset by peer" ]]
do result=$(whois asdf.com 2>/dev/null)
done


Top
 Profile  
 PostPosted: Sat Apr 03, 2010 9:47 pm   

Joined: Tue Mar 16, 2010 7:16 pm
Posts: 3
Well, it only happens intermittently. My main problem is that when it does happen it isn't stored in $result but rather printed to the terminal. I forgot to mention that this particular case is from another script that invokes various subprocesses with &.

By the way, is

Code:
[[ $result =~ "fgets: Connection reset by peer" ]]

notation for a membership test?

I will try your suggestions and report back. Thanks.


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP