I have ubuntu 18.04 and I recently added the rc.local script to /etc/ so I could run my emailing script to email myself my IP address from my jetson nano computer. I need it to email me because I cannot setup a static IP and the IP changes occasionally. The computer will be setup on a 1:16 RC race car so I have to ssh into it.

I used this tutorial to setup ssmtp on ubuntu: https://stackoverflow.com/questions/38391412/raspberry-pi-send-mail-from-command-line-using-gmail-smtp-server

I used this tutorial to attempt to run the script I show below on startup on ubuntu 18.04: https://www.linuxbabe.com/linux-server/how-to-enable-etcrc-local-with-systemd

This is my emailIP.sh :


echo "$STR" | ssmtp my.email@gmail.com

It is a very simple script and it works when i run it using sh emailIP.sh

When I run sudo systemctl start rc-local.service and then run sudo systemctl status rc-local.service

I get this output:

 ● rc-local.service - /etc/rc.local Compatibility
   Loaded: loaded (/etc/systemd/system/rc-local.service; enabled; vendor preset: enabled)
  Drop-In: /lib/systemd/system/rc-local.service.d
   Active: active (exited) since Sat 2019-03-23 14:45:28 CDT; 15min ago
  Process: 4391 ExecStart=/etc/rc.local start (code=exited, status=0/SUCCESS)

Mar 23 14:45:28 servanh-desktop systemd[1]: Starting /etc/rc.local Compatibility...
Mar 23 14:45:28 servanh-desktop rc.local[4391]: ssmtp: Cannot open smtp.gmail.com:587
Mar 23 14:45:28 servanh-desktop sSMTP[4497]: Unable to locate smtp.gmail.com
Mar 23 14:45:28 servanh-desktop sSMTP[4497]: Cannot open smtp.gmail.com:587
Mar 23 14:45:28 servanh-desktop systemd[1]: Started /etc/rc.local Compatibility.

So what I am not understanding is why it is giving me this Unable to locate smtp.gmail.com error when its in my /etc/ssmtp/ssmtp.conf and if that file was not configured correctly then my script would not run when I do sh emailIP.sh?

Edit: Me sad

  • Perhaps the required network services (name resolution in particular) are not ready at that time? – steeldriver Mar 23 at 21:12
  • Would that still be a problem if I test rc.local while my device is already booted? Does 'sudo systemctl start rc-local.service' recreate boot sequence? – Dayman Mar 23 at 21:24
  • Hmm... that's a good point - I must admit I read your question quickly and assumed the output was from the bootime journal. I don't know what happens when the rc-local service is started later. – steeldriver Mar 23 at 21:45
  • Don't worry I sometimes read over too fast too. Thank you for taking a look I really do appreciate it. – Dayman Mar 23 at 21:49
  • The same error message, "ssmtp: Cannot open..." was discussed in This question. You might check to see if any of the comments or answers apply to your situation. – John1024 Mar 23 at 23:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.