Go Back   HowtoForge Forums | HowtoForge - Linux Howtos and Tutorials > Linux Forums > Server Operation

Do you like HowtoForge? Please consider supporting us by becoming a subscriber.
Reply
 
Thread Tools Display Modes
  #1  
Old 26th October 2013, 16:28
danhansen@denmark danhansen@denmark is offline
Senior Member
 
Join Date: Mar 2013
Posts: 249
Thanks: 53
Thanked 4 Times in 4 Posts
Question sendmail and shell script --> path to?

Hello


I'm running an Ubuntu Server 12.04.2 - just a basic installation. No Apache, No PHP or anything. I'm doing a shell script and this script needs to send a mail.
My port 25 IS open of course. To have the script send a mail on the Ubuntu Server 12.04.2 I need to define a path for the mail client. Here's a part of the script:

echo '============================'
echo '= CPU Temp. i$ degrees ='
echo '============================'
/sbin/shutdown -h now
/usr/sbin/ssmtp me@myemail.com </home/xxx/MyScripts/hotcpu.txt
echo 'Email Sent.....'
exit

1. Is "sendmail" the default mail client in Ubuntu Server 12.04?

2. I need the right path to put into my script.

3. Will I need to protect the server against spammers? Server is in network where router uses Fixed IP, LAN/NAT and server is running UFW
__________________
Kind Regards
Dan

__________________________________________________ _______
Fixed IP/WAN
DMZ -> "ispserverip"
Primary NameServer -> ns1.myprimarynameserver.tld
Secondary NameServer -> ns2.somedomainservice.tld

Ubuntu Server 12.04.4
ISPconfig 3 v.3.0.5.2 (Single Server Setup)
NameServer: BIND v.9.8.1-P1
SquirrelMail: v.1.4.22
MailServer: PostFix v.2.9.6 - IMAP/POP3 Dovecot v.2.0.19
Database: MySQL Server v.5.5.29-0ubuntu0.12.04.2
Tutorial: "ThePerfectServer-ISPconfig3-Ubuntu12.04"
Reply With Quote
Sponsored Links
  #2  
Old 26th October 2013, 22:44
florian030 florian030 is offline
Senior Member
 
Join Date: Oct 2012
Posts: 252
Thanks: 8
Thanked 68 Times in 59 Posts
Default

To get the path you can use which XXX

And in your script:

[code]MAIL=`which mail`[code]

afterwards the path is stored in $MAIL

BTW: I would send the mail before shutting down the system.
__________________
regards
Florian

blog.schaal-24.de
Reply With Quote
  #3  
Old 27th October 2013, 02:43
danhansen@denmark danhansen@denmark is offline
Senior Member
 
Join Date: Mar 2013
Posts: 249
Thanks: 53
Thanked 4 Times in 4 Posts
Question sendmail? path to client? protection against spammers?

Hi florian,

Thanks for your reply

1.
Quote:
BTW: I would send the mail before shutting down the system.
In this post: http://forum.havetheknowhow.com/view...0&p=2629#p2629
I asked the same question. The guy who made the first script said:
b. The reason the shutdown command comes before the command to send the email is to ensure the server gets shutdown. I didn't want it staying alive if the email command made the whole script hang. The server does not shut down instantly and so has enough time to run the other lines in the script.
But I agree with you! It needs to be place after the shutdown command - my servers shuts down in less than 2 seconds! And isn't it possible to add a command to force the script to goto a sudden command if something halts it?!?

2.
Quote:
And in your script:
MAIL=`which mail`
afterwards the path is stored in $MAIL
Please define this. I'm not that "Ubuntu" yet

3.
Quote:
To get the path you can use which XXX
I'm not sure what you mean here, I inserted/wrote the X's myself. I write X's in scripts/code's/text's whenever it's a choice. Instead of e.g. /home/MYFOLDERNAME/MyScripts/msg.txt.
It's this path I need to know/change: /usr/sbin/ssmtp to a program in Ubuntu Server 12.04 which will send the txt file/msg. And I think I read somewhere that "sendmail" is a default mail-client in Ubuntu and the program I need to send my txt.file from the server.

4.
Will I need to protect the server against spammers?

Here the's whole script before I edited it - I changed it so that you get a warning if it gets hot and shutsdown if it gets too hot!
Code:
#!/bin/bash

# PURPOSE: Script to check temperature of CPU cores and report/shutdown if specified temperatures exceeded
#
# AUTHOR: feedback[AT]HaveTheKnowHow[DOT]com

# Expects two arguments:
#    1. Warning temperature
#    2. Critical shutdown temperature
#    eg. using ./CPUTempShutdown.sh 30 40
#        will warn when temperature of one or more cores hit 30degrees and shutdown when either hits 40degrees.

# NOTES:
# Change the strings ">>/home/htkh" as required
# Substitute string "myemail@myaddress.com" with your own email address in the string which starts "/usr/sbin/ssmtp myemail@myaddress.com"

# Assumes output from sensors command is as follows:
#
# coretemp-isa-0000
# Adapter: ISA adapter
# Core 0:      +35.0 C  (high = +78.0 C, crit = +100.0 C)  
#
# coretemp-isa-0001
# Adapter: ISA adapter
# Core 1:      +35.0 C  (high = +78.0 C, crit = +100.0 C) 
#
# if not then modify the commands str=$(sensors | grep "Core $i:") & newstr=${str:14:2} below accordingly

echo "JOB RUN AT $(date)"
echo "======================================="

echo ''
echo 'CPU Warning Limit set to => '$1
echo 'CPU Shutdown Limit set to => '$2
echo ''
echo ''

sensors

echo ''
echo ''

for i in 0 1
do

  str=$(sensors | grep "Core $i:")
  newstr=${str:14:2}

  if [ ${newstr} -ge $1 ]
  then
    echo '============================'                             >>/home/htkh/Desktop/CPUWarning.Log
    echo $(date)                                                    >>/home/htkh/Desktop/CPUWarning.Log
    echo ''                                                         >>/home/htkh/Desktop/CPUWarning.Log
    echo ' WARNING: TEMPERATURE CORE' $i 'EXCEEDED' $1 '=>' $newstr >>/home/htkh/Desktop/CPUWarning.Log
    echo ''                                                         >>/home/htkh/Desktop/CPUWarning.Log
    echo '============================'                             >>/home/htkh/Desktop/CPUWarning.Log
  fi
  
  if [ ${newstr} -ge $2 ]
  then
    echo '============================'
    echo ''
    echo 'CRITICAL: TEMPERATURE CORE' $i 'EXCEEDED' $2 '=>' $newstr
    echo ''
    echo '============================'
    /sbin/shutdown -h now
    /usr/sbin/ssmtp myemail@myaddress.com </home/htkh/MyScripts/msg.txt
    echo 'Email Sent.....'
    exit
  else
    echo ' Temperature Core '$i' OK at =>' $newstr
    echo ''
  fi
done

echo 'Both CPU Cores are within limits'
echo ''
__________________
Kind Regards
Dan

__________________________________________________ _______
Fixed IP/WAN
DMZ -> "ispserverip"
Primary NameServer -> ns1.myprimarynameserver.tld
Secondary NameServer -> ns2.somedomainservice.tld

Ubuntu Server 12.04.4
ISPconfig 3 v.3.0.5.2 (Single Server Setup)
NameServer: BIND v.9.8.1-P1
SquirrelMail: v.1.4.22
MailServer: PostFix v.2.9.6 - IMAP/POP3 Dovecot v.2.0.19
Database: MySQL Server v.5.5.29-0ubuntu0.12.04.2
Tutorial: "ThePerfectServer-ISPconfig3-Ubuntu12.04"

Last edited by danhansen@denmark; 27th October 2013 at 03:18.
Reply With Quote
  #4  
Old 27th October 2013, 09:06
florian030 florian030 is offline
Senior Member
 
Join Date: Oct 2012
Posts: 252
Thanks: 8
Thanked 68 Times in 59 Posts
 
Default

Hi Dan,

Quote:
But I agree with you! It needs to be place after the shutdown command - my servers shuts down in less than 2 seconds! And isn't it possible to add a command to force the script to goto a sudden command if something halts it?!?
I would just send the mail before shutting down the system. You may send the mail in the background by adding &bg.

Quote:
Please define this. I'm not that "Ubuntu" yet
I just don“t like hardcoded paths in scripts.
Code:
#!/bin/bash
SSMTP=`which ssmtp`
$SSMTP me@myemail.com </home/xxx/MyScripts/hotcpu.txt
I would use mail / mailx to send local mail from a script.

Quote:
4.
Will I need to protect the server against spammers?
Depends on your setup. You can add some rules to the firewall to limit access to port 25 or setup your MTA to reject unwanted clients.
__________________
regards
Florian

blog.schaal-24.de
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

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 On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
ISPconfig3 - Ubuntu 12.04.2 - ShellScript issues -> LMsensors danhansen@denmark ISPConfig 3 Priority Support 2 7th June 2013 11:10
MyDNS startup problem valter General 9 20th June 2009 18:31


All times are GMT +2. The time now is 14:00.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.