trying to execute 'at now + 2 minutes...

Discussion in 'Perl Misc' started by mmccaws2, Mar 17, 2008.

  1. mmccaws2

    mmccaws2 Guest

    Hi

    On unix I'll run a command at the command line like

    > at now + 2 minutes
    > ./trial.pl &
    > Ctrl d


    how do I do this from within a script?

    Thanks
    Mike
     
    mmccaws2, Mar 17, 2008
    #1
    1. Advertising

  2. >>>>> "mmccaws2" == mmccaws2 <> writes:

    mmccaws2> Hi
    mmccaws2> On unix I'll run a command at the command line like

    >> at now + 2 minutes
    >> ./trial.pl &
    >> Ctrl d


    mmccaws2> how do I do this from within a script?

    open AT, "|at now + 2 minutes" or die $!;
    print AT "./trial.pl"; # not sure why you backgrounded that.
    close AT;

    Or, if you don't really need "at", and you just want to execute something
    in two minutes, you can simply fork:

    defined(my $kid = fork) or die "Cannot fork: $!";
    unless ($kid) { # child does...
    sleep 2 * 60; # two minutes, measured in seconds
    exec "./trial.pl"; # for example, or just do it in line
    exit 0;
    }

    $kid's pid will show up on a waitpid() call later, so you need to wait for it
    eventually or exit soon, or you can double fork and wait if you don't want the
    zombie.

    print "Just another Perl hacker,"; # the original, #0 :)

    --
    Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
    <> <URL:http://www.stonehenge.com/merlyn/>
    Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
    See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
     
    Randal L. Schwartz, Mar 17, 2008
    #2
    1. Advertising

  3. mmccaws2

    Guest

    On 17 Mar, 08:10, mmccaws2 <> wrote:
    >
    > On unix I'll run a command at the command line like
    >
    > > at now + 2 minutes
    > > ./trial.pl &
    > > Ctrl d

    >
    > how do I do this from within a script?


    Perhaps, sleep($seconds) first would do it for you.

    /sandy
    http://myperlquiz.com/
     
    , Mar 17, 2008
    #3
  4. mmccaws2

    Guest

    mmccaws2 <> wrote:
    > Hi
    >
    > On unix I'll run a command at the command line like
    >
    > > at now + 2 minutes
    > > ./trial.pl &
    > > Ctrl d

    >
    > how do I do this from within a script?


    open my $at, "| at now + 2 minutes" or die $!;
    print $at './trial.pl&';
    close $at or die $!;

    Or you could do it strictly in Perl using fork and sleep and exec.

    Xho

    --
    -------------------- http://NewsReader.Com/ --------------------
    The costs of publication of this article were defrayed in part by the
    payment of page charges. This article must therefore be hereby marked
    advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
    this fact.
     
    , Mar 17, 2008
    #4
  5. mmccaws2

    mmccaws2 Guest

    On Mar 17, 8:51 am, wrote:
    > mmccaws2 <> wrote:
    > > Hi

    >
    > > On unix I'll run a command at the command line like

    >
    > > > at now + 2 minutes
    > > > ./trial.pl &
    > > > Ctrl d

    >
    > > how do I do this from within a script?

    >
    > open my $at, "| at now + 2 minutes" or die $!;
    > print $at './trial.pl&';
    > close $at or die $!;
    >
    > Or you could do it strictly in Perl using fork and sleep and exec.
    >
    > Xho
    >
    > --
    > --------------------http://NewsReader.Com/--------------------
    > The costs of publication of this article were defrayed in part by the
    > payment of page charges. This article must therefore be hereby marked
    > advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
    > this fact.


    Thanks everyone

    it works great.

    Mike
     
    mmccaws2, Mar 17, 2008
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    1
    Views:
    645
  2. $Need C Programmer$

    Email NOW $$ HIGH $$ C Programmer WANTED NOW!!

    $Need C Programmer$, Aug 2, 2006, in forum: C Programming
    Replies:
    2
    Views:
    722
    Christopher Benson-Manica
    Aug 2, 2006
  3. OldButStillLearning

    Now You See It Now You Don't

    OldButStillLearning, Dec 11, 2007, in forum: ASP .Net
    Replies:
    6
    Views:
    304
    Juan T. Llibre
    Dec 12, 2007
  4. Savas Ates
    Replies:
    1
    Views:
    295
    Patrice
    Aug 17, 2004
  5. Simon Gare

    Falsh text if time NOW() IS < 20 MINUTES AWAY

    Simon Gare, Oct 22, 2005, in forum: ASP General
    Replies:
    1
    Views:
    115
Loading...

Share This Page