October 5, 200817 yr So then there's not way to do it from an unRaid machine? I don't have any other machines that stay on 24/7. Only my two unRaid servers.
October 6, 200817 yr So then there's not way to do it from an unRaid machine? I don't have any other machines that stay on 24/7. Only my two unRaid servers. Certainly there is a way. It is time for you to read the installation document for apcupsd. It describes how you can set up a network notification to other apcupsd processes running on additional machines on your LAN. Joe L.
October 6, 200817 yr Author My power flickered today as I was watching TV. When I got back to my computer there were two emails waiting for me from apcupsd. One telling me the power went out, the second that the power was back up. Pretty cool.
October 8, 200817 yr So then there's not way to do it from an unRaid machine? I don't have any other machines that stay on 24/7. Only my two unRaid servers. Certainly there is a way. It is time for you to read the installation document for apcupsd. It describes how you can set up a network notification to other apcupsd processes running on additional machines on your LAN. Joe L. You're right, I should've read the manual before posting here. Because I view unRaid as proprietary, I assume most things will be unique to unRaid and also assume that most manuals or instructions found elsewhere won't be of much help. From what I gathered out of doing this little project it seems like some things are common among Linux distros and especially unRaid and Slackware. Anyhow, I apologize if I came across as wanting to be spoon fed. Hopefully this is my last question on this... I have apcupsd working on both my servers using one UPS. They both shutdown cleanly and as expected, but I'm now trying to get the UPS to shutdown after the last server goes down so that when power is restored my servers will power up automatically. I have set both BIOS's so that they power up when they receive AC power, and it works as expected except I have to manually power off the UPS. When I plug the UPS back in, both servers power up like I want. I read planetscott's post on page 2 of this thread about how he changed /etc/rc.d/rc.0 and replaced a few lines. I'm not sure how to do this. I can edit the file though Midnight Commander, but it's actually on a RAM drive which means it will reset on a reboot, right? I tried to copy the file to /boot so I can put a line in my go file to copy my custom version on each boot, but MC gave me an error. Something about a symlink. I notice the file size is extremely small and when I viiew the file it talks about point to rc.6, so I thought maybe it's just a link to the file rc.6 and I should edit that one, but MC gives an error when trying to edit rc.6? What do I need to do to make the changes to this file?
October 8, 200817 yr You're right, I should've read the manual before posting here. Because I view unRaid as proprietary, I assume most things will be unique to unRaid and also assume that most manuals or instructions found elsewhere won't be of much help. From what I gathered out of doing this little project it seems like some things are common among Linux distros and especially unRaid and Slackware. Anyhow, I apologize if I came across as wanting to be spoon fed. Most of unRAID is not proprietary. The only two pieces that are, are emhttp (the web-management interface) and the "user share" file-system that presents a merged version of the various disks. The rest of unRAID is a stripped down version of "slackware" Linux. It in turn has most of itself in common with most other Linux distributions. The "apcupsd" package is available on just about any Linux version out there. Hopefully this is my last question on this... I have apcupsd working on both my servers using one UPS. They both shutdown cleanly and as expected, but I'm now trying to get the UPS to shutdown after the last server goes down so that when power is restored my servers will power up automatically. I have set both BIOS's so that they power up when they receive AC power, and it works as expected except I have to manually power off the UPS. When I plug the UPS back in, both servers power up like I want. I read planetscott's post on page 2 of this thread about how he changed /etc/rc.d/rc.0 and replaced a few lines. I'm not sure how to do this. I can edit the file though Midnight Commander, but it's actually on a RAM drive which means it will reset on a reboot, right? I tried to copy the file to /boot so I can put a line in my go file to copy my custom version on each boot, but MC gave me an error. Something about a symlink. I notice the file size is extremely small and when I viiew the file it talks about point to rc.6, so I thought maybe it's just a link to the file rc.6 and I should edit that one, but MC gives an error when trying to edit rc.6? What do I need to do to make the changes to this file? He did more than he needed. You do not need to edit the rc.0 file at all. The apcupsd package has the ability to shut down the UPS in an extended outage. I already included the few commands needed to accomplish that. They were these last few lines in the script of mine you probably already installed: [pre] #Now, put into place the shutdown script replacement echo "/sbin/powerdown" >/etc/apcupsd/doshutdown echo "exit 99" >>/etc/apcupsd/doshutdown chmod 755 /etc/apcupsd/doshutdown sed -i -e "/\/sbin\/poweroff/i[ -f \/etc\/apcupsd\/powerfail ] \&\& \/etc\/apcupsd\/apccontrol killpower" /etc/rc.d/rc.6 [/pre] You do need to install the powerdown command. (I think WeboTech was the one who posted it) Other than that, apcupsd will invoke the "doshutdown" script when the batteries get near depletion and. it will invoke "powerdown" and that will do exactly as you describe... Note: you do need to add one more line to the script I posted earlier to send the signal to the UPS to shut itself down. so everything starts up again when power is restored. It is the last line in the script above. Joe L.
October 8, 200817 yr Now I'm confused. I thought that part of the script was invoked WeeboTech's script to shutdown unRaid. I had that installed prior to trying to get the UPS to shutdown. I understood it was a critical component in getting apcupsd to shutdown unRaid cleanly. I didn't know it issued any command to the UPS. The apcupsd manual led me to believe that the command needed to shutdown the UPS was killpower like planetscott mentions in his post. This is what it has to say: This feature is implemented on Unix systems by first requesting a system shutdown. As a part of the shutdown, apcupsd is terminated by the system, but the shutdown process executes a script where apcupsd is recalled after the disks are synced and the machine is idle. Apcupsd then requests the UPS to shut off the power (killpower). In any event what I would like is for the UPS power to be shutoff shortly after the "master" server shuts down. The reason being that although I have apcupsd configured to shutdown the server with only 5 minutes of run time left on the battery, once the server is shut down the remaining time jumps up to ~40 minutes. If the UPS waits until the batteries are almost depleted before powering down, that means there is a period of ~40 minutes where the power could be restored and the servers will not power back up automatically. The UPS remaining powered on for that time does me no good and as I showed above, actually has the potential to be a negative.
October 8, 200817 yr True, it is apcupsd that sends the killpower command to the UPS. The UPS does that based on a timer, not at remaining battery capacity as far as I know. My UPS shut down shortly after the server itself shut down... Apcupsd has to send the command to the UPS before the server powers itself down... there is nothing there to send it afterwards. The UPS itself delays shutting itself down to give the powerdown command time to work to shut down the server cleanly.
October 8, 200817 yr I'll check again when I get home, but I'm pretty sure I waited ~10 minutes after my server shutdown and the UPS hadn't shutdown.
October 8, 200817 yr Tonight I add 3 more 1 tb drives and fill up the slots... thank God... my credit card is limp It's been a while since I've looked into this, but I do remember needing a command to be sent to the UPS that told it to turn off.
October 9, 200817 yr I just tested it and I waited 15 minutes after the server shutdown and the UPS was still running. It may shutdown at some point when the battery gets lower, but like I said, that is less than ideal. This is the code the planetscott used (and I've also seen mentioned in the manual) in his /etc/rc.d/rc.0: if [ -f /etc/apcupsd/powerfail ]; then # ***apcupsd*** echo # ***apcupsd*** echo "APCUPSD will now power off the UPS" # ***apcupsd*** echo # ***apcupsd*** /etc/apcupsd/apccontrol killpower # ***apcupsd*** echo # ***apcupsd*** echo "Please ensure that the UPS has powered off before rebooting" # ***apcupsd*** echo "Otherwise, the UPS may cut the power during the reboot!!!" # ***apcupsd*** echo # ***apcupsd*** fi I assume this is where he was saying he put it. Should I replace all of this or only part of it? And being that I can't copy this file to another location how do I make sure this gets replaced on every boot? if [ -x /sbin/genpowerd ]; then # See if this is a powerfail situation: if /bin/egrep -q "FAIL|SCRAM" /etc/upsstatus 2> /dev/null ; then # Signal UPS to shut off the inverter: /sbin/genpowerd -k if [ ! $? = 0 ]; then echo echo "There was an error signaling the UPS." echo "Perhaps you need to edit /etc/genpowerd.conf to configure" echo "the serial line and UPS type." # Wasting 15 seconds of precious power: /bin/sleep 10 fi fi fi Will that power down the UPS right after the server goes down? Will it only power down the UPS on a shutdown do to power failure and not a shutdown or reboot I initiate under normal circumstances? If so, how do you
October 9, 200817 yr I just tested it and I waited 15 minutes after the server shutdown and the UPS was still running. It may shutdown at some point when the battery gets lower, but like I said, that is less than ideal. This is the code the planetscott used (and I've also seen mentioned in the manual) in his /etc/rc.d/rc.0: if [ -f /etc/apcupsd/powerfail ]; then # ***apcupsd*** echo # ***apcupsd*** echo "APCUPSD will now power off the UPS" # ***apcupsd*** echo # ***apcupsd*** /etc/apcupsd/apccontrol killpower # ***apcupsd*** echo # ***apcupsd*** echo "Please ensure that the UPS has powered off before rebooting" # ***apcupsd*** echo "Otherwise, the UPS may cut the power during the reboot!!!" # ***apcupsd*** echo # ***apcupsd*** fi I assume this is where he was saying he put it. Should I replace all of this or only part of it? And being that I can't copy this file to another location how do I make sure this gets replaced on every boot? if [ -x /sbin/genpowerd ]; then # See if this is a powerfail situation: if /bin/egrep -q "FAIL|SCRAM" /etc/upsstatus 2> /dev/null ; then # Signal UPS to shut off the inverter: /sbin/genpowerd -k if [ ! $? = 0 ]; then echo echo "There was an error signaling the UPS." echo "Perhaps you need to edit /etc/genpowerd.conf to configure" echo "the serial line and UPS type." # Wasting 15 seconds of precious power: /bin/sleep 10 fi fi fi Will that power down the UPS right after the server goes down? Will it only power down the UPS on a shutdown do to power failure and not a shutdown or reboot I initiate under normal circumstances? If so, how do you I could have sworn it would do it by itself, but I don't see the code anywhere... perhaps I was just fooled into thinking it shut down programaticaly rather than when it ran the battery down. I ended up adding one line (below, in blue) to the script of commands used to install the apcupsd package, configure it, and invoke it. A script with the following commands are invoked from my "go" file. [pre] #! /bin/bash # Install APC UPS driver module cd /boot/packages installpkg apcupsd-3.14.3-i486-1kjz.tgz sed -i -e "s/^DEVICE \/dev\/ttyS0/#DEVICE \/dev\/ttyS0/" /etc/apcupsd/apcupsd.conf sed -i -e "s/WALL=wall/WALL=\"mail -s 'unRAID_Server_UPS_Alert'\"/" /etc/apcupsd/apccontrol /sbin/apcupsd #Now, put into place the shutdown script replacement echo "/sbin/powerdown" >/etc/apcupsd/doshutdown echo "exit 99" >>/etc/apcupsd/doshutdown chmod 755 /etc/apcupsd/doshutdown sed -i -e "/\/sbin\/poweroff/i[ -f \/etc\/apcupsd\/powerfail ] \&\& \/etc\/apcupsd\/apccontrol killpower" /etc/rc.d/rc.6 [/pre] The added line (in blue) edits the rc.6 file (which is linked to the rc.0 file. they are the same file) The edited line in rc.6 adds the call to apccontrol before it invokes poweroff. Joe L. Edit: corrected line to kill UPS power on shutdown only when /etc/apcupsd/powerfail "flag" file exists
October 9, 200817 yr Will that line only shutdown the UPS in a powerfail event and not because I chose to shutdown the server? That makes me wonder... If the UPS is still getting power from the wall and you turn off the power button on it, does it still pass power to your peripherals?
October 10, 200817 yr Will that line only shutdown the UPS in a powerfail event and not because I chose to shutdown the server? That makes me wonder... If the UPS is still getting power from the wall and you turn off the power button on it, does it still pass power to your peripherals? You are correct, it would have shut the UPS down. Reading further, I now see how to fix that. In apcupsd.conf is this: # PWRFAILDIR <path to powerfail directory> # Directory in which to write the powerfail flag file. This file # is created when apcupsd initiates a system shutdown and is # checked in the OS halt scripts to determine if a killpower # (turning off UPS output power) is required. PWRFAILDIR /etc/apcupsd So... we only want to shutdown the UPS if that "flag" file exists. The correct line to add to the script would then be (put this all on one line): [pre]sed -i -e "/\/sbin\/poweroff/i[ -f \/etc\/apcupsd\/powerfail ] \&\& \/etc\/apcupsd\/apccontrol killpower" /etc/rc.d/rc.6 [/pre] Thanks for thinking of that possibility... This would have done it even if power was normal sed -i -e "s/\/sbin\/poweroff/\/etc\/apcupsd\/apccontrol killpower; \/sbin\/poweroff/" /etc/rc.d/rc.6 Joe L.
October 11, 200817 yr Hi all, I do connect my old UPS APC Back-UPS 500 with UnRaid server. I do connect UPS with UnRaid server through USB cable and I have same problems as member RockDown (http://lime-technology.com/forum/index.php?topic=1528.msg20233#msg20233). But I am do procedure by Joe L. http://lime-technology.com/forum/index.php?topic=1528.msg18315#msg18315 and now UPS with UnRaid server is work! I see status of UPS in UnRaid menu - System Info -> UPS status. Nice But how I can check if mail notifikation is work (loss power, critical status power of batt, e.g.)? Very thanks guys.
October 11, 200817 yr Hi all, I do connect my old UPS APC Back-UPS 500 with UnRaid server. I do connect UPS with UnRaid server through USB cable and I have same problems as member RockDown (http://lime-technology.com/forum/index.php?topic=1528.msg20233#msg20233). But I am do procedure by Joe L. http://lime-technology.com/forum/index.php?topic=1528.msg18315#msg18315 and now UPS with UnRaid server is work! I see status of UPS in UnRaid menu - System Info -> UPS status. Nice But how I can check if mail notifikation is work (loss power, critical status power of batt, e.g.)? Very thanks guys. It is pretty easy actually... Unplug the USB cord. If it is all working, an e-mail will be sent stating communications has been lost with the UPS. Plug the USB cord back in, a second message should appear stating communications is restored. Or, more work, but will test everything. Stop the unRAUD server Power down. Temporarily plug the server directly into the wall outlet, bypassing the UPS, but leave the UPS plugged into the wall outlet too. Plug a table lamp into the UPS to act as a load in place of the server. Power up the server. Stop the unRAID array. (Just in case the server shuts down without attempting to stop the array first, you will already be stopped, therefore you will not be forced to do a full parity check upon reboot) Now, unplug the UPS from the wall. It should now be powering the lamp you added as a load. A message will be added to the syslog stating it is on battery power (the server does not know it is directly plugged into the wall, don't tell it ) Let the UPS run until its batteries signal it is time to shut down. (this might take longer, as the lamp may not draw as much as the server) Watch the shut-down process. It should stop the array, shut the server down, and then, assuming you added the last "sed" line I described a post or so ago, shut down the UPS. (the lamp should go out soon after the server powers off) Then, unplug the server from the wall outlet, plug it back into the UPS. (unplug the lamp you used as a temporary load) Plug the UPS back into the wall outlet. It should start back up, the server should power up, and you will have tested most of everything. Now.. in a real power outage you might not get an e-mail alert since your router and cable-modem/DSL-modem might not have power to let it send mail through them. Joe L.
October 11, 200817 yr That line did the trick. My UPS now shuts off shorlty after the last server shuts down. Thanks a ton! One last question... I feel like this must be a dumb question with a simple answer since others appear to have this working, but I really have looked and I can't seem to figure out where you specify a TO: address for the email notifications. I configured the three settings at the beginning of the mail script, but none of them specifies the recipient. I have Joe L.'s smtp_check_unraid script installed and working, but this one doesn't and I know it's because I didn't tell it where to send the emails. What am I overlooking?
October 11, 200817 yr That line did the trick. My UPS now shuts off shorlty after the last server shuts down. Thanks a ton! One last question... I feel like this must be a dumb question with a simple answer since others appear to have this working, but I really have looked and I can't seem to figure out where you specify a TO: address for the email notifications. I configured the three settings at the beginning of the mail script, but none of them specifies the recipient. I have Joe L.'s smtp_check_unraid script installed and working, but this one doesn't and I know it's because I didn't tell it where to send the emails. What am I overlooking? Oops... you need one more line in your "go" script Something like this: echo "[email protected]" >/root/.forward Sorry, I had it as a separate task as I needed it for my normal e-mail status check. I had forgotten all about it. Obviously, change the e-mail address to your own. Joe L.
October 11, 200817 yr You also need this "mail" command installed as described in this post http://lime-technology.com/forum/index.php?topic=1528.msg16717#msg16717 unzip to the /boot/custom/bin folder, Edit it to set your mail server, and then copy to /usr/bin/mail using commands like this (also in your "go" script) cp /boot/custom/bin/mail.sh /usr/bin/mail chmod 755 /usr/bin/mail Joe L.
October 11, 200817 yr Hi all, I do connect my old UPS APC Back-UPS 500 with UnRaid server. I do connect UPS with UnRaid server through USB cable and I have same problems as member RockDown (http://lime-technology.com/forum/index.php?topic=1528.msg20233#msg20233). But I am do procedure by Joe L. http://lime-technology.com/forum/index.php?topic=1528.msg18315#msg18315 and now UPS with UnRaid server is work! I see status of UPS in UnRaid menu - System Info -> UPS status. Nice But how I can check if mail notifikation is work (loss power, critical status power of batt, e.g.)? Very thanks guys. It is pretty easy actually... Unplug the USB cord. If it is all working, an e-mail will be sent stating communications has been lost with the UPS. Plug the USB cord back in, a second message should appear stating communications is restored. Or, more work, but will test everything. Stop the unRAUD server Power down. Temporarily plug the server directly into the wall outlet, bypassing the UPS, but leave the UPS plugged into the wall outlet too. Plug a table lamp into the UPS to act as a load in place of the server. Power up the server. Stop the unRAID array. (Just in case the server shuts down without attempting to stop the array first, you will already be stopped, therefore you will not be forced to do a full parity check upon reboot) Now, unplug the UPS from the wall. It should now be powering the lamp you added as a load. A message will be added to the syslog stating it is on battery power (the server does not know it is directly plugged into the wall, don't tell it ) Let the UPS run until its batteries signal it is time to shut down. (this might take longer, as the lamp may not draw as much as the server) Watch the shut-down process. It should stop the array, shut the server down, and then, assuming you added the last "sed" line I described a post or so ago, shut down the UPS. (the lamp should go out soon after the server powers off) Then, unplug the server from the wall outlet, plug it back into the UPS. (unplug the lamp you used as a temporary load) Plug the UPS back into the wall outlet. It should start back up, the server should power up, and you will have tested most of everything. Now.. in a real power outage you might not get an e-mail alert since your router and cable-modem/DSL-modem might not have power to let it send mail through them. Joe L. After loss power of UPS then UnRaid server log this event to syslog Oct 11 21:18:40 Tower apcupsd[2711]: Power failure. Oct 11 21:18:46 Tower apcupsd[2711]: Running on UPS batteries. Oct 11 21:18:51 Tower apcupsd[2711]: Mains returned. No longer on UPS batteries. Oct 11 21:18:51 Tower apcupsd[2711]: Power is back. UPS running on mains. and I add this code to "go" script and reboot echo "[email protected]" > /root/.forward I install "mail" script too. But e-mail not send. Thanks for any other ideas?
October 12, 200817 yr Oops... you need one more line in your "go" script Something like this: echo "[email protected]" >/root/.forward I should have known there was an easier way...I had gone into a number of files under /etc/apcupsd/ and changed the SYSADMIN variable to my own email address.
October 16, 200817 yr This UPS project has kicked my butt! I made the changes as Joe showed, but I still don't receive any emails concerning UPS events. Here is my go file: #!/bin/bash # Start the Management Utility /usr/local/sbin/emhttp & sleep 30 for i in /dev/md* do blockdev --setra 2048 $i done echo "[email protected]" >/root/.forward /boot/monthly_parity_check.sh CTRLALTDEL=yes installpkg /boot/powerdown-1.01-noarch-unRAID.tgz /boot/S120-apcupsd-package-install.sh nohup sh -c "while true; do awk -W re-interval -f /boot/unmenu.awk; done" >/dev/null 2>&1 & cp /boot/mail.sh /usr/bin/mail chmod 755 /usr/bin/mail Here is my S120-apcupsd-package-install.sh script: #! /bin/bash # Install APC UPS driver module cd /boot/packages installpkg apcupsd-3.14.3-i486-1kjz.tgz cp /boot/apcupsd.conf /etc/apcupsd/ sed -i -e "s/WALL=wall/WALL=\"mail -s 'unRAID_Server_UPS_Alert'\"/" /etc/apcupsd/apccontrol /sbin/apcupsd #Now, put into place the shutdown script replacement echo "/sbin/powerdown" >/etc/apcupsd/doshutdown echo "exit 99" >>/etc/apcupsd/doshutdown chmod 755 /etc/apcupsd/doshutdown sed -i -e "/\/sbin\/poweroff/i[ -f \/etc\/apcupsd\/powerfail ] \&\& \/etc\/apcupsd\/apccontrol killpower" /etc/rc.d/rc.6 I have mail.sh in /boot/ and this is how it is configured: # The name of your SMTP server sSmtpServer="smtp-server.neo.rr.com" # Your domain name sDomain="www.neo.rr.com" # The "from" email address sMailFrom="[email protected]" After my go file is run I ended up with /root/.forward and it indeed contained my "to:' email address. What am I missing?
October 16, 200817 yr if someone would bundle this all up or provide a set of defintive links to its components I will host this.
October 16, 200817 yr This UPS project has kicked my butt! I made the changes as Joe showed, but I still don't receive any emails concerning UPS events. Here is my go file: #!/bin/bash # Start the Management Utility /usr/local/sbin/emhttp & sleep 30 for i in /dev/md* do blockdev --setra 2048 $i done echo "[email protected]" >/root/.forward /boot/monthly_parity_check.sh CTRLALTDEL=yes installpkg /boot/powerdown-1.01-noarch-unRAID.tgz /boot/S120-apcupsd-package-install.sh nohup sh -c "while true; do awk -W re-interval -f /boot/unmenu.awk; done" >/dev/null 2>&1 & cp /boot/mail.sh /usr/bin/mail chmod 755 /usr/bin/mail Here is my S120-apcupsd-package-install.sh script: #! /bin/bash # Install APC UPS driver module cd /boot/packages installpkg apcupsd-3.14.3-i486-1kjz.tgz cp /boot/apcupsd.conf /etc/apcupsd/ sed -i -e "s/WALL=wall/WALL=\"mail -s 'unRAID_Server_UPS_Alert'\"/" /etc/apcupsd/apccontrol /sbin/apcupsd #Now, put into place the shutdown script replacement echo "/sbin/powerdown" >/etc/apcupsd/doshutdown echo "exit 99" >>/etc/apcupsd/doshutdown chmod 755 /etc/apcupsd/doshutdown sed -i -e "/\/sbin\/poweroff/i[ -f \/etc\/apcupsd\/powerfail ] \&\& \/etc\/apcupsd\/apccontrol killpower" /etc/rc.d/rc.6 I have mail.sh in /boot/ and this is how it is configured: # The name of your SMTP server sSmtpServer="smtp-server.neo.rr.com" # Your domain name sDomain="www.neo.rr.com" # The "from" email address sMailFrom="[email protected]" After my go file is run I ended up with /root/.forward and it indeed contained my "to:' email address. What am I missing? Your issuse is probably the setup of your mail command, and has nothing to do with the UPS software. Login to your server and type: echo "testing" | sh -xv /usr/bin/mail root -s "unRAID Test Message" 2>&1 | tee /tmp/mail_test.txt Lots of lines will scroll to the screen, but copies will also be saved in /tmp/mail_test.txt Post the results (after editing your personal e-mail info from it) Once things are working you can type echo "your test message" | mail root -s "Subject line goes here" and the message should be sent. Joe L.
October 18, 200817 yr Here's the contents of mail_test.txt: # mail replacement. This script can be used to send # mail through an smtp server by use of the netcat command. # It will NOT work if your smtp server is expecting a login/password exchange # # Define the following three values to setup this script # The name of your SMTP server sSmtpServer="smtp-server.neo.rr.com" + sSmtpServer=smtp-server.neo.rr.com # Your domain name sDomain="www.neo.rr.com" + sDomain=www.neo.rr.com # The "from" email address sMailFrom="[email protected]" + [email protected] #------------------------------------------------------- # no changes should be needed below this line #------------------------------------------------------- # default subject is none is given on the command line subject="message from unRAID server" + subject='message from unRAID server' addressee="" + addressee= # process the arguments if [ $# = 0 ] then echo "Usage: mail [-s 'subject'] address [address] ..." exit 2 fi + '[' 3 = 0 ']' set -- "$@" + set -- root -s 'unRAID Test Message' while true do if [ "$#" = 0 ] then break fi case "$1" in -s) shift subject="$1" ;; *) addressee="$addressee $1" ;; esac shift done + true + '[' 3 = 0 ']' + case "$1" in + addressee=' root' + shift + true + '[' 2 = 0 ']' + case "$1" in + shift + subject='unRAID Test Message' + shift + true + '[' 0 = 0 ']' + break #echo "subject=" $subject if [ "$addressee" = "" ] then echo "No addressee given." echo "Usage: mail -s 'subject' address [address]" exit 2 fi + '[' ' root' = '' ']' # look up the ip address given the machine name ip_addr=`net lookup $sSmtpServer 2>/dev/null` net lookup $sSmtpServer 2>/dev/null ++ net lookup smtp-server.neo.rr.com + ip_addr=75.180.132.33 if [ $? = 0 ] then # Build the echo string sEcho="ehlo $sDomain\r\nmail from:$sMailFrom\r\n" # Add each recipient to the RCPT list for i in $addressee do sEcho+="RCPT TO:"$i"\r\n" done # Message header sEcho+="data\r\nFrom:$sMailFrom\r\nTo:" # Add each recipient to the message header for i in $addressee do sEcho+=$i";" done sEcho+="\r\n" # Message Subject sEcho+="Subject:$subject\r\n\r\n" sEcho+=`sed "s/$/\\r\\n/"` # this reads from stdin for the message body # End the message sEcho+="\r\n.\r\n" sEcho+="QUIT\r\n" # Send the message we just built echo -e $sEcho|nc -i 1 -q 1 $ip_addr 25 # Use the following line for debug #echo -e $sEcho|nc -w 1 -q 2 -i 1 -vv $ip_addr 25 else echo "unable to determine IP address of $sSmtpServer" 1>&2 exit 2 fi + '[' 0 = 0 ']' + sEcho='ehlo www.neo.rr.com\r\nmail from:[email protected]\r\n' + for i in '$addressee' + sEcho+='RCPT TO:root\r\n' + sEcho+='data\r\nFrom:[email protected]\r\nTo:' + for i in '$addressee' + sEcho+='root;' + sEcho+='\r\n' + sEcho+='Subject:unRAID Test Message\r\n\r\n' sed "s/$/\r\n/" ++ sed 's/$/\r\n/' + sEcho+=$'testing\r' + sEcho+='\r\n.\r\n' + sEcho+='QUIT\r\n' + echo -e ehlo 'www.neo.rr.com\r\nmail' 'from:[email protected]\r\nRCPT' 'TO:root\r\ndata\r\nFrom:[email protected]\r\nTo:root;\r\nSubject:unRAID' Test 'Message\r\n\r\ntesting \r\n.\r\nQUIT\r\n' + nc -i 1 -q 1 75.180.132.33 25 /usr/bin/mail: line 90: nc: command not found I noticed that if I cd /boot then run the mail_test, it seems to work, but I never get an email and one of the last few lines says "250 Recipient <root> Ok". I did add the line "echo "[email protected]" >/root/.forward" to my go file like you said.
October 19, 200817 yr Here's the contents of mail_test.txt: # mail replacement. This script can be used to send # mail through an smtp server by use of the netcat command. # It will NOT work if your smtp server is expecting a login/password exchange # # Define the following three values to setup this script # The name of your SMTP server sSmtpServer="smtp-server.neo.rr.com" + sSmtpServer=smtp-server.neo.rr.com # Your domain name sDomain="www.neo.rr.com" + sDomain=www.neo.rr.com # The "from" email address sMailFrom="[email protected]" + [email protected] #------------------------------------------------------- # no changes should be needed below this line #------------------------------------------------------- # default subject is none is given on the command line subject="message from unRAID server" + subject='message from unRAID server' addressee="" + addressee= # process the arguments if [ $# = 0 ] then echo "Usage: mail [-s 'subject'] address [address] ..." exit 2 fi + '[' 3 = 0 ']' set -- "$@" + set -- root -s 'unRAID Test Message' while true do if [ "$#" = 0 ] then break fi case "$1" in -s) shift subject="$1" ;; *) addressee="$addressee $1" ;; esac shift done + true + '[' 3 = 0 ']' + case "$1" in + addressee=' root' + shift + true + '[' 2 = 0 ']' + case "$1" in + shift + subject='unRAID Test Message' + shift + true + '[' 0 = 0 ']' + break #echo "subject=" $subject if [ "$addressee" = "" ] then echo "No addressee given." echo "Usage: mail -s 'subject' address [address]" exit 2 fi + '[' ' root' = '' ']' # look up the ip address given the machine name ip_addr=`net lookup $sSmtpServer 2>/dev/null` net lookup $sSmtpServer 2>/dev/null ++ net lookup smtp-server.neo.rr.com + ip_addr=75.180.132.33 if [ $? = 0 ] then # Build the echo string sEcho="ehlo $sDomain\r\nmail from:$sMailFrom\r\n" # Add each recipient to the RCPT list for i in $addressee do sEcho+="RCPT TO:"$i"\r\n" done # Message header sEcho+="data\r\nFrom:$sMailFrom\r\nTo:" # Add each recipient to the message header for i in $addressee do sEcho+=$i";" done sEcho+="\r\n" # Message Subject sEcho+="Subject:$subject\r\n\r\n" sEcho+=`sed "s/$/\\r\\n/"` # this reads from stdin for the message body # End the message sEcho+="\r\n.\r\n" sEcho+="QUIT\r\n" # Send the message we just built echo -e $sEcho|nc -i 1 -q 1 $ip_addr 25 # Use the following line for debug #echo -e $sEcho|nc -w 1 -q 2 -i 1 -vv $ip_addr 25 else echo "unable to determine IP address of $sSmtpServer" 1>&2 exit 2 fi + '[' 0 = 0 ']' + sEcho='ehlo www.neo.rr.com\r\nmail from:[email protected]\r\n' + for i in '$addressee' + sEcho+='RCPT TO:root\r\n' + sEcho+='data\r\nFrom:[email protected]\r\nTo:' + for i in '$addressee' + sEcho+='root;' + sEcho+='\r\n' + sEcho+='Subject:unRAID Test Message\r\n\r\n' sed "s/$/\r\n/" ++ sed 's/$/\r\n/' + sEcho+=$'testing\r' + sEcho+='\r\n.\r\n' + sEcho+='QUIT\r\n' + echo -e ehlo 'www.neo.rr.com\r\nmail' 'from:[email protected]\r\nRCPT' 'TO:root\r\ndata\r\nFrom:[email protected]\r\nTo:root;\r\nSubject:unRAID' Test 'Message\r\n\r\ntesting \r\n.\r\nQUIT\r\n' + nc -i 1 -q 1 75.180.132.33 25 /usr/bin/mail: line 90: nc: command not found I noticed that if I cd /boot then run the mail_test, it seems to work, but I never get an email and one of the last few lines says "250 Recipient <root> Ok". I did add the line "echo "[email protected]" >/root/.forward" to my go file like you said. I now see the problem... actually several problems. First, the script you are using does not use the .forward file. (I've updated the attachment you downloaded to have a version that does) Second, your script does not set the PATH environment variable (the updated does) that is why it almost worked when you cd'd to the /boot folder... that is probably where you have a copy of "nc" (netcat) Just in case you do not have a copy of "nc" it is also in the updated attached zip file. You should put "nc" either in /boot/nc, or in /boot/custom/bin/nc Please accept my apology, the version of mail.sh posted earlier in this thread did not use the .forward file... therefore the mail was basically being sent to "root" It worked otherwise, but only if you set the PATH environment variable or copied "nc" to be in your path. I've updated that original post to have the updated attachment of mail.zip. You can find it here: http://lime-technology.com/forum/index.php?topic=1528.msg16717#msg16717 You will have to re-edit the three lines at the top of mail.sh again, to set them to your server, etc. Joe L.
Archived
This topic is now archived and is closed to further replies.