Cool way to run a script on a remote machine

If you have a local script file and want to run the script on another server use the following :

ssh root@torino.maranello.local  ‘bash -s’ < script_local.sh

Enjoy 🙂

Amazon EC2 Docs and locations

To work with command line on the Amazon Cloud you need to get hold of the following file which is the EC2-api-tools look for the latest version here :

I used the file found here.

When trying to setup the Amazon EC2 tools you would expect to have some script that asks you key questions and sets up the environment for you.

Well not quite so.

Starting Point is here : Setting Up the Amazon EC2 Command Line Tools

1)  Install the Java JDK (Java Development Kit) OR  RTE ( Run Time Engine ) found here. For cento select the rpm.

13:30:16-root@controller:~$ yum install jre-7u9-linux-i586.rpm

2)  Test the java installation

13:36:56-root@controller:~$ java -version
java version “1.7.0_09”
Java(TM) SE Runtime Environment (build 1.7.0_09-b05)
Java HotSpot(TM) Client VM (build 23.5-b02, mixed mode, sharing)

3)  Download and unpack the api tools

13:38:39-root@controller:/tmp$ wget “http://s3.amazonaws.com/ec2-downloads/ec2-api-tools.zip”

13:39:49-root@controller:/tmp$ unzip ec2-api-tools.zip

4)  Move it to the user home folder under a new folder e.g. ec2

13:39:52-root@controller:/$ mv /tmp/ec2-api-tools-1.6.4/ ~/ec2/

5) Create a softlink to the new version (used for rewiring later when new versions are installed)

13:39:53-root@controller:/$ ln -s ~/ec2/ec2-api-tools-1.6.4/ ~/ec2/api

Create a shell script with the following environment parameters to tell amazon where the stuff is and who you are:

I add this script to my /etc/profile.d/ec2 since only two users on this machine is me :).

 

 

#!/bin/bash
export JAVA_HOME=/usr
export EC2_HOME=/root/ec2/api
export PATH=$PATH:$EC2_HOME/bin  
export AWS_ACCESS_KEY=XXXXXXXXXXX
export AWS_SECRET_KEY=//XXXXXXXXXXXXXXXXX
export EC2_URL=https://ec2.eu-west-1.amazonaws.com

 

 

Other Documents :

 

 

Adding a XFS filesystem to CentOS 5

Howto use enterprise Linux ‘extras’ to mount a XFS filesystem on a CentOS v5.2 VM

Install RPM’s
Note: Due to this bug (3205), install binutils to overcome the error “xargs: nm: No such file or directory” while installing kmod-xfs-xen.

# yum install binutils
# yum install xfsprogs yum-kmod kmod-xfs-xen

# mkfs.xfs -f /dev/sda1

Check

A chunk of disk (2TB) has been allocated to a LVM partition for the VM, which is formatted with XFS. The device is mapped into the VM as /dev/xvdc1 (i.e. a whole device, c.f. partitioned device).

Before using the filesystem, perform a check:

# xfs_check /dev/xvdc1

Note: xfs_check requires a significant chunk of memory to run. With 2Gbyte of swap and 1Gbyte of RAM a check was unsuccessful.

Mount
Mount the disk by using it’s volume label. The label can be verified with the xfs_admin program:

# xfs_admin -l /dev/xvdc1
label = “purple-files”

Add the mount entry to ‘/etc/fstab’ so that the filesystem is automatically mounted at the next restart.

LABEL=purple-files /files xfs defaults 0 0
Mount the filesystem

# mount /files

NOTE: CENTOS 6.X

Centos 6.X (64bit) already supports XFS in kernel. You only need to
install xfsprogs package to mount xfs filesystems.

just yum install xfsprogs (it is included in centos 6.2 base)

Appendices

# yum install xfsprogs yum-kmod kmod-xfs-xen

Dependencies Resolved

=============================================================================
Package Arch Version Repository Size
=============================================================================
Installing:
kmod-xfs-xen x86_64 0.4-2 extras 256 k
xfsprogs x86_64 2.9.4-1.el5.centos extras 1.3 M
yum-kmod noarch 1.1.10-9.el5.centos base 15 k

Transaction Summary
=============================================================================
Install 3 Package(s)
Update 0 Package(s)
Remove 0 Package(s)

Total download size: 1.6 M

Search entire filesystem for text in Linux

To search for text through the entire filesystem from the current path down in Linux use the following :

find / -type f -print0 | xargs -0  grep -l  "string to search" 2>/dev/null

Script to list all the MAC addresses on the system

Listing the mac addresses of nic cards excluding null or loopback MACs i.e. 00:00:00:00:00:00

grep -H . /sys/class/net/*/address | awk ‘{split($0,array,”address:”);print array[2]}’ | grep -v ’00:00:00:00:00:00′

 

 

 

Force fsck on next boot

Since live systems are near to impossible to fsck when running (unless you can pull one side of the mirror then clone it to the other (very messy).

Become Root

sudo su –

or

su –

As root create file in root folder a file named forcefsck

touch /forcefsck

Restart the system.

shutdown -r now


        

Using .htaccess to redirect a page with permanently moved 301

Though there are many ways to redirect using the HTTP 301 status code.

(make sure the AllowOverride is set to all on the apache config)

The .htaccess must be as follows:

Options +FollowSymlinks
 RewriteEngine on
 rewritecond %{http_host} ^orig.domain.com [nc]
 rewriterule ^(.*)$ http://new.domain.com/
 $1 [r=301,nc]

Replace the orig.domain.com and new.domain.com with the ones needed for your case of course.

You can setup logs for checking the rewriting though be warned enable them only when debugging they are hugely intensive on I/O and CPU on a heavy utilised server.

More info here : http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html#rewritelog

Nagios fail to run ifstatus

/usr/local/nagios/libexec/check_ifstatus -H localhost

&nbsp

Can’t locate Net/SNMP.pm in @INC (@INC contains: /usr/local/nagios/libexec /usr/local/lib/perl5 /usr/local/share/perl5 /usr/lib/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib/perl5 /usr/share/perl5 .) at ./check_ifstatus line 38.

BEGIN failed–compilation aborted at ./check_ifstatus line 38.

 

Solution:

yum install perl-Net-SNMP

Nagios configuration debugging

After testing a nagios configuration update ( including a new service or renaming some host etc..) before committing the changes and reloading / restarting the nagios service a good test is the following:

/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
(more…)