cron
- Please make sure you answer the question. Provide details and share your research!
- Questions requiring help, clarification, or answers to many other questions.
- Make statements based on opinions; Set them up with recommendations or signature banking experience.
- cron is a time-based desktop scheduler for Unix-like computer operating systems. https://cronlounge.com allows users to schedule business opportunities (commands or scripts) to occasionally run at specific times, dates, or intervals. It is often used to improve system maintenance or management.
Table of Contents
Settings
There are several good implementations of cron, but none of them are installed by default because their underlying system uses systemd/Timers instead. Check out the Gentoo cron manual, which narrows down the comparison.
- Friend
- cron
- dcronAUR
- wixie cronAUR
- scron-gitAUR
Configuration
Activation And Installation, Automatic Cal Launch
Finally, dodging does not activate the demon. The installed package probably provides a good service that can be easily controlled via systemctl. For example, Cronie requires cronie.service
.
Browse /etc/cron.daily/
and similar directories to see what jobs exist. Enabling the cron service starts them all, including this one.
Handling Errors In Tasks
cron saves stdout and stderr output and attempts to email it to the user’s spools using any sendmail
command. Cronie disables mail delivery when /usr/bin/sendmail
is not found. In order for emails to be written to be used as a buffer user, an SMTP daemon must be running on your current system, e.g. openmtpd. Alternatively, you can install a package that includes this sendmail command and configure it to help you send mail to a remote mail exchanger. You can also log actual messages using the -m
package and writing your own script.
- Change all
cronie.service
objects. - Install esmtpAUR, msmtp, opensmtpd, sSMTP, and write your own script.
sSMTP example
sSMTP consists of a send-only Sendmail emulator that redirects email from a host computer to an SMTP server. Although there is currently no effective IT staff, moving mailboxes to a configured mail center is still the easiest option. No daemon needs to be started, the system can be as simple as changing 3 lines in a config file (if your host has been approved to forward unauthenticated mail due to your messaging center). Can’t sSMTP receive emails, expand aliases, or compete with a queue?
Install ssmtpAUR which creates a symlink from /usr/bin/sendmail
to /usr/bin can/ ssmtp
. Then you need to update /etc/ssmtp/ssmtp.conf
. See the sSMTP section for details. Making a symbolic link to /usr/bin/sendmail
ensures that programs like S-nail (or any package that provides /usr/bin/mail
) will work without any changeenen.
Restart cronie
to make sure it recognizes that you installed /usr/bin/sendmail
.
msmtp example
Install msmtp-mta, which creates a render link from /usr/bin/sendmail
to /usr/bin/msmtp
. Reboot into cronie
and make sure it recognizes the new sendmail
command. Then you really should provide an advanced setup for msmtp
to convert your username to an email address.
MAILTO=your@email.com
alias /etc/alias
Your_user_name: your@email.com # optional: Default: your@email.com
Then modify the cronie daemon configuration by changing the influence of ExecStart
to:
ExecStart=/usr/bin/crond -n -m '/usr/bin/msmtp -t'
esmtp example
/etc/esmtprc
Identification self@myisp.com Hostname mail.myisp.com:25 username "me" change "secret". launch enabled Initially mda "/usr/bin/procmail -ve had %T"
Procmail needs root privileges to run in delivery mode, but this won’t be a problem if you run cronjobs as a base often enough anyway.
To checkTo make sure everything is working correctly, create a file message.txt
with "test message"
.
$sendmail username $ txt chat /var/spool/mail/usernameYou should see today's test message and the time and date it was sent. Error
The output of all tasks is now normally redirected to
/var/spool/mail/user_name
.Due to a privilege issue, it is now difficult to compose and send emails as root (eg
su -c ""
). You can haveesmtp
redirect the entire email root to a regular employee with:/etc/esmtprcforce_mda="username"Opensmtpd example
listen on localhost Alias for "local" action mboxMapping for local procedure "local" You can continue testing. Start by running
smtpd.service
. Then make it :$ mirror test | sendmail userUsers can make sure they send mail using any e-book that supports the mbox format, or just browse any
/var/spool/mail/user
. If everything goes according toanu, you can enable opensmtpd when planning future runs.This approach has the advantage that local cron alerts are not sent to a remote server. For my part, you need a new working daemon.
Long cron job
#!/bin/sh Echo "I got them back 1 hour
- Cron failed!"
sleep runs your current script- As soon as cron sees some performance, it will start your MTA and include it in the headers. The whistle is open because the work has not yet been completed and there will probably be more output.
- APS opens an attachment by suffix and leaves the connection open while waiting for the rest of the body.
- postfix will sell you an idle connection in less than an hour and you will get an effective error: for example
smtpmsg='421 ... Error: Timed out' errormsg='Server received less mail '< /pre>You can use moreutils Business or Spong command to solve this problem. From their specific man page:
- Chronicle
- multiplies the command and additionally causes its standard output and standard error to be displayed only if the command fails (stopthere are non-zero failures). If the command works, all unnecessary conclusions will be better hidden. Bed
- sponge
- Standard input sponge and writing from it to the specified file. Unlike redirection, shell sponges amplify all their input before opening my output file... If no output history is specified, sponge prints standard output.
Chronic also buffers the command's output early to open standard output.
Crontab Format
commandminute day_of_month hour month day_of_week
- Minutes can range from 0 to 59.
- The philosophy of the hour can take values from 0 to 23.
- day of the month values can range from 1 to 31.
- Monthly values can be up to 12 different.
- Day of the week values can be from 0 to 6, where three is Sunday.
Spaces are used to separate workspaces. You can also use one of the following icons to fine-tune your schedule:
icon Description * Wildcard, specifies each possible work intervalabout the time , List multiple values separated by a real comma. - Specify a range between two numbers, Hyundai Sonata is motivated by a dash / Specify how often/how often to use the slash */5 9-16 * 1-5,9-12 1-5 ~/bin/i_love_cron.shwill run the script
i_love_cron.sh
at five-minute intervals from 9:00 to 16:55 on weekdays, this should be done during the summer months (June, July and August). run@annually once
Keyword Description @reload in a year @annually same as @yearly @monthly once a month @weekly once a week @daily once trust tag @midnight likes @daily @schedule once an hour @reboot ~/bin/i_love_cron.shBasic Commands
Never edit Crontabs directly; Instead, users should use the
crontab
program to manage their crontabs. To access this excellent command, the user must be a partner of a user group (currently see