shutdown of linux box from cron perl script

Discussion in 'Perl Misc' started by Eric Peterson, Jan 6, 2005.

  1. Sorry for the cross-posting, but I'm not sure if this question lands on the
    perl side of things, or the linux side...

    I have a perl script that runs once a minute to check various things. Under
    one condition I want it to reboot the system. The command line equivalent
    of "shutdown -r 10". I can get the script to work perfectly if I manually
    run it from the command-line, "./myshutdownscript.pl". But when it runs
    automatically from cron, the shutdown command seems to be ignored, though
    all other output indicates the perl script is running fine.

    Any suggestions?

    Using: Debian Sarge, kernel 2.6, pentiumIII box, Perl 5.8.4

    Thanks!
    -Eric
     
    Eric Peterson, Jan 6, 2005
    #1
    1. Advertising

  2. "Eric Peterson" <> wrote in
    news:eek:gkDd.10900$:

    > Sorry for the cross-posting, but I'm not sure if this question lands
    > on the perl side of things, or the linux side...


    Well, I tried setting follow ups to comp.os.linux but it seems that group
    is defunct (the most recent message on Google is from September 04).

    > I have a perl script that runs once a minute to check various things.
    > Under one condition I want it to reboot the system. The command line
    > equivalent of "shutdown -r 10". I can get the script to work
    > perfectly if I manually run it from the command-line,
    > "./myshutdownscript.pl". But when it runs automatically from cron,
    > the shutdown command seems to be ignored, though all other output
    > indicates the perl script is running fine.


    A reasonable assumption is that cron jobs run with different priviliges.

    That is an OS issue. Please post in an appropriate forum.

    --
    A. Sinan Unur
    d
    (remove '.invalid' and reverse each component for email address)
     
    A. Sinan Unur, Jan 7, 2005
    #2
    1. Advertising

  3. Eric Peterson

    Keith Keller Guest

    ["Followup-To:" header set to comp.os.linux.misc.]

    On 2005-01-06, Eric Peterson <> wrote:
    > Sorry for the cross-posting, but I'm not sure if this question lands on the
    > perl side of things, or the linux side...
    >
    > I have a perl script that runs once a minute to check various things. Under
    > one condition I want it to reboot the system. The command line equivalent
    > of "shutdown -r 10". I can get the script to work perfectly if I manually
    > run it from the command-line, "./myshutdownscript.pl". But when it runs
    > automatically from cron, the shutdown command seems to be ignored, though
    > all other output indicates the perl script is running fine.


    I'd try posting to comp.os.linux.misc instead, and also would post a
    short script which replicates the problem there. (Sinan's correct, in
    that if the script runs from the command line, it's probably not a Perl
    problem.)

    --keith

    --
    -francisco.ca.us
    (try just my userid to email me)
    AOLSFAQ=http://wombat.san-francisco.ca.us/cgi-bin/fom
     
    Keith Keller, Jan 7, 2005
    #3
  4. "A. Sinan Unur" <> wrote in message
    news:Xns95D6C4031245Fasu1cornelledu@132.236.56.8...
    > "Eric Peterson" <> wrote in
    > news:eek:gkDd.10900$:
    >
    > > Sorry for the cross-posting, but I'm not sure if this question lands
    > > on the perl side of things, or the linux side...

    >
    > Well, I tried setting follow ups to comp.os.linux but it seems that group
    > is defunct (the most recent message on Google is from September 04).


    Odd. I see messages there from earlier this week. I'm getting them from
    the news server at sbcglobal.net

    >
    > > I have a perl script that runs once a minute to check various things.
    > > Under one condition I want it to reboot the system. The command line
    > > equivalent of "shutdown -r 10". I can get the script to work
    > > perfectly if I manually run it from the command-line,
    > > "./myshutdownscript.pl". But when it runs automatically from cron,
    > > the shutdown command seems to be ignored, though all other output
    > > indicates the perl script is running fine.

    >
    > A reasonable assumption is that cron jobs run with different priviliges.
    >
    > That is an OS issue. Please post in an appropriate forum.
    >
    > --
    > A. Sinan Unur
    > d
    > (remove '.invalid' and reverse each component for email address)
    >
     
    Eric Peterson, Jan 7, 2005
    #4
  5. Perfect!
    Thanks!

    "Abigail" <> wrote in message
    news:...
    > Eric Peterson () wrote on MMMMCXLVI
    > September MCMXCIII in

    <URL:news:eek:gkDd.10900$>:
    > '' Sorry for the cross-posting, but I'm not sure if this question lands

    on the
    > '' perl side of things, or the linux side...
    > ''
    > '' I have a perl script that runs once a minute to check various things.

    Under
    > '' one condition I want it to reboot the system. The command line

    equivalent
    > '' of "shutdown -r 10". I can get the script to work perfectly if I

    manually
    > '' run it from the command-line, "./myshutdownscript.pl". But when it

    runs
    > '' automatically from cron, the shutdown command seems to be ignored,

    though
    > '' all other output indicates the perl script is running fine.
    > ''
    > '' Any suggestions?
    >
    >
    > Your PATH is probably different when running from cron. Try using
    > the full path: /sbin/shutdown -r
    >
    >
    > Abigail
    > --
    > $=-=4*++$|;{print$"x--$==>"\@\x7Fy~*kde~box*Zoxf*Bkiaox \r"
    > ^
    > $/x24if!select$,,$,,$,,join+q=.==>$^W=>$|;$=&&redo}sleep$|;
     
    Eric Peterson, Jan 7, 2005
    #5
  6. Eric Peterson

    Joe Smith Guest

    Eric Peterson wrote:
    > runs automatically from cron, the shutdown command seems to be ignored


    The perl answer to this problem is to add a line to your script:

    $ENV{PATH} .= ':/sbin:/usr/sbin' unless $ENV{PATH} =~ /sbin/;

    -Joe
     
    Joe Smith, Jan 7, 2005
    #6
  7. Eric Peterson

    Steven_Smith Guest

    Joe Smith wrote:
    > Eric Peterson wrote:
    >
    >> runs automatically from cron, the shutdown command seems to be ignored

    >
    >
    > The perl answer to this problem is to add a line to your script:
    >
    > $ENV{PATH} .= ':/sbin:/usr/sbin' unless $ENV{PATH} =~ /sbin/;
    >
    > -Joe

    Or in general to use the absolute path to the executable if
    there can be problems. Actually, for scripts used by many
    people I've been bitten by not using the absolute path
    several times, so generally I use it. The problem of course
    is that then you can become platform specific...

    Steve S.
     
    Steven_Smith, Jan 10, 2005
    #7
    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. Zouplaz
    Replies:
    3
    Views:
    139
    William Crawford
    Sep 14, 2006
  2. Edward

    running perl script in cron

    Edward, May 13, 2004, in forum: Perl Misc
    Replies:
    1
    Views:
    168
    Walter Roberson
    May 13, 2004
  3. Y.G.

    setting linux display for Cron

    Y.G., Jun 12, 2006, in forum: Perl Misc
    Replies:
    1
    Views:
    88
  4. Micha
    Replies:
    2
    Views:
    321
    Henry Law
    Mar 23, 2008
  5. Krishna Chaitanya
    Replies:
    1
    Views:
    144
    Krishna Chaitanya
    Feb 27, 2009
Loading...

Share This Page