`
Ashton
  • 浏览: 32468 次
  • 性别: Icon_minigender_1
  • 来自: 上海
最近访客 更多访客>>
社区版块
存档分类
最新评论

Time out script in perl

阅读更多
I have a script used to test the sftp connection which runs too long, so I want to time it out after a given number of seconds.After a google search and perl doc reading, I find the ALARM function can work well.

#!/usr/bin/perl
eval {
   local %SIG;//in some ENV %SIG should be global variable
   $SIG{ALRM}= sub{ die "timeout reached, after 20 seconds!\n"; };
   alarm 20;
   print "sleeping for 60 seconds\n";
   sleep 60; # This is where to put your code, between the alarms
   alarm 0;
};

alarm 0;

if($@) { print "Error: $@\n"; }

exit(0);

reference:http://perl.coding-school.com/perl-timeout/
分享到:
评论

相关推荐

    Practical Mod Perl

    Handling Server Timeout Cases and Working with $SIG{ALRM} Section 6.11. Generating Correct HTTP Headers <br> Section 6.12. Method Handlers: The Browse and See, Browse and View Example ...

    Web.Client.Programming.with.Perl.Automating.Tasks.on.the.Web.pdf

    out http://www.perl.com for the latest book critiques. Is This Book for You? Some of you already know why you picked up this book. But others may just have a nagging feeling that it's something ...

    UE(官方下载)

    Using Perl-Style regexes to identify functions in your syntax-highlighted files and populate the function list Autocorrect keywords in UltraEdit/UEStudio How to enable and disable autocorrect keywords...

    squish test

    5. **Snooze/Timeout Features:** These features help handle unpredictable pop-ups or wait times for Java components. Additional functionality tested includes: 1. **Multiple Java Client Interaction:**...

    2009 达内Unix学习笔记

    ls -t (time)按修改时间排序,显示目录和文件。 ls -lt 是“-l”和“-t”的组合,按时间顺序显示列表。 ls -F 显示文件类型,目录“/ ”结尾;可执行文件“*”结尾;文本文件(none),没有结尾。 ls -R 递归显示...

    Windows下的“批处理

    rslt = WS.Popup(Message, timeout, title, buttons); if (rslt == 2) { WScript.Quit; } } showit(); ``` 2. **网络信息显示**:此示例演示了如何使用WSH获取并显示当前用户的网络信息,包括用户名、域和...

    外文翻译 stus MVC

    By the time the event gets here, the input form data (or HTML form data) has already been translated out of the request stream and into an ActionForm class. Struts, an MVC 2 implementation Struts...

    Bochs - The cross platform IA-32 (x86) emulator

    Changes in 2.4.6 (February 22, 2011): Brief summary : - Support more host OS to run on: - Include win64 native binary in the ... [2914433] makesym.perl misses symbols by John R. Jackson [2908481] USB ...

    unix power tools 3ed.pdf

    **2.3 充分利用终端、xterm 和 X Windows (Chapter 5: Getting the Most out of Terminals, xterm, and X Windows)** - **终端模拟器**: xterm 的高级功能介绍。 - **X Window系统**: 基础概念和管理技巧。 - **多...

    freemarker总结

    <#assign mail="jsmith@other.com" in my> ${my.mail} l 输出结果: jsmith@acme.com jsmith@other.com l 数据模型中的变量任何地方都可见,也包括不同的名字空间,下面是修改的库: <p>Copyright ...

    测试培训教材

    The VAPI-XP testing tool enables you to create new testing scripts using Microsoft VBScript, Microsoft JavaScript (JScript version), PerlScript, and PythonScript, and integrate these scripts into your...

    Linux shell下30个有趣的命令和提示(推荐)

    22. **定时运行命令**:`timeout` 命令可以限制命令执行时间,如`timeout 10s ./script.sh`。 23. **合并两个已排序文件的行**:`comm` 命令比较两个已排序文件,`comm file1 file2` 显示不同和共有的行。 24. **...

Global site tag (gtag.js) - Google Analytics