mailto alternative for systemd timers
-
I read that systemd timers can't mailto. With cron phasing out there must be a way to receive e-mails when a timer fails. If not, how do you resolve this when you are managing several hundred servers?
-
@wirestyle22 said in mailto alternative for systemd timers:
I read that systemd timers can't mailto. With cron phasing out there must be a way to receive e-mails when a timer fails. If not, how do you resolve this when you are managing several hundred servers?
You write a shell script to send email and then call said script with your script that you use to create the timer.
-
@jaredbusch Thanks
-
@wirestyle22 There are lots of examples. you simply need to pick one.
I would recommend either
mailx
orssmtp
-
I would recommend writing the script to take parameters. Because then it is generic and you can plug it in on every system as part of the system setup process.
https://tecadmin.net/pass-command-line-arguments-in-shell-script/ -
Extremely helpful. Thanks @JaredBusch
-
I use mailx most of the time.
-
@jaredbusch said in mailto alternative for systemd timers:
I would recommend writing the script to take parameters. Because then it is generic and you can plug it in on every system as part of the system setup process.
https://tecadmin.net/pass-command-line-arguments-in-shell-script/Here's a template that I loosely follow for this:
#!/bin/bash #Script functions function script_help () { echo " Usage: $(basename $0) [options] -a word -a Echos the word you type -h this help text Example: $(basename $0) "-a word exit ${1:-0} } function thing () { echo $variable } #Show help if no arguments or options are passed [[ ! "$*" ]] && script_help 1 OPTIND=1 #Read command line options # A colon after a flag means it takes an argument while getopts "a:ih" opt; do case "$opt" in a) variable=$OPTARG ;; h) script_help ;; \?) script_help 1 ;; esac done shift $(($OPTIND-1)); #Run argument function thing
In this case, it calls the thing function on the argument from the -a flag and also has a help function.