Does cron make up missed jobs?

If my computer is off at the time of a scheduled job does cron run that job at the next boot or is it lost?

Thanks, jon

On Mon 13 Oct 2014 06:26:01 PM CDT, 6520302 wrote:

If my computer is off at the time of a scheduled job does cron run that
job at the next boot or is it lost?

Thanks, jon

Hi
Unless you have specified a cron job time, they will run 15 minutes
after boot.


Cheers Malcolm °¿° LFCS, SUSE Knowledge Partner (Linux Counter #276890)
openSUSE 13.1 (Bottle) (x86_64) GNOME 3.10.1 Kernel 3.11.10-21-desktop
If you find this post helpful and are logged into the web interface,
please show your appreciation and click on the star below… Thanks!

Malcolm:

Thank you. Yes, I have specified a time.

I set up a job to run one time every week. So by specifying a time it will fail if the computer is not running?
I guess I need to rethink my strategy.

Rgds, jon

On Mon 13 Oct 2014 07:36:01 PM CDT, 6520302 wrote:

malcolmlewis;2669306 Wrote:
> Hi
> Unless you have specified a cron job time, they will run 15 minutes
> after boot.

Malcolm:

Thank you. Yes, I have specified a time.

I set up a job to run one time every week. So by specifying a time it
will fail if the computer is not running?
I guess I need to rethink my strategy.

Rgds, jon

Hi
Use the @reboot?


Cheers Malcolm °¿° LFCS, SUSE Knowledge Partner (Linux Counter #276890)
openSUSE 13.1 (Bottle) (x86_64) GNOME 3.10.1 Kernel 3.11.10-21-desktop
If you find this post helpful and are logged into the web interface,
please show your appreciation and click on the star below… Thanks!

Thanks again. Not aware of that option and will research it.

Jon

Hi Malcolm:

@reboot doesn’t sound like the right solution. It runs once after reboot. I reboot every day but only want to run the job on Friday.

I’ll just change the time of the job to make sure it runs late enough in the day that I’m unlikely to have a problem with the computer off.

Appreciate your tips. The forum won’t let me click the star because you were the last person I clicked on the star.

Rgds, Jon

On 2014-10-13 21:25, malcolmlewis wrote:

> On Mon 13 Oct 2014 06:26:01 PM CDT, 6520302 wrote:
>
>
>> If my computer is off at the time of a scheduled job does cron run that
>> job at the next boot or is it lost?

> Hi
> Unless you have specified a cron job time, they will run 15 minutes
> after boot.

Wait, those are not “normal” cron jobs. They are the jobs that you
create in “/etc/cron.{hourly,daily,weekly,monthly}”. They are a SuSE
addition. Those will certainly run at the next opportunity, starting 15
minutes after boot.

But there is no way to specify a job to run on Fridays, and if failed,
do when possible. For that you would use anacron instead, I guess.

You can set the preferred time for daily jobs, though.

Maybe the /usr/lib/cron/run-crons script could be improved for a
preferred weekday.

A way would be to put the job at an scheduled time, and then have a
daily job to verify that last time it run was not more than 7 days ago,
and if not, run it.


Cheers / Saludos,

Carlos E. R.
(from 13.1 x86_64 “Bottle” at Telcontar)

Ahhh, things are getting more complicated. I’ll study these suggestions but for my simple purposes it seems that changing the job start time to a later time in the day, when my computer is usually running, would be the simplest way to insure I don’t miss the job running.

Jon

On 2014-10-14 02:46, 6520302 wrote:

> Ahhh, things are getting more complicated. I’ll study these suggestions
> but for my simple purposes it seems that changing the job start time to
> a later time in the day, when my computer is usually running, would be
> the simplest way to insure I don’t miss the job running.

There may be other simpler ways. You can just place the script in
“/etc/cron.daily/”, and have it check at the start if “today is Friday”.
If it is not, exit.


cer@Telcontar:~> date '+%A'
Tuesday
cer@Telcontar:~> date '+%u'
2
cer@Telcontar:~>

It is trivial to use that in a script.

Then on “/etc/sysconfig/cron” you define:


DAILY_TIME="22:10"

So it will normally run every Friday at about 22:15, but if that time
the computer is not running, it will run the next day, or perhaps 15
minutes after boot; I’m unsure about daily jobs, but I think it is 15
minutes, not next day.


Cheers / Saludos,

Carlos E. R.
(from 13.1 x86_64 “Bottle” at Telcontar)

robin:

Thanks for the script info. I’m very green on scripts and syntax requirements. I think the code you posted looks good and I will give it a try.
It looks a lot better than me just having a crontab for a time that I may or may not miss by being shutdown.

Rgds, Jon

On 2014-10-15 18:36, 6520302 wrote:

> Thanks for the script info. I’m very green on scripts and syntax
> requirements. I think the code you posted looks good and I will give it
> a try.
> It looks a lot better than me just having a crontab for a time that I
> may or may not miss by being shutdown.

If you have difficulties with the script, ask :slight_smile:


#!/bin/bash

TODAYIS=`date '+%u'`

if  $TODAYIS -eq 5 ]; then
echo "Today is Friday"
else
echo "Today is not Friday"
fi

If after the not Friday echo you place a line with “exit”, the script
will simply exit. So you can either place your code below the “is
Friday” echo, or below the “fi”.


Cheers / Saludos,

Carlos E. R.
(from 13.1 x86_64 “Bottle” at Telcontar)

robin:

Thanks, I do have some issues I need help resolving.

First, there are a number of scripts in cron.daily that apparently come with the system. I am using v13.1x64 kde.

drwxr-xr-x 140 root root  12288 Oct 15 18:36 ..
-rwxr-xr-x   1 root root      1 May 17  2011 google-earth
-rwxr-xr-x   1 root root    634 Apr  3  2014 logrotate
-rwxr-xr-x   1 root root    778 Jun 12 01:58 mdadm
-rwxr-xr-x   1 root root   1414 Oct  2  2013 packagekit-background.cron
-rwx--x--x   1 jon  users   184 Oct 15 18:33 run-ffox
-rwxr--r--   1 root root    948 Sep 27  2013 suse-clean_catman
-rwxr-xr-x   1 root root   1875 Sep 12 00:14 suse.de-backup-rc.config
-rwxr-xr-x   1 root root   2059 Sep 12 00:14 suse.de-backup-rpmdb
-rwxr-xr-x   1 root root    566 Sep 12 00:14 suse.de-check-battery
-rwxr-xr-x   1 root root    371 Sep 12 00:14 suse.de-cron-local
-rwxr-xr-x   1 root root    744 Oct  8  2013 suse.de-snapper
-rwxr--r--   1 root root   1693 Sep 27  2013 suse-do_mandb

My question about this is that I have changed sysconfig/cron to set a Daily_Time and changed the max_not_run to 0 and wonder if that has an undesirable effect on these originally installed scripts.

Regarding my script:

When cron runs my script the messages & warn logs has an entry that “scriptname returned 1”
My script runs fine in a terminal. The purpose of the script is to open firefox to a specific url.
Also the code shown below (after the echo) runs fine in crontab

I have made sure the code is executable and I even tried changing the owner on the off chance that was my problem, currently the script is as shown below, the values are to test it’s function and will ultimately be changed to a different day & time.


#!/bin/bash

TODAYIS=`date '+%u'`

if  $TODAYIS -eq 3 ]; then
echo "Today is Wed"
export DISPLAY=:0 && firefox --new-window http://www.virtualbox.org
else
echo "Today is not Friday"
exit
fi

So why am I getting a return code of 1?

Rgds, Jon

Try using absolute path

/bin/firefox

Instead of just firefox also check the error message in /var/spool/mail or the likes

On 2014-10-16 04:06, 6520302 wrote:

> Thanks, I do have some issues I need help resolving.
>
> First, there are a number of scripts in cron.daily that apparently come
> with the system. I am using v13.1x64 kde.

Yes, there are a bunch.

> My question about this is that I have changed sysconfig/cron to set a
> Daily_Time and changed the max_not_run to 0 and wonder if that has an
> undesirable effect on these originally installed scripts.

No, no issue at all.

> Regarding my script:
>
> When cron runs my script the messages & warn logs has an entry that
> “scriptname returned 1”
> My script runs fine in a terminal. The purpose of the script is to open
> firefox to a specific url.

Can’t be done.

Firefox needs a graphical terminal, and your script has none.

If you absolutely need firefox to run automatically, you need seeking
for a way to start it via some mechanism in your desktop, not via cron.
Not possible or far from simple.


Cheers / Saludos,

Carlos E. R.
(from 13.1 x86_64 “Bottle” at Telcontar)

On 2014-10-16, jetchisel <jetchisel@no-mx.forums.opensuse.org> wrote:
> > export DISPLAY=:0 && firefox --new-window http://www.virtualbox.org

I’m not sure cron jobs can be made to run within X, which is a necessity for Firefox. Have you tried using lynx instead?

Robin & Flymail:

Thanks for your replies. I will try the absolute path and see if it helps, I gather that it won’t.

What puzzles me is that this works just fine in crontab. It opens a terminal and runs FF.

Why would crontab work but not the same code in a script. Is that because of the way the shell is executed?

Jon

Probably because a cron job in /etc/cron.daily/ is executed as root, whereas one in crontab is run as the corresponding user.

And only the owning user has access to the X session by default, not even root can open a window there, unless the user allows it (see “man xhost”).
That’s one of the reasons why things like kdesu, gnomesu, and xdg-su exist to run GUI applications as root.

OK, I’ll research your comments and try to gain further knowledge.

I do want to mention, but don’t know if it is applicable, that I changed the owner of the script to myself & group users after it previously failed to run as owner root. Of course, it still doesn’t work.

Jon

It doesn’t matter who’s the owner of the script. It still runs as the user who called it (provided that user has the necessary file permissions of course, i.e. read and execute).
And for scripts in /etc/cron.daily/ that’s root.

If you call the script from your user’s crontab, it should work.

Yes, it does work. The issue that started this thread was that crontab doesn’t make up missed schedules when the computer is shutdown whereas cron.daily does make up the missed schedule. It was suggested upthread that I try cron.daily to make up missed schedules but for reasons that you have mentioned this will not work.

I’ll go back to using crontab and have a scheduled time that most likely will not be effected by the computer being shutdown at the scheduled time.

Thanks, Jon