Thursday, September 1, 2011

Script to recursively check a folder and delete files older

#!/bin/bash
Dir="/backup/backup/"
days="30"

find $Dir -type f -mtime +$days -exec rm {} \;


modify days value according to requirement. How old files you want to delete.

Accessing files of Linux system from Windows


Steps to access files from Linux:
  1. Install Samba On Linux, read article here 
  2. Prepare VBScript to mount network drive for the mapped folder thru Samba, read article here
  3. Run the vbscript on startup, by creating shortcut on start menu, read article here

Installing and Configuring Monit Step by Step


install and configure monit

apt-get install monit

Monit Configuration file is  /etc/monit/monitrc

Now make the list of services you want to monitor 


for example sshd,apache,Mysql 


Now for monit web interface the default port number is 2812

Now let us configure the monit 


vi /etc/monit/monitrc
-------------------------------------------------------------------------------------------------------------------- 
 
set daemon  60    // time interval of the daemon
set logfile syslog facility log_daemon
set mailserver localhost
set mail-format { from: monit@server1.example.com }
set alert root@localhost // mail id to send email alerts
set httpd port 2812 and  // If you want to chang port number change here better leave it default
     SSL ENABLE          // for SSL
     PEMFILE  /var/certs/monit.pem   // SSL certificate location
     allow admin:test                // user name and password Basic Auth

// monitoring sshd

check process sshd with pidfile /var/run/sshd.pid
   start program  "/etc/init.d/ssh start"
   stop program  "/etc/init.d/ssh stop"
   if failed port 22 protocol ssh then restart
   if 5 restarts within 5 cycles then timeout
// monitoring mysql

check process mysql with pidfile /var/run/mysqld/mysqld.pid
   group database
   start program = "/etc/init.d/mysql start"
   stop program = "/etc/init.d/mysql stop"
   if failed host 127.0.0.1 port 3306 then restart
   if 5 restarts within 5 cycles then timeout
// monitoring apache

check process apache with pidfile /var/run/apache2.pid
   group www
   start program = "/etc/init.d/apache2 start"
   stop program  = "/etc/init.d/apache2 stop"

   if failed host www.example.com port 80 protocol http
      and request "/monit/token" then restart
here monit tries to connect www.example.com on port 80 and tries to access a file
/monit/token
 
the actual location of /monit/token is 
 
/var/www/www.example.com/web/monit/token
 
as our website document root is   
 
/var/www/www.example.com/web 
 
if monit cannot access this file it means apache is not runnig so it will
restart apache.
 
Creation of token is given below  
   if cpu is greater than 60% for 2 cycles then alert
   if cpu > 80% for 5 cycles then restart
   if totalmem > 500 MB for 5 cycles then restart
   if children > 250 then restart
   if loadavg(5min) greater than 10 for 8 cycles then stop
   if 3 restarts within 5 cycles then timeout

you can add your custom process for 
monitoring here

---------------------------------------------------------------------------------------------------------------- 


Creation of token
 ---------------------

mkdir /var/www/www.example.com/web/monit

echo "hello" > /var/www/www.example.com/web/monit/token 


Creation of SSL-encrypted monit web interface

-----------------------------------------------------------------
(  /var/certs/monit.pem  )


openssl req -new -x509 -days 365 -nodes -config ./monit.cnf -out /var/certs/monit.pem -keyout /var/certs/monit.pem
openssl gendh 512 >> /var/certs/monit.pem
openssl x509 -subject -dates -fingerprint -noout -in /var/certs/monit.pem
chmod 700 /var/certs/monit.pem 



then we need to configure OpenSSL configuration file to create our certificate 
vi /var/certs/monit.cnf

example file is  
-------------------------------------------------------------------------------------------
# create RSA certs - Server

RANDFILE = ./openssl.rnd

[ req ]
default_bits = 1024
encrypt_key = yes
distinguished_name = req_dn
x509_extensions = cert_type

[ req_dn ]
countryName = Country Name (2 letter code)
countryName_default = MO

stateOrProvinceName             = State or Province Name (full name)
stateOrProvinceName_default     = Monitoria

localityName                    = Locality Name (eg, city)
localityName_default            = Monittown

organizationName                = Organization Name (eg, company)
organizationName_default        = Monit Inc.

organizationalUnitName          = Organizational Unit Name (eg, section)
organizationalUnitName_default  = Dept. of Monitoring Technologies

commonName                      = Common Name (FQDN of your server)
commonName_default              = server.monit.mo

emailAddress                    = Email Address
emailAddress_default            = root@monit.mo

[ cert_type ]
nsCertType = server
------------------------------------------------------------------------------ 
enable monit daemon now
/etc/default/monit 
 
in this file set startup =1 and interval for running the monit daemon
example file is below 
--------------------------------------------------------------
# Defaults for monit initscript
# sourced by /etc/init.d/monit
# installed at /etc/default/monit by maintainer scripts
# Fredrik Steen 

# You must set this variable to for monit to start
startup=1

# To change the intervals which monit should run uncomment
# and change this variable.
CHECK_INTERVALS=60
--------------------------------------------------------------- 
now let us start monit
/etc/init.d/monit start  
 
 
Now point your browser to https://www.example.com:2812/
 (make sure port 2812 is not blocked by your firewall), log in with admin and test 
as specified in /etc/monit/monitrc

Install Mac on any PC

To ensure you don't lose any files, use a blank hard drive.

1. Download the Rebel EFI file, available here.
2. Burn the file to a CD.
3. Insert the Rebel EFI disc into your CD drive.
4. Start or restart your computer.
5. As computer boots up select, Boot Options or Boot Menu Key
**Boot Options or Boot Menu Key differ by motherboard manufacturer.
6. Select CD ROM
7. After CD loads press enter to run the CD
8. When prompted, Eject the CD and it will ask for the Snow Leopard DVD
9. Insert the Snow Leopard DVD
10. Select Main Language
11. Click Continue, if you want to continue with the installation of Snow Leopard.
12. Click Agree, if you agree.
13. Select the disk that you want to install Snow Leopard on.
a. If no disk shows, Click on Utilities on the tool bar, then select Disk Utilities.
b. On the left you should see your hard drive.
c. If not, a disk is not connected or cannot be read by your computer.
d. After selecting your hard drive click on Partition.
e. Under Volume Scheme, click current and select 1 partition.
f. Under Volume Information, name your hard drive.
g. Format: Mac OS Extended (Journaled)
h. At the bottom of the window Click on the Options Button.
i. Select the GUID Partition Table
j. Click OK
k. Click Apply
l. Click Partition
m. Quit Disk Utilities
14. Select the disk that you want to install Snow Leopard on.
15. Click Install.
16. When Installation completes. restart the computer
17. As the computer starts up, insert the Rebel EFI CD
18. As computer boots up select Boot Options or Boot Menu Key
**Boot Options or Boot Menu Key differ by motherboard manufacturer.
19. Select CD ROM
20. Once CD loads you will see both the Hard Disk and the Rebel EFI CD
21. Use the arrow keys to highlight the Hard Drive
22. Press Enter to boot Hard drive.
23. Launch the Rebel EFI application from the CD.
24. Follow the on-screen authentication procedure.
25. Click Continue
26. Select your Keyboard
27. Click Continue
28. Select, Do not transfer my information now.
29. Click Continue
30. If, you have and Apple ID enter it now
31. If not, Click Continue
32. Enter your Registration Information
33. Click Continue
34. Create your Account Information
35. Click Continue
36. Select Time Zone
37. Click Continue
38. Click Done

Desired Profile for Linux Admins keep your self Updated

Installation, Configuration, Maintenance of OS ( Linux : RedHat, Suse )
Handling CVS and SVN for repository on Linux Platform.
Installation and troubleshooting of Oracle Database, Application Server ( Weblogic), 

Apache, Tomcat etc. and Web servers
Shell sciprting skills to automate the backups.
Good Knowledge of NFS,NIS and File Systems.
Configuration of Services like FTP,Telnet, SSH, etc
Sound knowledge of Solaris .
Preferably RHCE Certified Engineer.
Installation, Configuration, Maintenance of OS ( Linux : RedHat, 

Suse )
Handling CVS and SVN for repository on Linux Platform.
Installation and troubleshooting of Oracle Database, Application Server ( Weblogic),

Various Admin Requirements

Linux
/Solaris/AIX/HPUX/Redhat (Expertise in at least two)


Remote support, KVM, DRAC, ALOM, HMC


Perl/shell scripting(MUST)


LVM/Sun Disk Suite


Network services, NFS, NIS, DNS, Samba.


OpenSource software compilation and installation (gcc, cc)


Knowledge of RAID (0,1,1+0,3,5)


OS installation, kernel configuration


Web servers, apache, iPlanet, tomcat


Monitoring tools, Nagios, Netsaint, OVO, BMC patrol, MRTG, Remedy


Troubleshooting and performance tuning.


Veritas products - File System, Clustering, Volume Manager


OpenPKG / RPM, Sun Packages


Storage knowledge, EMC, HP-EVA, IBM-ESS


Virtualization, Vmware, Xen


Role: Configuration Management-unix and linux admin exp

?The individual should have sound Unix Background, with at least 2years of Administration Skills in Solaris 5.8 and above and Redhat Linux 4 and above.
?The individual should have handson admin experience of at least 4 years in ClearCase ver 6 and above, ClearCase MultiSite
?The individual must be skilled in DesignSync and should have at least 1years hands-on experience with DesignSync
?The individual should posses sufficient knowledgeable of Windows environment to be able to different windows related and Application related issues
?The individual should have knowledgeable in Defect and Requirement Management tools like ClearQuest, RequisitePro
?The individual must exhibit very good programming skills with Perl

Good To Have Skills:
?Knowledge / hands-on with BuildForge, Klockwork, Sourceforge, GIT will be an added advantage

Must have skills for linux administrator

User & group administration
Configuring Linux Networking
Installing and configuring Linux Operating system
Basic Operating System Concepts
Basic experience in Shell Scripts.
Knowledge on apache server
Knowledge on FTP,SSH,SSL,Telnet & xinetd
Knowledge about File system hierarchy
Basic Network Troubleshooting
Installing & configuring Linux Software
Monitoring Server Performance
Configuring Linux Software RAID
Expanding Linux Partitions with LVM
Network Based Linux Installation like NFS, HTTP & FTP
In-depth knowledge on Linux operating system
Experience in shell and Perl scripting
Kernel compilation and fine tuning.
Configuring Linux Firewalls Using iptables
Configuring & Managing Disk Usage With Quotas
Knowledge on TCP/IP
File system Management
Expertise in managing and configuring various services like DNS, NIS, NFS, APACHE, FTP, DHCP & SAMBA
Knowledge on High Availability and Clustering.
High Level of Troubleshooting skills

Redhat KickStart Installation step by step guide

To use kickstart, you must:
1. Create a kickstart file.
2. Create a boot media with the kickstart file or make the kickstart file available on the network.
3. Make the installation tree available.
4. Start the kickstart installation.


Genral Installation and automatic creation of kickstart file

step 1 : Connect system to DHCP network
Step 2 : Boot your system using Redhat boot media.
Step 3 : Enter command "linux askmethod" at boot prompt and press enter.
step 4 : Follow the installation process till it asks for Installation Method.

The options for installation method incude.

Local CDROM
Hard Drive
NFS Image  ( Network installation )
FTP  ( Network installation )
HTTP ( Network installation )

Select your method and install accordingly.

After installation /root/anaconda-ks.cfg file is automatically created during Install.

/root/anaconda-ks.cfg can be used as a template for future installation.

It is a scripted installation process.

we can manually configure with System-Config-Kickstart

Check systax of Kickstart file with : ksvalidator

Once you are ready with Kickstart file lets start installation with Kickstart file.


for installation with kickstart we should give following command at boot prompt

linux ks= Url

Ks will queries DHCP for kickstart location
URl gets file via HTTP or FTP or NFS.

we can also give local address like

KS=floppy; ks=Cdrom or ks= hd:device:/path of the file.


Using a NFS Server

Verify that the first two lines of the file look like this or else you may be prompted for NFS ISO file location information. 

install 
nfs --server=192.16.1.100 --dir=/data/network-install/ISO


example : linux ks=nfs:192.168.1.100:/kickstart/ks.cfg

Run this at boot prompt with your settings for NFS ks installation

Using a Web Server

Verify that the first two lines of the file look like this or else you may be prompted for RPM base file location information.

install
url --url http://192.168.1.100/network-install/

example : linux ks=http://192.168.1.100/network-install/kickstart/ks.cfg

Run this at boot prompt with your settings for http ks installation

Comming to Kickstart file it consists of three sections

1 command section 
2 packages section
3 scripts section



Note 1: Do not change the order of the entries in the kickstart configuration file.
Note 2: The IP address you assign must be on the same subnet as that of the DHCP server for kickstart to work. If the server is going to reside on a different network after the installation, then you have to run a separate script to change the IP addressing information after the installation is complete.

Redhat refrence links for Kickstart

What are Kickstart Installations ? explained by Redhat
How Do You Perform a Kickstart Installation? explained by Redhat
Creating the Kickstart File  explained by Redhat
Kickstart Options  explained by Redhat
Pre-installation Script explained by Redhat
Post-installation Script explained by Redhat
Making the Kickstart File Available explained by Redhat
Starting a Kickstart Installation explained by Redhat
Kickstart Configurator explained by Redhat
Installation Method explained by Redhat