Re: convert crontab jobs to systemd timers

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Sent from ProtonMail, encrypted email based in Switzerland.
------- Original Message -------
On Saturday, April 9th, 2022 at 5:46 PM, Mike Wright <nobody@xxxxxxxxxxxxxxxxxxxx> wrote:


> On 4/8/22 05:43, olivares33561 via users wrote:
>
> > Sent from ProtonMail, encrypted email based in Switzerland.
> >
> >
> > ------- Original Message -------
> > On Friday, April 8th, 2022 at 5:13 AM, Barry Scott barry@xxxxxxxxxxxxxxxx wrote:
> >
> > > > On 7 Apr 2022, at 21:22, olivares33561 via users users@xxxxxxxxxxxxxxxxxxxxxxx wrote:
> > > >
> > > > Sent from ProtonMail, encrypted email based in Switzerland.
> > > >
> > > > I am getting closer.
> > > >
> > > > [olivares@fedora user]$ cat poweroff.service
> > > > # /etc/systemd/system/poweroff.service
> > > > [Unit]
> > > > Description = Poweroff machine at 16:20 PM Mo-Fri
> > > >
> > > > [Service]
> > > > Type=oneshot
> > > > #ExecStart=~/bin/poweroff.sh
> > > > ExecStart=/usr/bin/sudo /usr/bin/systemctl --no-block poweroff.service
> > >
> > > To power down the system you can use the command
>
> Best Regards,
>
>
> Antonio
> _______________________________________________
> users mailing list -- users@xxxxxxxxxxxxxxxxxxxxxxx
> To unsubscribe send an email to users-leave@xxxxxxxxxxxxxxxxxxxxxxx
> Fedora Code of Conduct:
> https://docs.fedoraproject.org/en-US/project/code-of-conduct/
> List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines
> List Archives:
> https://lists.fedoraproject.org/archives/list/users@xxxxxxxxxxxxxxxxxxxxxxx
> Do not reply to spam on the list, report it:
> https://pagure.io/fedora-infrastructure
>
> > > /usr/bin/systemctl poweroff
> > >
> > > See man systemctl for the details of what this does.
> > >
> > > Barry
> > >
> > > > [olivares@fedora user]$ cat poweroff.timer
> > > > # /etc/systemd/system/poweroff.timer
> > > > [Unit]
> > > > Description=Poweroff machine at 4:20 PM Mo-Fri
> > > >
> > > > [Timer]
> > > > OnCalendar=Mon..Fri --* 16:20:00
> > > > Persistent=true
> > > >
> > > > [Install]
> > > > WantedBy=timers.target
> > > >
> > > > I get the following error message:
> > > >
> > > > [olivares@fedora user]$ systemctl --user enable poweroff.service
> > > > The unit files have no installation config (WantedBy=, RequiredBy=, Also=,
> > > > Alias= settings in the [Install] section, and DefaultInstance= for template
> > > > units). This means they are not meant to be enabled using systemctl.
> > > >
> > > > Possible reasons for having this kind of units are:
> > > > • A unit may be statically enabled by being symlinked from another unit's
> > > > .wants/ or .requires/ directory.
> > > > • A unit's purpose may be to act as a helper for some other unit which has
> > > > a requirement dependency on it.
> > > > • A unit may be started when needed via activation (socket, path, timer,
> > > > D-Bus, udev, scripted systemctl call, ...).
> > > > • In case of template units, the unit is meant to be enabled with some
> > > > instance name specified.
> > > > [olivares@fedora user]$
> > > >
> > > > Thank you all for helping me.
> > > >
> > > > Best Regards,
> > > >
> > > > Antonio
> >
> > I have modified poweroff.service and added the line
> >
> > [olivares@fedora user]$ cat poweroff.service
> > # /etc/systemd/system/poweroff.service
> > [Unit]
> > Description = Poweroff machine at 16:20 PM Mo-Fri
> >
> > [Service]
> > Type=oneshot
> > #ExecStart=~/bin/poweroff.sh
> > #ExecStart=/usr/bin/sudo /usr/bin/systemctl --no-block poweroff.service
> > ExecStart=/usr/bin/systemctl poweroff
> > [olivares@fedora user]$ cat poweroff.timer
> > # /etc/systemd/system/poweroff.timer
> > [Unit]
> > Description=Poweroff machine at 4:20 PM Mo-Fri
> >
> > [Timer]
> > OnCalendar=Mon..Fri --* 07:45:00
> > Persistent=true
> >
> > [Install]
> > WantedBy=timers.target
> > [olivares@fedora user]$
> >
> > however, when I try to enable the service I get
> >
> > [olivares@fedora user]$ mcedit poweroff.service
> >
> > [olivares@fedora user]$ mcedit poweroff.timer
> >
> > [olivares@fedora user]$ systemctl --user enable poweroff.service
> > The unit files have no installation config (WantedBy=, RequiredBy=, Also=,
> > Alias= settings in the [Install] section, and DefaultInstance= for template
> > units). This means they are not meant to be enabled using systemctl.
> >
> > Possible reasons for having this kind of units are:
> > • A unit may be statically enabled by being symlinked from another unit's
> > .wants/ or .requires/ directory.
> > • A unit's purpose may be to act as a helper for some other unit which has
> > a requirement dependency on it.
> > • A unit may be started when needed via activation (socket, path, timer,
> > D-Bus, udev, scripted systemctl call, ...).
> > • In case of template units, the unit is meant to be enabled with some
> > instance name specified.
> > [olivares@fedora user]$
> >
> > I changed 16:20:00 to 07:45:00 for testing purposes. But this is what I get. I just want a service that powers off machine using this method. The crontab method of shutting down the machine worked before, but now fails too. I don't have any crontab entries anymore to make sure it does not affect/compete with systemd-timer.
> >
> > [olivares@fedora user]$ crontab -l
> > [olivares@fedora user]$
>
>
> Please be so kind as to share your solution.

I will report back with one that works, but with a caveat.  I still need to fix a problem with display.  The monitor goes to sleep and I need to wake it up.  If it is up, the service and timers created work great.  a dalarm service and dalarm.timer :

[olivares@fedora ~]$ cd .config/systemd/user/
[olivares@fedora user]$ ls
dalarm.service  dalarm.timer  default.target.wants  timers.target.wants
[olivares@fedora user]$ cat dalarm.timer
[Unit]
Description=Schedule a message every 1 minute
RefuseManualStart=no  # Allow manual starts
RefuseManualStop=no   # Allow manual stops

[Timer]
#Execute job if it missed a run due to machine being off
Persistent=true
#Run 120 seconds after boot for the first time
#OnBootSec=120
#Run every 1 minute thereafter
#OnUnitActiveSec=60
#File describing job to execute
#Unit=schedule-test.service
# run every day
OnCalendar=Mon-Fri *-*-* 08:42:00
OnCalendar=Mon-Fri *-*-* 09:52:00
OnCalendar=Mon-Fri *-*-* 10:40:00
OnCalendar=Mon-Fri *-*-* 11:28:00
OnCalendar=Mon-Fri *-*-* 12:16:00
OnCalendar=Mon-Fri *-*-* 12:57:00
OnCalendar=Mon-Fir *-*-* 14:40:00
OnCalendar=Mon-Fri *-*-* 15:28:00
OnCalendar=Mon-Fri *-*-* 16:17:00

[Install]
WantedBy=timers.target
[olivares@fedora user]$ cat dalarm.service
[Unit]
Description=A job to test the systemd scheduler & play music to prepare for next class

[Service]
Type=simple
ExecStart=/home/olivares/bin/dalarm.sh

[Install]
WantedBy=default.target
[olivares@fedora user]$ cat ~/bin/dalarm.sh
#!/bin/sh
#
#

export DISPLAY=:0
/usr/bin/xset dpms force on;
#/usr/bin/xset -dpms;

/usr/bin/xterm -display :0 -bg black -fg white \
-e /usr/local/bin/mplayer -really-quiet -shuffle -playlist ~/.playlist & PID=$!
/usr/bin/sleep 360
/usr/bin/kill $PID

#/usr/bin/xset +dpms;
/usr/bin/xset dpms force off;
[olivares@fedora user]$ cat ~/bin/dalarm.sh
#!/bin/sh
#
#

export DISPLAY=:0
/usr/bin/xset dpms force on;
#/usr/bin/xset -dpms;

/usr/bin/xterm -display :0 -bg black -fg white \
-e /usr/local/bin/mplayer -really-quiet -shuffle -playlist ~/.playlist & PID=$!
/usr/bin/sleep 360
/usr/bin/kill $PID

#/usr/bin/xset +dpms;
/usr/bin/xset dpms force off;

-----------------------------------
The script works well, but I need to wake up the screen which it does not do :(  This is why I asked the other question and I had to run the command to see if X11 was running or wayland.  It is wayland so the old commands do not work.  I have it blank after 2 minutes, and if I am not using the computer the dalarm service does not play the music.  Thanks to all who have helped/guided me to find a working solution(conversion to systemd-timer for a crontab entry).
The one for shutdown I have removed it because it did not work, maybe because there are already services with the same names?  I will turn off machine manually in the meantime.  If someone has a solution, I would appreciate it very much. I just need a simple shutdown/poweroff at 4:20 ---> 16:20:00 which is the end of the day and it is (Good place/time to stop the machine)

Best Regards,


Antonio
_______________________________________________
users mailing list -- users@xxxxxxxxxxxxxxxxxxxxxxx
To unsubscribe send an email to users-leave@xxxxxxxxxxxxxxxxxxxxxxx
Fedora Code of Conduct: https://docs.fedoraproject.org/en-US/project/code-of-conduct/
List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines
List Archives: https://lists.fedoraproject.org/archives/list/users@xxxxxxxxxxxxxxxxxxxxxxx
Do not reply to spam on the list, report it: https://pagure.io/fedora-infrastructure



[Index of Archives]     [Older Fedora Users]     [Fedora Announce]     [Fedora Package Announce]     [EPEL Announce]     [EPEL Devel]     [Fedora Magazine]     [Fedora Summer Coding]     [Fedora Laptop]     [Fedora Cloud]     [Fedora Advisory Board]     [Fedora Education]     [Fedora Security]     [Fedora Scitech]     [Fedora Robotics]     [Fedora Infrastructure]     [Fedora Websites]     [Anaconda Devel]     [Fedora Devel Java]     [Fedora Desktop]     [Fedora Fonts]     [Fedora Marketing]     [Fedora Management Tools]     [Fedora Mentors]     [Fedora Package Review]     [Fedora R Devel]     [Fedora PHP Devel]     [Kickstart]     [Fedora Music]     [Fedora Packaging]     [Fedora SELinux]     [Fedora Legal]     [Fedora Kernel]     [Fedora OCaml]     [Coolkey]     [Virtualization Tools]     [ET Management Tools]     [Yum Users]     [Yosemite News]     [Gnome Users]     [KDE Users]     [Fedora Art]     [Fedora Docs]     [Fedora Sparc]     [Libvirt Users]     [Fedora ARM]

  Powered by Linux