LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 02-03-2016, 08:08 AM   #1
gargunkle
Member
 
Registered: Oct 2011
Posts: 31

Rep: Reputation: Disabled
systemd: send a mail at boot time


Hi,

I have a CentOS 7 system whose IP may change sometimes. I would like to send a mail at boot time. I am using postfix. The config I have is:

[root@system ~]# cat /etc/systemd/system/mailip.service
[Unit]
Description=mailip
After=network-online.target
Wants=network-online.target

[Service]
ExecStart=/root/mailip.sh
Type=oneshot

[Install]
WantedBy=multi-user.target graphical.target

[root@system ~]# cat /root/mailip.sh
#!/bin/bash

ip addr | mail -s "system start ip config" address@isp.com
[root@system ~]#

I had run:
systemctl daemon-reload
systemctl enable mailip

If I run /root/mailip.sh manually it works. However, if I reboot the system or run "systemctl start mailip," no mail is generated. Any ideas what I could be missing?

Many thanks.
 
Old 02-03-2016, 04:37 PM   #2
thesnow
Member
 
Registered: Nov 2010
Location: Minneapolis, MN
Distribution: Ubuntu, Red Hat, Mint
Posts: 172

Rep: Reputation: 56
Since you don't explicitly set the path for ip or mail in mailip.sh, have you checked your PATH variable, or tried adding it in your script? Similar thing has chumped me many times with cron, e.g.:

Code:
export PATH=$PATH:/path/to/ip:/path/to/mail
 
Old 02-03-2016, 06:20 PM   #3
twork
LQ Newbie
 
Registered: Mar 2015
Posts: 20

Rep: Reputation: Disabled
One idea: change:

Code:
ip addr | mail -s "system start ip config" address@isp.com
...to:

Code:
ip addr | mail -s "system start ip config" address@isp.com >> /var/log/mailip.log 2>&1
Then if something is going wrong with invocation, you should get a record of it in /var/log/mailip.log.

If nothing shows up there, then we know that either your script isn't being called, or the problem is happening somewhere further down the process.
 
Old 02-03-2016, 06:32 PM   #4
notjustrelational
LQ Newbie
 
Registered: Feb 2016
Posts: 1

Rep: Reputation: Disabled
This looks right:

[root@system ~]# cat /etc/systemd/system/mailip.service
[Unit]
Description=mailip
After=network-online.target
Wants=network-online.target

[Service]
ExecStart=/root/mailip.sh
Type=oneshot

[Install]
WantedBy=multi-user.target graphical.target

[root@system ~]# cat /root/mailip.sh
#!/bin/bash

ip addr | mail -s "system start ip config" address@isp.com >> /var/log/mailip.log 2>&1
[root@system ~]#

I had run:
systemctl daemon-reload
systemctl enable mailip
 
Old 02-04-2016, 10:27 AM   #5
gargunkle
Member
 
Registered: Oct 2011
Posts: 31

Original Poster
Rep: Reputation: Disabled
Hmm, still no go.

Haven't changed /etc/systemd/system/mailip.service

[root@system ~]# cat /root/mailip.sh
#!/bin/bash

/usr/sbin/ip addr | /usr/bin/mail -s "system start ip config" address@isp.com >> /var/log/mailip.log 2>&1


Works as /root/mailip.sh still (but oddly nothing gets written to /var/log/mailip.log)

-rw-r--r-- 1 root root 0 Feb 4 10:22 /var/log/mailip.log

"systemctl start mailip" doesn't generate a mail, doesn't update the log and doesn't write to maillog.

Feb 4 10:24:07 systemname systemd: Starting mailip...
Feb 4 10:24:07 systemname systemd: Started mailip.

It's odd.
 
Old 02-04-2016, 10:56 PM   #6
twork
LQ Newbie
 
Registered: Mar 2015
Posts: 20

Rep: Reputation: Disabled
Okay, so it looks like our init process isn't calling that script at all, but just to be sure, what if we set aside the present script and replace it with:

#!/bin/bash
echo "testing: $0" > /tmp/testing-${0}.out

Then if that tmp file doesn't show up, we know that the trouble is somewhere in systemd, and not something weird with the mail setup, or the way the mail and systemd areas interact.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: A Two-Second Boot Time With systemd LXer Syndicated Linux News 0 05-14-2012 09:00 AM
Boot Delay 30min: systemd-analyze blame systemd-tmpfiles-setup.service BGHolmes Fedora 0 07-27-2011 10:02 AM
Ubuntu won't boot after installing send mail penguinman99 Ubuntu 2 08-14-2006 12:52 AM
HOw to send mail at a particular time indian Linux - General 2 08-29-2004 02:50 AM
E-Mail clients are taking time to send /receive mails qs_tahmeed Linux - Networking 0 08-23-2004 11:07 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 03:25 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration