FAQ
Hello all,
I've created a perl script that creates a vpn connection, I call the
vpn connection with the perl system function eg.

system("vpnclient connect company_lan") ;

With the system function, the perl script will not continue until I
stop the vpn connection. When I stop the vpn connection then the perl
script continues which does a whole bunch of post vpn clean up.

My question is; how do I keep my perl script from dying if my shell
window accidentally closes while my perl script is paused at the
system function portion of my script? If for some reason my shell
window closes while it's running my vpn connection, then my perl
script dies and will not have a chance to do any post vpn clean up
stuff that's it's programmed to do.

Thanks all!

Search Discussions

  • Shlomi Fish at Feb 10, 2010 at 2:54 pm

    On Tuesday 09 Feb 2010 20:40:02 Ariel Casas wrote:
    Hello all,
    I've created a perl script that creates a vpn connection, I call the
    vpn connection with the perl system function eg.

    system("vpnclient connect company_lan") ;

    With the system function, the perl script will not continue until I
    stop the vpn connection. When I stop the vpn connection then the perl
    script continues which does a whole bunch of post vpn clean up.

    My question is; how do I keep my perl script from dying if my shell
    window accidentally closes while my perl script is paused at the
    system function portion of my script? If for some reason my shell
    window closes while it's running my vpn connection, then my perl
    script dies and will not have a chance to do any post vpn clean up
    stuff that's it's programmed to do.

    Thanks all!
    The easiest way would be to use GNU screen or something similar:

    * http://www.gnu.org/software/screen/

    * http://tmux.sourceforge.net/

    If you want to do it inside Perl you can look at
    http://perldoc.perl.org/functions/fork.html ,
    http://perldoc.perl.org/perlipc.html and multi-tasking.

    Regards,

    Shlomi Fish

    --
    -----------------------------------------------------------------
    Shlomi Fish http://www.shlomifish.org/
    "Humanity" - Parody of Modern Life - http://shlom.in/humanity

    Deletionists delete Wikipedia articles that they consider lame.
    Chuck Norris deletes deletionists whom he considers lame.

    Please reply to list if it's a mailing list post - http://shlom.in/reply .
  • Alan Haggai Alavi at Feb 10, 2010 at 3:07 pm
    Hello Ariel,

    You could use either GNU Screen (http://www.gnu.org/software/screen/)
    or `nohup` command to run your script.

    Regards,
    Alan Haggai Alavi.
    --
    The difference makes the difference.
  • Jeff Peng at Feb 10, 2010 at 10:22 pm

    On Wed, Feb 10, 2010 at 2:40 AM, Ariel Casas wrote:
    My question is; how do I keep my perl script from dying if my shell
    window accidentally closes while my perl script is paused at the
    system function portion of my script?
    Hi,

    Make a daemon process for running in the script, or use nohup:

    nohup perl a.pl

    HTH.

    Jeff.
  • Shawn H Corey at Feb 10, 2010 at 10:40 pm

    Jeff Peng wrote:
    On Wed, Feb 10, 2010 at 2:40 AM, Ariel Casas wrote:

    My question is; how do I keep my perl script from dying if my shell
    window accidentally closes while my perl script is paused at the
    system function portion of my script?
    Hi,

    Make a daemon process for running in the script, or use nohup:

    nohup perl a.pl

    HTH.

    Jeff.
    You can do the same thing inside Perl with %SIG:

    $SIG{HUP} = 'IGNORE';

    See `perldoc perlvar` and search for /\%SIG/


    --
    Just my 0.00000002 million dollars worth,
    Shawn

    Programming is as much about organization and communication
    as it is about coding.

    I like Perl; it's the only language where you can bless your
    thingy.
  • C.DeRykus at Feb 11, 2010 at 2:37 pm

    On Feb 10, 2:39 pm, shawnhco...@gmail.com (Shawn H Corey) wrote:
    Jeff Peng wrote:
    On Wed, Feb 10, 2010 at 2:40 AM, Ariel Casas wrote:

    My question is; how do I keep my perl script from dying if my shell
    window accidentally closes while my perl script is paused at the
    system function portion of my script?
    Make a daemon process for running in the script, or use nohup:
    nohup perl a.pl

    You can do the same thing inside Perl with %SIG:

    $SIG{HUP} = 'IGNORE';
    I'd think 'nohup perl a.pl' would be a smidge safer though since
    the script is vulnerabe during startup/loading before the 'IGNORE'
    is seen. Of course, you could mitigate risk by setting the 'IGNORE'
    inside a BEGIN{}.

    --
    Charles DeRykus
  • Shawn H Corey at Feb 13, 2010 at 8:30 pm

    C.DeRykus wrote:
    I'd think 'nohup perl a.pl' would be a smidge safer though since
    the script is vulnerabe during startup/loading before the 'IGNORE'
    is seen. Of course, you could mitigate risk by setting the 'IGNORE'
    inside a BEGIN{}.
    But nohup has the same "vulnerability" since it does the same thing. :)


    --
    Just my 0.00000002 million dollars worth,
    Shawn

    Programming is as much about organization and communication
    as it is about coding.

    I like Perl; it's the only language where you can bless your
    thingy.
  • Ariel Casas at Feb 11, 2010 at 10:38 pm
    All I needed to do is add:

    $SIG{HUP} = 'IGNORE';

    I tested it by killing my terminal window while an active vpn
    connection and confirmed that my perl script runs it's post vpn
    cleanup stuff even after the terminal window closed.

    Thanks Shawn!


    Ariel C.

    On Feb 10, 2:39 pm, shawnhco...@gmail.com (Shawn H Corey) wrote:
    Jeff Peng wrote:
    On Wed, Feb 10, 2010 at 2:40 AM, Ariel Casas wrote:

    My question is; how do I keep my perl script from dying if my shell
    window accidentally closes while my perl script is paused at the
    system function portion of my script?
    Hi,
    Make a daemon process for running in the script, or use nohup:
    nohup perl a.pl
    HTH.
    Jeff.
    You can do the same thing inside Perl with %SIG:

    $SIG{HUP} = 'IGNORE';

    See `perldoc perlvar` and search for /\%SIG/

    --
    Just my 0.00000002 million dollars worth,
    Shawn

    Programming is as much about organization and communication
    as it is about coding.

    I like Perl; it's the only language where you can bless your
    thingy.
  • Jeff Peng at Feb 14, 2010 at 3:55 am

    On Thu, Feb 11, 2010 at 6:39 AM, Shawn H Corey wrote:
    You can do the same thing inside Perl with %SIG:

    $SIG{HUP} = 'IGNORE';
    Also "nohup" redirect all stdout and stderr to a file "nohup.out".
    So you have also to reopen STDOUT and STDERR to a file handle if doing
    it in the script.

    btw, Cheers Chinese New Year for all Chinese Perl users.

    --
    Jeff Peng
    Email: jeffpeng@netzero.net
    Skype: compuperson

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupbeginners @
categoriesperl
postedFeb 9, '10 at 6:40p
activeFeb 14, '10 at 3:55a
posts9
users6
websiteperl.org

People

Translate

site design / logo © 2021 Grokbase