# apcupsd - not emailing me when power down

## Joseph_sys

My remote box is connected direclty to apcups and it is running "apcupsd"

However, when I pull the cord out of the wall the "onbattery" script is not

email me anything.

My configuration: apcupsd.conf

```
UPSCABLE usb

UPSTYPE usb

DEVICE

POLLTIME 60

LOCKFILE /var/lock

SCRIPTDIR /etc/apcupsd

PWRFAILDIR /etc/apcupsd

NOLOGINDIR /etc

ONBATTERYDELAY 6

BATTERYLEVEL 60

MINUTES 10

TIMEOUT 0

ANNOY 300

ANNOYDELAY 60

NOLOGON disable

KILLDELAY 0

NETSERVER on

NISIP 0.0.0.0

NISPORT 3551

EVENTSFILE /var/log/apcupsd.events

EVENTSFILEMAX 10

UPSCLASS standalone

UPSMODE disable

STATTIME 0

STATFILE /var/log/apcupsd.status

LOGSTATS off

DATATIME 0
```

onbattery - script suppose to be called by "/etc/apcupsd/apccontrol" and execute it.

What am I missing?

I have "mailto" installed and it is working. I sent an email to "root" and I received it.

There is nothing to be configured in "onbattery" script.

----------

## mvaterlaus

hi,

you have to edit the on battery event script and send yourself a mail when the script is executet. Normally, apcupsd sends a message via wall, so all logged in users are notified that the ups is running on battery. If you do not implement the mailing part, you wont get any mails.

You could also send a mail for every event by replacing the ${WALL} command in the apccontrol script, but if you overwrite the wall command, your logged in users are not notified when the ups status changes and they probably will get an unexpected logout.

----------

## Joseph_sys

 *mvaterlaus wrote:*   

> hi,
> 
> you have to edit the on battery event script and send yourself a mail when the script is executet. Normally, apcupsd sends a message via wall, so all logged in users are notified that the ups is running on battery. If you do not implement the mailing part, you wont get any mails.
> 
> You could also send a mail for every event by replacing the ${WALL} command in the apccontrol script, but if you overwrite the wall command, your logged in users are not notified when the ups status changes and they probably will get an unexpected logout.

 

onbattery - script suppose to be called by "/etc/apcupsd/apccontrol" and execute it. What am I missing? 

I have "mailto" installed and it is working. I sent an email to "root" and I received it.

There is nothing to be configured in "onbattery" script:

```
#!/bin/sh

#

# This shell script if placed in /etc/apcupsd

# will be called by /etc/apcupsd/apccontrol when the UPS

# goes on batteries.

# We send an email message to root to notify him.

#

SYSADMIN=root

APCUPSD_MAIL="/bin/mail"

HOSTNAME=`hostname`

MSG="$HOSTNAME Power Failure !!!"

#

(

  echo "Subject: $MSG"

  echo " "

  echo "$MSG"

  echo " "

  /sbin/apcaccess status

) | $APCUPSD_MAIL -s "$MSG" $SYSADMIN

exit 0

The script is called by apccontrol and SYSADMIN=root
```

Yes, I have "/bin/mail" on the path.

So I don't know why isn't it working.

----------

## mvaterlaus

ok. i didn't know the mail part is already scripted in gentoo. please have a look at the var ONBATTERYDELAY in your apcupsd.conf. It will tell you, how long it takes unitl the event ONBATTERY is raised.

also, have a look at /var/log/apcupsd.event and pull out the cable to see if the event appears in the log.

----------

## Joseph_sys

 *mvaterlaus wrote:*   

> ok. i didn't know the mail part is already scripted in gentoo. please have a look at the var ONBATTERYDELAY in your apcupsd.conf. It will tell you, how long it takes unitl the event ONBATTERY is raised.
> 
> also, have a look at /var/log/apcupsd.event and pull out the cable to see if the event appears in the log.

 

I just checked the log "apcupsd.events" is not registering anything from apcupsd.

I unplug/plug the power from the wall and there was no entry in the /var/log/apcupsd.events 

```
tail /var/log/apcupsd.events 

2015-06-06 17:29:57 -0600  Valid lock file for pid=2386, but not ours pid=32492

2015-06-06 17:29:57 -0600  apcupsd FATAL ERROR in device.c at line 71

Unable to create UPS lock file.

  If apcupsd or apctest is already running,

  please stop it and run this program again.

2015-06-06 17:29:57 -0600  Valid lock file for pid=2386, but not ours pid=32492

2015-06-06 17:29:57 -0600  apcupsd error shutdown completed

2015-06-06 17:35:07 -0600  apcupsd exiting, signal 15

2015-06-06 17:35:07 -0600  apcupsd shutdown succeeded

2015-06-06 17:35:46 -0600  apcupsd 3.14.8 (16 January 2010) gentoo startup succeeded
```

My configuration: apcupsd.conf 

```
sed -e 's/#.*//' -e '/^$/ d' apcupsd.conf

UPSCABLE usb

UPSTYPE 

DEVICE 

LOCKFILE /var/lock

SCRIPTDIR /etc/apcupsd

PWRFAILDIR /etc/apcupsd

NOLOGINDIR /etc

ONBATTERYDELAY 6

BATTERYLEVEL 60

MINUTES 10

TIMEOUT 0

ANNOY 300

ANNOYDELAY 60

NOLOGON disable

KILLDELAY 0

NETSERVER on

NISIP 0.0.0.0

NISPORT 3551

EVENTSFILE /var/log/apcupsd.events

EVENTSFILEMAX 10

UPSCLASS standalone

UPSMODE disable

STATTIME 0

STATFILE /var/log/apcupsd.status

LOGSTATS off

DATATIME 0
```

apccontrol - I did not touch it.

The apcupsd is started.

----------

## mvaterlaus

Does it work to read the status of your ups manually with the apctest tool [1]? For this to work, you have to shutdown the apcupsd daemon.

[1]http://www.apcupsd.org/manual/manual.html#apctest

----------

## Joseph_sys

 *mvaterlaus wrote:*   

> Does it work to read the status of your ups manually with the apctest tool [1]? For this to work, you have to shutdown the apcupsd daemon.
> 
> [1]http://www.apcupsd.org/manual/manual.html#apctest

 

apctest - is working 

```
apctest 

2015-06-09 16:21:45 apctest 3.14.8 (16 January 2010) gentoo

Checking configuration ...

Attached to driver: usb

sharenet.type = DISABLE

cable.type = USB_CABLE

You are using a USB cable type, so I'm entering USB test mode

mode.type = USB_UPS

Setting up the port ...

Hello, this is the apcupsd Cable Test program.

This part of apctest is for testing USB UPSes.

Getting UPS capabilities...SUCCESS

Please select the function you want to perform.

1)  Test kill UPS power

2)  Perform self-test

3)  Read last self-test result

4)  View/Change battery date

5)  View manufacturing date

6)  View/Change alarm behavior

7)  View/Change sensitivity

8)  View/Change low transfer voltage

9)  View/Change high transfer voltage

10) Perform battery calibration

11) Test alarm

12) View/Change self-test interval

 Q) Quit
```

Though the problem I think it might be my small box. "Intel(R) Atom(TM) CPU  330   @ 1.60GHz"

Though, I don't know how this could be causing a problem.

On a remote location I have two computers connected to this APCUPS, one is this Atom and another one full-tower box that is running apcupsd in a slave mode; and it is working correctly.  When power goes down I get and email from my tower-box; but not from small one Atom.

----------

