ML
    • Recent
    • Categories
    • Tags
    • Popular
    • Users
    • Groups
    • Register
    • Login

    mailto alternative for systemd timers

    IT Discussion
    systemd timers
    4
    8
    990
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • W
      wirestyle22
      last edited by wirestyle22

      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?

      J 1 Reply Last reply Reply Quote 0
      • J
        JaredBusch @wirestyle22
        last edited by

        @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.

        W 1 Reply Last reply Reply Quote 2
        • W
          wirestyle22 @JaredBusch
          last edited by

          @jaredbusch Thanks

          J 1 Reply Last reply Reply Quote 0
          • J
            JaredBusch @wirestyle22
            last edited by

            @wirestyle22 There are lots of examples. you simply need to pick one.

            I would recommend either mailx or ssmtp

            0_1538491191030_e02a7d12-a064-4c8d-8ab2-2b799b676575-image.png

            1 Reply Last reply Reply Quote 3
            • J
              JaredBusch
              last edited by JaredBusch

              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/

              S 1 Reply Last reply Reply Quote 3
              • W
                wirestyle22
                last edited by

                Extremely helpful. Thanks @JaredBusch

                1 Reply Last reply Reply Quote 0
                • S
                  scottalanmiller
                  last edited by

                  I use mailx most of the time.

                  1 Reply Last reply Reply Quote 1
                  • S
                    stacksofplates @JaredBusch
                    last edited by

                    @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.

                    1 Reply Last reply Reply Quote 2
                    • 1 / 1
                    • First post
                      Last post