systemd, send an email after restart

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
0
down vote

favorite












I am using systemd to autolaunch a service with the following script: (see below)



I am trying to send an email before the service is started (the commented out line).



the link at the end of the line /home/vincent/wintergreen/service_files/IB_restart_email is the content of the email, as described here in paragraph 7.



Unit]
Description=Manages an instance of IBController

[Service]
Type=forking
User=vincent
Group=vincent
ExecStart=/bin/bash -c "cd /opt/IBController && bash IBControllerStart.sh -inline && sleep 10"
# ExecStartPre=/usr/bin/mail -s "Restarting TWS" me@gmail.com < /home/vincent/wintergreen/service_files/IB_restart_email
Environment=DISPLAY=:0.0
KillMode=control-group
TimeoutSec=0
Restart=always

[Install]
WantedBy=graphical.target


However, this line returns the error mail: Cannot parse address <' (while expanding <'): Malformed email address. (i can see the error message when opening the journalctl)



This command works when used directly in the shell. Anyone has an idea how to make this mail sending line work when used from the systemd file?



PS: I am using postfix for the mail sending







share|improve this question



















  • Have you try in format cat /home/vincent/wintergreen/service_files/IB_restart_email|/usr/bin/mail -s "Restarting TWS" me@gmail.com because < symbol is user as part of email address
    – Romeo Ninov
    May 16 at 16:31






  • 1




    You used /bin/bash -c ... for the ExecStart, so why not also for the ExecStartPre line?
    – thrig
    May 16 at 16:41














up vote
0
down vote

favorite












I am using systemd to autolaunch a service with the following script: (see below)



I am trying to send an email before the service is started (the commented out line).



the link at the end of the line /home/vincent/wintergreen/service_files/IB_restart_email is the content of the email, as described here in paragraph 7.



Unit]
Description=Manages an instance of IBController

[Service]
Type=forking
User=vincent
Group=vincent
ExecStart=/bin/bash -c "cd /opt/IBController && bash IBControllerStart.sh -inline && sleep 10"
# ExecStartPre=/usr/bin/mail -s "Restarting TWS" me@gmail.com < /home/vincent/wintergreen/service_files/IB_restart_email
Environment=DISPLAY=:0.0
KillMode=control-group
TimeoutSec=0
Restart=always

[Install]
WantedBy=graphical.target


However, this line returns the error mail: Cannot parse address <' (while expanding <'): Malformed email address. (i can see the error message when opening the journalctl)



This command works when used directly in the shell. Anyone has an idea how to make this mail sending line work when used from the systemd file?



PS: I am using postfix for the mail sending







share|improve this question



















  • Have you try in format cat /home/vincent/wintergreen/service_files/IB_restart_email|/usr/bin/mail -s "Restarting TWS" me@gmail.com because < symbol is user as part of email address
    – Romeo Ninov
    May 16 at 16:31






  • 1




    You used /bin/bash -c ... for the ExecStart, so why not also for the ExecStartPre line?
    – thrig
    May 16 at 16:41












up vote
0
down vote

favorite









up vote
0
down vote

favorite











I am using systemd to autolaunch a service with the following script: (see below)



I am trying to send an email before the service is started (the commented out line).



the link at the end of the line /home/vincent/wintergreen/service_files/IB_restart_email is the content of the email, as described here in paragraph 7.



Unit]
Description=Manages an instance of IBController

[Service]
Type=forking
User=vincent
Group=vincent
ExecStart=/bin/bash -c "cd /opt/IBController && bash IBControllerStart.sh -inline && sleep 10"
# ExecStartPre=/usr/bin/mail -s "Restarting TWS" me@gmail.com < /home/vincent/wintergreen/service_files/IB_restart_email
Environment=DISPLAY=:0.0
KillMode=control-group
TimeoutSec=0
Restart=always

[Install]
WantedBy=graphical.target


However, this line returns the error mail: Cannot parse address <' (while expanding <'): Malformed email address. (i can see the error message when opening the journalctl)



This command works when used directly in the shell. Anyone has an idea how to make this mail sending line work when used from the systemd file?



PS: I am using postfix for the mail sending







share|improve this question











I am using systemd to autolaunch a service with the following script: (see below)



I am trying to send an email before the service is started (the commented out line).



the link at the end of the line /home/vincent/wintergreen/service_files/IB_restart_email is the content of the email, as described here in paragraph 7.



Unit]
Description=Manages an instance of IBController

[Service]
Type=forking
User=vincent
Group=vincent
ExecStart=/bin/bash -c "cd /opt/IBController && bash IBControllerStart.sh -inline && sleep 10"
# ExecStartPre=/usr/bin/mail -s "Restarting TWS" me@gmail.com < /home/vincent/wintergreen/service_files/IB_restart_email
Environment=DISPLAY=:0.0
KillMode=control-group
TimeoutSec=0
Restart=always

[Install]
WantedBy=graphical.target


However, this line returns the error mail: Cannot parse address <' (while expanding <'): Malformed email address. (i can see the error message when opening the journalctl)



This command works when used directly in the shell. Anyone has an idea how to make this mail sending line work when used from the systemd file?



PS: I am using postfix for the mail sending









share|improve this question










share|improve this question




share|improve this question









asked May 16 at 15:38









jim basquiat

1417




1417











  • Have you try in format cat /home/vincent/wintergreen/service_files/IB_restart_email|/usr/bin/mail -s "Restarting TWS" me@gmail.com because < symbol is user as part of email address
    – Romeo Ninov
    May 16 at 16:31






  • 1




    You used /bin/bash -c ... for the ExecStart, so why not also for the ExecStartPre line?
    – thrig
    May 16 at 16:41
















  • Have you try in format cat /home/vincent/wintergreen/service_files/IB_restart_email|/usr/bin/mail -s "Restarting TWS" me@gmail.com because < symbol is user as part of email address
    – Romeo Ninov
    May 16 at 16:31






  • 1




    You used /bin/bash -c ... for the ExecStart, so why not also for the ExecStartPre line?
    – thrig
    May 16 at 16:41















Have you try in format cat /home/vincent/wintergreen/service_files/IB_restart_email|/usr/bin/mail -s "Restarting TWS" me@gmail.com because < symbol is user as part of email address
– Romeo Ninov
May 16 at 16:31




Have you try in format cat /home/vincent/wintergreen/service_files/IB_restart_email|/usr/bin/mail -s "Restarting TWS" me@gmail.com because < symbol is user as part of email address
– Romeo Ninov
May 16 at 16:31




1




1




You used /bin/bash -c ... for the ExecStart, so why not also for the ExecStartPre line?
– thrig
May 16 at 16:41




You used /bin/bash -c ... for the ExecStart, so why not also for the ExecStartPre line?
– thrig
May 16 at 16:41










1 Answer
1






active

oldest

votes

















up vote
2
down vote



accepted










As documented in man systemd.service, systemd has a limited support for shell syntax, which does not include "<". So, the character is set to the "mail" command, resulting in this error.



I presume you are most interested in emails due to automatic restarts, which wold be due to service crashes.



For that, the OnFailure= directive is a better choice. Use it to provide a spaces-separated list of units that are activated when the unit enters the failed state.



There are already ready-made solutions to handle this, like this one which will email you the "status" output (including some log output) of the service when it fails.



Also, consider using the WorkingDirectory= directive instead of manually calling "cd" in ExecStart=.



It also not clear why "sleep 10" would be needed as part of starting the app.






share|improve this answer





















    Your Answer







    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "106"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    convertImagesToLinks: false,
    noModals: false,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );








     

    draft saved


    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f444179%2fsystemd-send-an-email-after-restart%23new-answer', 'question_page');

    );

    Post as a guest






























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    2
    down vote



    accepted










    As documented in man systemd.service, systemd has a limited support for shell syntax, which does not include "<". So, the character is set to the "mail" command, resulting in this error.



    I presume you are most interested in emails due to automatic restarts, which wold be due to service crashes.



    For that, the OnFailure= directive is a better choice. Use it to provide a spaces-separated list of units that are activated when the unit enters the failed state.



    There are already ready-made solutions to handle this, like this one which will email you the "status" output (including some log output) of the service when it fails.



    Also, consider using the WorkingDirectory= directive instead of manually calling "cd" in ExecStart=.



    It also not clear why "sleep 10" would be needed as part of starting the app.






    share|improve this answer

























      up vote
      2
      down vote



      accepted










      As documented in man systemd.service, systemd has a limited support for shell syntax, which does not include "<". So, the character is set to the "mail" command, resulting in this error.



      I presume you are most interested in emails due to automatic restarts, which wold be due to service crashes.



      For that, the OnFailure= directive is a better choice. Use it to provide a spaces-separated list of units that are activated when the unit enters the failed state.



      There are already ready-made solutions to handle this, like this one which will email you the "status" output (including some log output) of the service when it fails.



      Also, consider using the WorkingDirectory= directive instead of manually calling "cd" in ExecStart=.



      It also not clear why "sleep 10" would be needed as part of starting the app.






      share|improve this answer























        up vote
        2
        down vote



        accepted







        up vote
        2
        down vote



        accepted






        As documented in man systemd.service, systemd has a limited support for shell syntax, which does not include "<". So, the character is set to the "mail" command, resulting in this error.



        I presume you are most interested in emails due to automatic restarts, which wold be due to service crashes.



        For that, the OnFailure= directive is a better choice. Use it to provide a spaces-separated list of units that are activated when the unit enters the failed state.



        There are already ready-made solutions to handle this, like this one which will email you the "status" output (including some log output) of the service when it fails.



        Also, consider using the WorkingDirectory= directive instead of manually calling "cd" in ExecStart=.



        It also not clear why "sleep 10" would be needed as part of starting the app.






        share|improve this answer













        As documented in man systemd.service, systemd has a limited support for shell syntax, which does not include "<". So, the character is set to the "mail" command, resulting in this error.



        I presume you are most interested in emails due to automatic restarts, which wold be due to service crashes.



        For that, the OnFailure= directive is a better choice. Use it to provide a spaces-separated list of units that are activated when the unit enters the failed state.



        There are already ready-made solutions to handle this, like this one which will email you the "status" output (including some log output) of the service when it fails.



        Also, consider using the WorkingDirectory= directive instead of manually calling "cd" in ExecStart=.



        It also not clear why "sleep 10" would be needed as part of starting the app.







        share|improve this answer













        share|improve this answer



        share|improve this answer











        answered May 16 at 16:59









        Mark Stosberg

        3,4891023




        3,4891023






















             

            draft saved


            draft discarded


























             


            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f444179%2fsystemd-send-an-email-after-restart%23new-answer', 'question_page');

            );

            Post as a guest













































































            Popular posts from this blog

            How to check contact read email or not when send email to Individual?

            Displaying single band from multi-band raster using QGIS

            How many registers does an x86_64 CPU actually have?