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
April 12

Linux: SCP tricks

Quite a handy thing about scp is that it supports asterisks. You can copy all files in a remote directory in a way like this:

scp yourusername@yourserver:/home/yourusername/* .

And you can also just copy a whole directory by specifying the -r (recursive) option:

scp -r yourusername@yourserver:/home/yourusername/ .

Both of these also work when copying to a (remote) server or copying between a (remote) server and another (remote) server.

You can also limit the bandwidth scp may use when copying. This is very useful if you’re wanting to copy a huge amount of data without suffering from slow internet for a long time. Limiting bandwidth is done this way:

scp -l bandwidthlimit yourusername@yourserver:/home/yourusername/* .

The bandwidth is specified in Kbit/sec. What does this mean? Eight bits is one byte. If you want to copy no faster than 10 Kbyte/sec, set the limit to 80. If you want to copy no faster than 80 Kbyte/sec, set the limit to 640. Get it? You should set the limit to eight times the maximum Kbyte/sec you want it to be. I’d recommend to set the -l option with all scp’ing you do on a connection that other people need to use, too. A big amount of copying can virtually block a whole 10 Mbit network if you’re using hubs.

By: rechosen

Category: Linux | Comments Off on Linux: SCP tricks