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 Tuesday, April 5th, 2022 at 6:43 PM, Ranjan Maitra <mlmaitra@xxxxxxx> wrote:


> On Tue Apr05'22 10:02:35PM, Barry wrote:
>
> > From: Barry barry@xxxxxxxxxxxxxxxx
> > Date: Tue, 5 Apr 2022 22:02:35 +0100
> > To: olivares33561 olivares33561@xxxxxxxxxxxxxx, Community support for
> > Fedora users users@xxxxxxxxxxxxxxxxxxxxxxx
> > Reply-To: Community support for Fedora users users@xxxxxxxxxxxxxxxxxxxxxxx
> > Subject: Re: convert crontab jobs to systemd timers
> >
> > > On 5 Apr 2022, at 21:19, olivares33561 via users users@xxxxxxxxxxxxxxxxxxxxxxx wrote:
> > >
> > > Dear kind Fedora users,
> > >
> > > I have a crontab file that I use to play some files about 3 minutes before bell rings between classes. I had to install anacron with dnf command. I have seen emails where some folks recommend systemd timers. How can I convert a crontab
> > > #
> > > [olivares@fedora Downloads]$ crontab -l
> > > # min hour day-of-month month day-of-week command
> > > # 0-59 0-23 1-31 1-12 0-6 0=sun 1=mon
> > > #50 04 * * 1-5 ~/.xalarm >/dev/null 2>&1
> > > #50 04 * * 0,6 ~/.salarm >/dev/null 2>&1
> > > #59 09 * * 0,6 ~/.salarm >/dev/null 2>&1
> > > #00 07 * * 1-5 ~/.xalarm >/dev/null 2>&1
> > > 42 08 * * 1-5 ~/.dalarm >/dev/null 2>&1
> > > 52 09 * * 1-5 ~/.dalarm >/dev/null 2>&1
> > > 40 10 * * 1-5 ~/.dalarm >/dev/null 2>&1
> > > 28 11 * * 1-5 ~/.dalarm >/dev/null 2>&1
> > > 16 12 * * 1-5 ~/.dalarm >/dev/null 2>&1
> > > 57 12 * * 1-5 ~/.dalarm >/dev/null 2>&1
> > > 40 14 * * 1-5 ~/.dalarm >/dev/null 2>&1
> > > 28 15 * * 1-5 ~/.dalarm >/dev/null 2>&1
> > > 17 16 * * 1-5 ~/.dalarm >/dev/null 2>&1
> > > #30 16 * * 1-5 ~/.lalarm > /dev/null 2>&1
> > > 25 16 * * 1-5 /usr/sbin/poweroff >/dev/null 2>&1
> > >
> > > #
> > > to systemd timers? An easy idiot proof way. The .dalarm script calls mplayer and plays from a playlist.
> > >
> > > #
> > > [olivares@fedora Downloads]$ sudo systemctl list-timers
> > > [sudo] password for olivares:
> > > NEXT LEFT LAST PASSED UN>
> > > Tue 2022-04-05 15:13:39 CDT 1min 46s left n/a n/a sy>
> > > Tue 2022-04-05 15:38:11 CDT 26min left n/a n/a dn>
> > > Wed 2022-04-06 00:00:00 CDT 8h left Tue 2022-04-05 05:34:07 CDT 9h ago lo>
> > > Wed 2022-04-06 00:00:00 CDT 8h left Tue 2022-04-05 05:34:07 CDT 9h ago un>
> > > Wed 2022-04-06 00:34:55 CDT 9h left Tue 2022-04-05 05:34:07 CDT 9h ago pl>
> > > Sun 2022-04-10 01:00:00 CDT 4 days left Tue 2022-04-05 05:34:07 CDT 9h ago ra>
> > > Mon 2022-04-11 00:20:16 CDT 5 days left Tue 2022-04-05 05:34:07 CDT 9h ago fs>
> > >
> > > 7 timers listed.
> > > Pass --all to see loaded but inactive timers, too.
> > > #
> > >
> > > I have read https://opensource.com/article/20/7/systemd-timers
> > > and
> > > https://www.maketecheasier.com/use-systemd-timers-as-cron-replacement/
> > >
> > > but have not tried it out. Any help on this is appreciated. I want to test it out. Thank you in advance
> >
> > Why not try it out? What is stopping you?
> >
> > The only thing I would add to you reading list if the man page for systemd.timer
> >
> > I would start with a timer service that uses /bin/echo that you can use to see that the timer service runs when you expect.
> >
> > Barry
>
>
> So sorry to suddenly wake up on this thread, but is cron going away. I use it all the time, hourly for backups and nightly for updates.
>
> Many thanks,
> Ranjan

I do not know the answer to that question, but I wanted to find out if there are scripts that can help convert a crontab file to a systemd-timer run based.  Many people are recommending it.  I am used to using crontab, but running Fedora 36(Beta* I know not part of this list, but I had to install anacron to get it working),.  In previous versions of Fedora I did not have to do this.  So it may*, maynot* survive the future.

In case someone can help, I setup my crontab with the following:

[olivares@fedora ~]$ cat ~/.dalarmsetup2.sh
#!/bin/sh
#
# This script sets up to find music and sets up a player and plays music at a certain time
#
# create file to find music and setup crontab accordingly
FIND=$(echo `which find`)
SORT=$(echo `which sort`)
XTERM=$(echo `which xterm`)
MPLAYER=$(echo `which mplayer`)
SLEEP=$(echo `which sleep`)
KILL=$(echo `which kill`)
XSET=$(echo `which xset`)
echo "#!/bin/sh " >> ~/.fndmus
echo "# " >> ~/.fndmus
echo "# find the music & create playlist" >> ~/.fndmus
echo "# " >> ~/.fndmus
echo "# find the music check ~/ /media/disk where music is stored :)" >> ~/.fndmus
echo "$FIND ~/ -iname ""*.mp3"" -o -iname ""*.og*"" -o -iname ""*.m4a""-o -iname ""*.wma"" -o -iname "*.ra"> ~/.playlist-all " >> ~/.fndmus
echo "# sort the playlist " >> ~/.fndmus
echo "$SORT ~/.playlist-all> ~/.playlist " >> ~/.fndmus
chmod +x ~/.fndmus
# setup crontab to play music
#set -ue
tmp=/tmp/crontab$$
crontab -l >"$tmp"
echo "# min  hour day-of-month month day-of-week command" >> "$tmp"
echo "# 0-59 0-23    1-31    1-12  0-6 0=sun 1=mon " >> "$tmp"
echo "#50 04 * * 1-5 ~/.xalarm >/dev/null 2>&1" >>"$tmp"
echo "#50 04 * * 0,6 ~/.salarm >/dev/null 2>&1" >>"$tmp"
echo "#59 09 * * 0,6 ~/.salarm >/dev/null 2>&1" >>"$tmp"
echo "#00 07 * * 1-5 ~/.xalarm >/dev/null 2>&1" >>"$tmp"
echo "42 08 * * 1-5 ~/.dalarm >/dev/null 2>&1" >>"$tmp"
echo "52 09 * * 1-5 ~/.dalarm >/dev/null 2>&1" >>"$tmp"
echo "40 10 * * 1-5 ~/.dalarm >/dev/null 2>&1" >>"$tmp"
echo "28 11 * * 1-5 ~/.dalarm >/dev/null 2>&1" >>"$tmp"
echo "16 12 * * 1-5 ~/.dalarm >/dev/null 2>&1" >>"$tmp"
echo "57 12 * * 1-5 ~/.dalarm >/dev/null 2>&1" >>"$tmp"
echo "40 14 * * 1-5 ~/.dalarm >/dev/null 2>&1" >>"$tmp"
echo "28 15 * * 1-5 ~/.dalarm >/dev/null 2>&1" >>"$tmp"
echo "17 16 * * 1-5 ~/.dalarm >/dev/null 2>&1 " >>"$tmp"
echo "#30 16 * * 1-5 ~/.lalarm > /dev/null 2>&1" >> "$tmp"
echo "25 16 * * 1-5 sudo systemctl poweroff >/dev/null 2>&1" >>"$tmp"
crontab "$tmp"
rm "$tmp"
# setup Mplayer to play with xterm
echo "#!/bin/sh                                    " >>  ~/.xalarm
echo "#                                              " >> ~/.xalarm
echo "# save as ~/.xalarm                          " >> ~/.xalarm
echo " " >> ~/.xalarm
echo "export DISPLAY=:0" >> ~/.xalarm
echo "$XSET dpms force on;" >> ~/.xalarm
echo "$XSET -dpms;" >> ~/.xalarm
echo " " >> ~/.xalarm
echo "$XTERM -display :0 -bg black -fg white \\" >> ~/.xalarm
echo "-e $MPLAYER -really-quiet -shuffle -playlist ~/.playlist & PID=\$!" >> ~/.xalarm
echo "$SLEEP 1680"  >> ~/.xalarm
echo "$KILL \$PID"  >> ~/.xalarm
echo " " >> ~/.xalarm
echo "$XSET +dpms;" >> ~/.xalarm
echo "$XSET dpms force off;" >> ~/.xalarm
chmod +x ~/.xalarm
# run the script mean to find music and create playlist
~/.fndmus
cp ~/.xalarm ~/.lalarm
cp ~/.xalarm ~/.salarm
cp ~/.xalarm ~/.dalarm
sed -i 's|1680|14400|g' ~/.lalarm
sed -i 's|1680|600|g' ~/.salarm
sed -i 's|1680|360|g' ~/.dalarm

It calls on several programs and it sets it up and works automagically :)  I just want to have something in case this functionality goes away and try it out and hope it works the same. I had to add code to enable the monitor(since I am using hdmi), the screen needs to wake up and had to install xset.  If anyone can share code/script to convert the above crontab to a systemd-timer unit It would be awesome.

Links
[1] : https://fedoraproject.org/wiki/Features/SystemdCalendarTimers
[2] : https://wiki.archlinux.org/title/Systemd/Timers

Thanks & 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