Cronjob with log

Hi,

I created a cron job, and usualy with that command I got a log but there is no log with that one, idea why? Maybe it is different with openSUSE?
thanks

sudo crontab -l
[sudo] password for root: 
50 21 * * * /sbin/shutdown -h now >> /tmp/shutdown_cron.log 2>&1

@james80 openSUSE Tumbleweed uses systemd timers, cron is somewhat old and rather deprecated.

1 Like

but the shutdown still works but I wonder why I dont have log…

@james80 /tmp is tmpfs, gone on a reboot…

1 Like

Ok i see, on Debian it was different so, the log stayed there.

Do you have a suggestion where to put it?
Anywhere i guess :grin:

@james80 /var/log? But if you change to a systemd timer, it should be in the journal (maybe even with cron…)

1 Like

I do not know what you expect to go into /tmp/shutdown_cron.log, but as far as I can see it, this command produces no output at all on stdout, nor on stderr when everything is well.

Also, when you have /tmp as a tmpfs, then it will be destroyed on shutdown, thus on next boot it will be empty.

BTW, my idea is that while the whole mechanism is taken over by systemd, the crontab interface will be supported by systemd for a considerable time to come. There is to much of a code base used with it on private and professional systems build up in > 50 years to drop it.

1 Like

@hcvv it’s not the default (or installed) anymore on Tumbleweed.

Thanks for the info.

on tumbleweed, crontab is there…

Thanks for the info.

@james80 but is cron installed (i not a +i)…

I am on Leap 15.6, but here the package cron contains:

/etc/cron.d
/etc/cron.daily
/etc/cron.hourly
/etc/cron.monthly
/etc/cron.weekly
/usr/share/doc/packages/cron
/usr/share/doc/packages/cron/cron_to_cronie.README

thus NOT the deamon.
The deamon /usr/sbin/cron seems to be in the cronie package. And the tool crontab is also part of it. Thus when the OP shows he uses the command crontab, I aasume he has the package cronie installed. If that is from the standard Tumbleweed OSS repo or from elsewhere I can not see.

@hcvv It’s still there, but one must manually install, so override the defaults in Tumbleweed :wink:

NIce. There are more of those kind.

But we better return to the original question. which was NOT "does cron function or not, but about the fact that the OP searches for some logging.

I asked what he expects to get because a good problem description is: what did you do (I think that is clear), what did you expect to get (not really clear) and what did you get instead (also not 100% clear, nothing, an empty file?).

@hcvv The real issue is that Tumbleweed rolls, users need to also move with the times else get left behind, and if new technologies aren’t working, create bug reports…

so something like that would do the job?

create /etc/systemd/system/auto-suspend.timer:

[Unit]
Description=Automatically suspend on a schedule

[Timer]
OnCalendar=*-*-* 03:00:00

[Install]
WantedBy=timers.target

/etc/systemd/system/auto-suspend.service:

[Unit]
Description=Suspend

[Service]
Type=oneshot
ExecStart=/usr/bin/systemctl suspend

[Unit]
Description=Suspend

[Service]
Type=oneshot
ExecStart=/usr/bin/systemctl suspend

I am more conservative. As long as there is no clear definition of an issue I will not give any verdict about it being the real issue or not.

@james80 if the ExecStart=command works, then it should :wink:

Which job?
In your post #3

So the job is done.