Page 1 of 3 123 LastLast
Results 1 to 10 of 23

Thread: perl script intended to reactivate computer so that cron jobs run

  1. #1

    Default perl script intended to reactivate computer so that cron jobs run

    I have crontab jobs that take place during the night, but would rather not leave my machine (a Dell Precision T1500, running openSUSE 11.2 64-bit) constantly active. The need is to bump the machine into activity just before a scheduled crontab job.

    The earlier history of my enquiry can be found (if needbe) under the 64-bit forum, under title: "scripts in crontab not executed if computer (Dell desktop, openSUSE 11.2) inactive." In short, with others' help I have been directed to a perl script (originating on a Ubuntu forum) that becomes active when the machine goes inactive (I think that's the intent -- makes sense anyway) and executes an rtcwake command designed to spur the computer into action at the designated time(s). The script, which is given below, is not working -- or to be more specific, when I added this script to the Gnome session manager then rebooted, I got an empty screen right after login. I did CTRL ALT F1 and I received the following message: "prepare_preload warning: Too many forks, PIDs got reused, we're confused at 41315 splash 4309 fork 4310".

    I am not familiar with perl, and I'm stuck at the line containing the test if(m/^\s+boolean true/){ ... what does this mean? Any suggestion as to where I might be going wrong? Thanks, jdw

    Code:
    #!/usr/bin/perl
    my $cmd = "dbus-monitor --session \"type='signal',interface='org.gnome.ScreenSaver', member='SessionIdleChanged'\"";
    while (<IN>) {
    if (m/^\s+boolean true/) {
    system("/usr/sbin/rtcwake -m mem -t $(date --date=01:00:00 +%s)");
    system("/usr/sbin/rtcwake -m mem -t $(date --date=05:00:00 +%s)");
    system("/usr/sbin/rtcwake -m mem -t $(date --date=10:00:00 +%s)");
    system("/usr/sbin/rtcwake -m mem -t $(date --date=15:00:00 +%s)");
    } elsif (m/^\s+boolean false/) {
    system("echo Issued a wake-up reminder to ensure scheduled crontab jobs run");
    }
    }

  2. #2
    Join Date
    Jun 2008
    Location
    Podunk
    Posts
    32,323
    Blog Entries
    15

    Default Re: perl script intended to reactivate computer so that cron jobs run

    Hi
    Have a read of this article;
    Wake your Linux up from sleep for a cron job
    Cheers Malcolm °¿° SUSE Knowledge Partner (Linux Counter #276890)
    SUSE SLE, openSUSE Leap/Tumbleweed (x86_64) | GNOME DE
    If you find this post helpful and are logged into the web interface,
    please show your appreciation and click on the star below... Thanks!

  3. #3

    Default Re: perl script intended to reactivate computer so that cron jobsrun

    j1d1w1 wrote:
    > I am not familiar with perl, and I'm stuck at the line containing the
    > test if(m/^\s+boolean true/){ ... what does this mean?


    It means that the code following the if (system etc) will be executed if
    and only if a line read from the filehandle IN starts with one or more
    whitespace characters followed by 'boolean true'.

    You haven't shown where IN is opened and you haven't shown anywhere that
    $cmd is used. If what you've shown us is a complete program, it does
    nothing.

  4. #4

    Default Re: perl script intended to reactivate computer so that cron jobsrun

    Thanks Malcolm and djh-novell. Regarding the web reference, the catch is that my machine can go to sleep at any time (my choice), so I need something more than is explained there. The rtcwake is what I'm using, but I need to issue those commands whenever the machine drops off...

    djh-novell, yes, sorry, when cutting out comments in my file I accidentally chopped one line (the open) from the script as I had shortened it for the forum... should be:

    Code:
    #!/usr/bin/perl
    my $cmd = "dbus-monitor --session \"type='signal',interface='org.gnome.ScreenSaver', member='SessionIdleChanged'\"";
    open (IN, "$cmd |");
    while (<IN>) {
    if (m/^\s+boolean true/) {
    system("/usr/sbin/rtcwake -m mem -t $(date --date=01:00:00 +%s)");
    system("/usr/sbin/rtcwake -m mem -t $(date --date=05:00:00 +%s)");
    system("/usr/sbin/rtcwake -m mem -t $(date --date=10:00:00 +%s)");
    system("/usr/sbin/rtcwake -m mem -t $(date --date=15:00:00 +%s)");
    } elsif (m/^\s+boolean false/) {
    system("echo Issued a wake-up reminder to ensure scheduled crontab jobs run");
    }
    }

  5. #5
    Join Date
    Jun 2008
    Location
    Podunk
    Posts
    32,323
    Blog Entries
    15

    Default Re: perl script intended to reactivate computer so that cron jobsrun

    Hi
    You need to run the dbus-monitor --session command and check the string your looking for is the same in the script.
    Cheers Malcolm °¿° SUSE Knowledge Partner (Linux Counter #276890)
    SUSE SLE, openSUSE Leap/Tumbleweed (x86_64) | GNOME DE
    If you find this post helpful and are logged into the web interface,
    please show your appreciation and click on the star below... Thanks!

  6. #6

    Default Re: perl script intended to reactivate computer so that cron jobsrun

    Thanks Malcolm... response to "dbus-monitor --session" is:

    signal sender=org.freedesktop.DBus -> dest=:1.1671 serial=2 path=/org/freedesktop/DBus; interface=org.freedesktop.DBus; member=NameAcquired
    string ":1.1671"
    method call sender=:1.1671 -> dest=org.freedesktop.DBus serial=3 path=/org/freedesktop/DBus; interface=org.freedesktop.DBus; member=AddMatch
    string "type='method_call'"
    method call sender=:1.1671 -> dest=org.freedesktop.DBus serial=4 path=/org/freedesktop/DBus; interface=org.freedesktop.DBus; member=AddMatch
    string "type='method_return'"
    method call sender=:1.1671 -> dest=org.freedesktop.DBus serial=5 path=/org/freedesktop/DBus; interface=org.freedesktop.DBus; member=AddMatch
    string "type='error'"
    Referring back to the script shown earlier, I guess I change to

    interface='org.freedesktop.DBus'

    but ought I also to make the substitution: member='AddMatch' ?

    Thx, John.

  7. #7
    Join Date
    Jun 2008
    Location
    Podunk
    Posts
    32,323
    Blog Entries
    15

    Default Re: perl script intended to reactivate computer so that cron jobsrun

    Hi
    Might be the case, can you manually create the screensaver or sleep to see what's output?
    Cheers Malcolm °¿° SUSE Knowledge Partner (Linux Counter #276890)
    SUSE SLE, openSUSE Leap/Tumbleweed (x86_64) | GNOME DE
    If you find this post helpful and are logged into the web interface,
    please show your appreciation and click on the star below... Thanks!

  8. #8

    Default Re: perl script intended to reactivate computer so that cron jobsrun

    Not sure what that means Malcolm, or how to proceed... thx, john

  9. #9

    Default Re: perl script intended to reactivate computer so that cron jobsrun

    PS. I do know how to force the machine into sleep using rtcwake -- but not sure where I should look for this "output"

  10. #10
    Join Date
    Jun 2008
    Location
    Podunk
    Posts
    32,323
    Blog Entries
    15

    Default Re: perl script intended to reactivate computer so that cron jobsrun

    On Thu, 2011-03-31 at 15:36 +0000, j1d1w1 wrote:
    > PS. I do know how to force the machine into sleep using rtcwake -- but
    > not sure where I should look for this "output"
    >
    >

    Hi
    So open a terminal and run the command, then put it to sleep, then wake
    it up. There should be output in the terminal showing the sleep and wake
    output.

    --
    Cheers Malcolm (Linux Counter #276890)
    SUSE Linux Enterprise Desktop 11 (x86_64) Kernel 2.6.32.29-0.3-default
    up 15:09, 2 users, load average: 0.00, 0.06, 0.04
    GPU GeForce 8600 GTS Silent - Driver Version: 260.19.26


Page 1 of 3 123 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •