May 23

Linux: Running available updates on multiple servers and emailing the results

The following script runs the available updates on the server it is executing from along with multiple servers. It collects the data into a single file and then emails the information.
Although this script uses yum, you should be able to do the same thing with apt-get.
Prerequisite: Sendmail

*Note the dos2unix command. If you do not add this, Sendmail will send your file as a .dat attachment rather than adding your file contents to the body of your message.

vi runup.sh
echo “Centos Software Update Results” > rrslt.txt
echo -e “n” >> rrslt.txt
echo “SRV1” >> rrslt.txt
yum update -y >> rrslt.txt
echo -e “n” >> rrslt.txt
echo “SRV2” >> rrslt.txt
ssh root@SRV2 -t ‘yum update -y’ >> rrslt.txt
echo -e “n” >> rrslt.txt
echo “SRV3” >> rrslt.txt
ssh root@SRV3 -t ‘yum update -y’ >> rrslt.txt
echo -e “n” >> rrslt.txt
echo “SRV4” >> rrslt.txt
ssh root@SRV4 -t ‘yum update -y’ >> rrslt.txt
sed “/Loaded plugins:/d” rrslt.txt > tmp2 ; mv tmp2 rrslt.txt
sed “/Loading mirror/d” rrslt.txt > tmp2 ; mv tmp2 rrslt.txt
sed “/* base:/d” rrslt.txt > tmp2 ; mv tmp2 rrslt.txt
sed “/* extras:/d” rrslt.txt > tmp2 ; mv tmp2 rrslt.txt
sed “/* updates:/d” rrslt.txt > tmp2 ; mv tmp2 rrslt.txt
sed “/Setting up Update Process/d” rrslt.txt > tmp2 ; mv tmp2 rrslt.txt
dos2unix rrslt.txt
mail -s ‘Centos Server Update Results’ [email protected] < rrslt.txt

Category: Linux | Comments Off on Linux: Running available updates on multiple servers and emailing the results
May 16

Linux: Checking for updates on multiple servers and emailing the results

The following script checks for updates on the server it is executing from along with multiple servers. It collects the data into a single file and then emails the information.
Although this script uses yum, you should be able to do the same thing with apt-get.
Prerequisite: Sendmail

*Note the dos2unix command.  If you do not add this, Sendmail will send your file as a .dat attachment rather than adding your file contents to the body of your message.

vi chkup.sh
echo “Available Centos Server Updates:” > crslt.txt
echo -e “n” >> crslt.txt
echo “SRV01” >> crslt.txt
yum check-update >> crslt.txt
echo -e “n” >> crslt.txt
echo “SVR02” >> crslt.txt
ssh root@svr02 ‘yum check-update’ >> crslt.txt
echo -e “n” >> crslt.txt
echo “SVR03” >> crslt.txt
ssh root@svr03 ‘yum check-update’ >> crslt.txt
echo -e “n” >> crslt.txt
echo “SVR04” >> crslt.txt
ssh root@svr04 ‘yum check-update’ >> crslt.txt
sed “/Loaded plugins:/d” crslt.txt > tmp ; mv tmp crslt.txt
sed “/Loading mirror/d” crslt.txt > tmp ; mv tmp crslt.txt
sed “/* base:/d” crslt.txt > tmp ; mv tmp crslt.txt
sed “/* extras:/d” crslt.txt > tmp ; mv tmp crslt.txt
sed “/* updates:/d” crslt.txt > tmp ; mv tmp crslt.txt
dos2unix crslt.txt
mail -s ‘Daily Centos Server Update Report’ [email protected] < crslt.txt

Then add this to a cron job
The following example will run every Monday through Friday (1-5) at 6 a.m.:
crontab -e
0 6 * * 1-5 /root/scripts/chkup.sh #CENTOS update checking of multiple servers

Category: Linux | Comments Off on Linux: Checking for updates on multiple servers and emailing the results
May 15

Linux: Using sendmail from console

To send an email from console you need to use mail command, which is an intelligent mail processing system which has a command syntax reminiscent of ed with lines replaced by messages. To send an email to [email protected] you need to type following command:

$ mail [email protected]:

Subject: Hello
Hai,
How are you? Hope so you are fine 🙂
Take care
Babai
Vivek
. <Type DOT (.) followed by ENTER KEY>
Cc: <Press ENTER KEY>

You need to type . (dot) to send an email. To send contains of file (such as /tmp/message) as mail body then use following command:
$ mail -s ‘Hai’ [email protected] < /tmp/messagePlease note that above command will NOT route an email if you do not have properly configured MTA/mail server.

By Vivek Gite

Category: Linux | Comments Off on Linux: Using sendmail from console
May 10

Linux: Red Hat – Change Ethernet name – Remove old ethernet devices

When running a linux system in a virtual environment the ethernet card may be assigned a new MAC address  when cloning or changing VLANS.
When this happens the ether net increments by one.  Eg. eth0, eth1, eth2

If you are experiencing this you can manually change your eth name by doing the following:

1. Type: ifconfig – and note the  MAC address of your ethernet card

2. vi /etc/udev/rules.d/70-persistent-net.rules

3.  Look for the lines that start with: SUBSYSTEM==”net”   – Check to see if your MAC address matches

4. You can safely remove any line that does not have a matching MAC address.

5. After removing these you should be left with a single line that includes your MAC address.  At the end of this line change NAME=”eth?” to NAME=”eth0″

Save your file and reboot.

Category: Linux | Comments Off on Linux: Red Hat – Change Ethernet name – Remove old ethernet devices
April 26

Linux: Sendmail setup and forwarding root email to an external server

1. yum install sendmail

2. yum install sendmail-cf

3. nano sendmail.mc
Add smart host
define(`SMART_HOST’, `[your.smtpserver.com]’)dnl
*Make certain your smtp server is set to allow connections from your ip*

If you want your sendmail to accept remote connections add dnl:
dnl DAEMON_OPTIONS(`Port=smtp,Addr=127.0.0.1, Name=MTA’)dnl

4. ./make sendmail.cf

5. service sendmail restart

6. nano /etc/aliases
root: [email protected]

7. newaliases

8. nano /etc/hosts
127.0.0.1 servername.domain.com localhost servername
::1 localhost6.localdomain6 localhost6
172.22.2.122 mailhost smtpmailserver.yourserver.com

9. echo “This is a test” | mailx -s “A test mail” root < /dev/null

To test is you are accepting SMTP traffic
telnet yourservername 25

HELO yourservername Like I am 🙂

MAIL FROM:root@yourservername My address

RCPT TO:therename@yourservername Your address

DATA

text message for therename. This is text message

Category: Linux | Comments Off on Linux: Sendmail setup and forwarding root email to an external server