Resolving timeout issues in Shell, Perl, and SSH scripts

Source: Internet
Author: User
Tags sleep ssh

We sometimes execute a script because some of the programs in the script are suspended and timed out, which affects our judgment of the next step. Random we have to set the timeout for functions and processes so that he does not respond after a period of time, return a status.

In the command parameters Ssh-o serveraliveinterval=60 This way can be controlled to 60 seconds.

such as clientaliveinterval=15,clientalivecountmax=3, it will be sent in 15 seconds, 30 seconds sent once, 45 seconds sent once, if three failed to recover the link

But this parameter is not very good, we can add a sleep 100 after the try.

#!/bin/sh    

Timeout ()    
{    
        waitfor=3    
        command=$*    
        $command &    
        commandpid=$!    

        (Sleep $waitfor; kill-9 $commandpid >/dev/null 2>&1) &    

        watchdog=$!    
        sleeppid= $PPID wait    
        $commandpid >/dev/null 2>&1     

        kill $sleeppid >/dev/null 2>&1    
}< C13/>test123 ()    
{    

        ifconfig sleep    
        ifconfig    
#        Curl htpp://www.facebook.com    
}    

Timeout test123

Basic control to about 3s

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.