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
#!/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");
}
}
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.
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:
#!/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");
}
}
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.
So, what is the typical scenario for your system going into standby? What I think needs to be done, is monitor the dbus output and carry on as normal, then review the dbus monitor output so you can select a ‘trigger’ for the script to activate.
The session monitor does not provide any information… I can have the machine slip into sleep for a few seconds and emerge, but nothing is logged in dbus-monitor --session. Anyhow I’ll leave the dbus-monitor active and watch out for anything that might pertain. Thanks again, John.
On Thu, 2011-03-31 at 18:36 +0000, j1d1w1 wrote:
> The session monitor does not provide any information… I can have the
> machine slip into sleep for a few seconds and emerge, but nothing is
> logged in dbus-monitor --session. Anyhow I’ll leave the dbus-monitor
> active and watch out for anything that might pertain. Thanks again,
> John.
>
>
Hi
Check down in /var/log as well there maybe something to monitor in one
of the log files.
Thanks Malcolm – had a quick look at files in /var/log without anything jumping out as helpful. dbus-monitor --session --profile has these entries that are I think related to the screensaver coming on or off… John.
sig 1301604573 386969 25 /org/gnome/ScreenSaver org.gnome.ScreenSaver ActiveChanged
sig 1301604573 387320 84 /org/gnome/SessionManager/Presence org.gnome.SessionManager.Presence StatusChanged
Hello Malcolm, I have some info that might suggest a “trigger” to activate my perl script. I went to a departmental seminar at about 11:55 MDT, and my machine went to sleep some time later (apparently at 12:35:19, which probably makes sense: my settings are that display goes inactive after 10 minutes, and the computer “goes to sleep when inactive for 30 minutes”). I returned at about 13:00 MDT and when I issued a dbus-monitor --session I got some clues. The monitor registered events at Unix time 1301682919 (12:35:19) then nothing until 1301684370 (12:59:30) which coincides nicely with when I returned from the seminar. Do you see anything here that suggests how I might amend my perl script? Thanks, John.
Hi
OK, lets assume the following would create the trigger;
my $cmd = "dbus-monitor --session \"type='signal',interface='org.gnome.ScreenSaver', member='GetActive'\"";
Then you would really need to look at a form of cancel, so normal activities don’t set it running, if you don’t have a cancel it will start multiple instances, else add a check by creating a PID file, and see if it exists and act accordingly.
Not sure what you mean by having a cancel – is that a further instruction in the perl script? And this would be, multiple instances of the rtcwake command? If so, that might not matter (unless it was zillions of them)? Thanks, John.
Thanks Malcolm: I made that change in my script (my $cmd = “dbus-monitor --session “type=‘signal’,interface=‘org.gnome.ScreenSaver’, member=‘GetActive’””;)… as earlier, when I restart the machine with this as a start-up job as soon as I have logged in I get the default blank green screen and nothing else… so I did a CRTL ALT F1 and renamed the script. John.