1

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 :

#!/bin/bash
STR="$(/sbin/ifconfig)"

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
           └─debian.conf
   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

Dayman
  • 11
  • 2
  • Perhaps the required network services (name resolution in particular) are not ready at that time? – steeldriver Mar 23 '19 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 '19 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 '19 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 '19 at 21:49
  • The same error message, "ssmtp: Cannot open..." was discussed in [This question](https://askubuntu.com/questions/531526/ssmtp-cannot-open-mail-server-com25). You might check to see if any of the comments or answers apply to your situation. – John1024 Mar 23 '19 at 23:50
  • If you have another email which you can use with SMTP, try using that intead of GMail to isolate the problem of whether it's your script or the GMail issue. If it is GMail issue, likely you may want to change the GMail account settings, for example look at https://github.com/matomo- org/matomo/issues/8613 and https://www.digitalocean.com/community/tutorials/how-to-use-google-s-smtp-server step number 6 – Sergiy Kolodyazhnyy Mar 24 '19 at 01:50

0 Answers0