Tuesday 30 July 2013

Error: Date not updated on Xen Linux Machine

I was trying to set date and time on  paravirtualized xen VM machine with OS centos 5.5 but server was not taking time update and it was showing old date and time. It was also giving following errors when setting time with date command and ntp server.

[root@app04 ~]# date -s "Tue Jul 30 13:32:44 IST 2013"

date: cannot set date: Operation not permitted
Tue Jul 30 13:32:44 IST 2013

[root@app04 ~]# hwclock

Cannot access the Hardware Clock via any known method.
Use the --debug option to see the details of our search for an access method.

Solution:

I checked independent_wallclock kernel parameter in VM machine which was off (value=0). Due to which machine was not taking update of time. So we set it to value 1.

[root@app04 ~]# cat /proc/sys/xen/independent_wallclock
0

[root@app04 ~]# echo 1 > /proc/sys/xen/independent_wallclock

[root@app04 ~]# cat /proc/sys/xen/independent_wallclock
1

Now restarted ntp service and system date was updated.

[root@app04 ~]# service ntpd restart
Shutting down ntpd:                                        [  OK  ]
ntpd: Synchronizing with time server:                      [  OK  ]
Starting ntpd:                                             [  OK  ]

[root@app04 ~]# date

Tue Jul 30 13:40:13 IST 2013

Friday 19 July 2013

Visual Source Safe backup configuration Script & deletion of files older than 7 Days in Windows

On Windows Server I configured the “Visual Source Safe” Software Backup. Please find below scripts for Backup configuration.

1.       This script will take backup of VSS repository.

@ECHO OFF
@TITLE Backing up source safe databases
FOR /F "tokens=2-4 delims=/ " %%i IN ('date /t') DO SET DATE=%%i-%%j-%%k
C:\Program Files\Native Visual Safe\win32\ssarc -d-  e:\vss_backups\%DATE% General backup.ssa $/QMS “-sF:\vssqms” –y<username>,<Pasword>
@ECHO Finished backups

Where C:\Program Files\Native Visual Safe\win32\ssarc  is path of ssarc command.
            E:\vss_backups\%DATE% General backup.ssa is the destination path of backup.
“-sF:\vssqms” is the path of VSS Directory.
$/QMS is the name of repository in VSS which backup is required. If full backup needed we can use “$/” .


2.       This script will delete 7 days older files in E:\vss_backup directory in Windows.



forfiles /p "E:\vss_backup" /s /m *.*  /c "cmd /c  Del @path" /D -7

Monday 15 July 2013

Append, Insert, Replace and Count File Lines into Linux using sed scripting.


Sometime Linux admin has to append, replace and insert the lines into Linux files without using editor. sed is strong scripting utility, through which we can perform these action using command line options. Here we will discuss one by one all option of append, replace, insert and count the file lines.

First of all we create a sample file which can be altered using sed command for file lines actions.

[jitendrakumar@paragtesting ~]$ cat jitendrakumaryogi.txt
This is first line.
My Name is Jitendra Kumar.
I am a Software Engineer.
Oracle is a database Software.
Tomcat and Jboss are application servers.
We love India.
India is a strong nation.
--------Hello------------------
Server1
Server2
Server3
Server4
____________END________________

1.      Append Lines Using Sed.

We use option “a” with sed command to append a line after every line with the address or pattern.

SYNTAX:
#sed ‘Address a\
                        Line which need to be appended’ filename
#sed ‘/PATTERN/ a\
                        Line which need to be appended’ filename
Example1:

Add a line “Software and Development” after 4th line. Sed “a” option will insert line after 4th line.

[jitendrakumar@paragtesting ~]$ sed '4 a\
> Software and Development' jitendrakumaryogi.txt
This is first line.
My Name is Jitendra Kumar.
I am a Software Engineer.
Oracle is a database Software.
Software and Development
Tomcat and Jboss are application servers.
We love India.
India is a strong nation.
--------Hello------------------
Server1
Server2
Server3
Server4
____________END________________

Example2:

Add a line “Shell Scripting” after pattern “Jitendra Kumar”.

[jitendrakumar@paragtesting ~]$ sed '/Jitendra Kumar/a \
Shell Scripting' jitendrakumaryogi.txt
This is first line.
My Name is Jitendra Kumar.
Shell Scripting
I am a Software Engineer.
Oracle is a database Software.
Tomcat and Jboss are application servers.
We love India.
India is a strong nation.
--------Hello------------------
Server1
Server2
Server3
Server4
____________END________________

Example3: Append a line after the End of file.

The following example will add “Testing” after end of line.
[jitendrakumar@paragtesting ~]$ sed '$ a\
> Testing' jitendrakumaryogi.txt
This is first line.
My Name is Jitendra Kumar.
I am a Software Engineer.
Oracle is a database Software.
Tomcat and Jboss are application servers.
We love India.
India is a strong nation.
--------Hello------------------
Server1
Server2
Server3
Server4
____________END____________

Testing

2.      Insert the Line using Sed command.

Sed command used “I” option for inserting line before particular line or pattern.

SYNTAX:
#sed ‘Address i\
                        New Line’ filename
#sed ‘/PATTERN/i \
                        New Line’ filename

Example1: Insert “Implementation of Script” before line 6.

[jitendrakumar@paragtesting ~]$ sed '6 i\
Implementation of Script' jitendrakumaryogi.txt
This is first line.
My Name is Jitendra Kumar.
I am a Software Engineer.
Oracle is a database Software.
Tomcat and Jboss are application servers.
Implementation of Script
We love India.
India is a strong nation.
--------Hello------------------
Server1
Server2
Server3
Server4
____________END____________

Example2:  Insert “Deployment of Application” before pattern “database”.

[jitendrakumar@paragtesting ~]$ sed '/database/i\
Deployment of Application' jitendrakumaryogi.txt
This is first line.
My Name is Jitendra Kumar.
I am a Software Engineer.
Deployment of Application
Oracle is a database Software.
Tomcat and Jboss are application servers.
We love India.
India is a strong nation.
--------Hello------------------
Server1
Server2
Server3
Server4
____________END____________


3.      Replace line using sed command.

“c” command in sed used to replace every line matches with the pattern or ranges with the new given line.

SYNTAX:
#sed ‘Address c\
                        Replace line’ filename
#sed ‘/PATTERN/c \
                        Replace Line’ filename


Example1: Replace a first line of file.

[jitendrakumar@paragtesting ~]$ sed '1 c \
First Line' jitendrakumaryogi.txt
First Line
My Name is Jitendra Kumar.
I am a Software Engineer.
Oracle is a database Software.
Tomcat and Jboss are application servers.
We love India.
India is a strong nation.
--------Hello------------------
Server1
Server2
Server3
Server4
____________END____________

Example2: Replace a line which matches patteen.

Replace the line which contain pattern “Server1” to “It is nice to have it.”

[jitendrakumar@paragtesting ~]$ sed '/Server1/c \
It is nice to have it' jitendrakumaryogi.txt
This is first line.
My Name is Jitendra Kumar.
I am a Software Engineer.
Oracle is a database Software.
Tomcat and Jboss are application servers.
We love India.
India is a strong nation.
--------Hello------------------
It is nice to have it
Server2
Server3
Server4
____________END____________

4.      Print Line Number using sed command.

“=” is a command to print the current line number to standard output.

SYNTAX:

#sed ‘=’ filename

The above send command syntax prints line number in the first line and the original line from the file in the next line.
SYNTAX:
Sed –n ‘/PATTERN/,/PATTERN/ {
=
P
}’ filename

Example1:
Print the line numbers for the lines matches from the pattern “Software” to “Server”

[jitendrakumar@paragtesting ~]$ sed -n '/Software/,/Server/ {
> =
> p
> }' jitendrakumaryogi.txt
3
I am a Software Engineer.
4
Oracle is a database Software.
5
Tomcat and Jboss are application servers.
6
We love India.
7
India is a strong nation.
8
--------Hello------------------
9
Server1

sed ‘=’ command accepts only one address, so if you want to print line number for a range of lines, you must use the curly braces
Example 2: Print the total number of lines in a file
[jitendrakumar@paragtesting ~]$ sed -n '$=' jitendrakumaryogi.txt

14

Friday 12 July 2013

Detect LUN in Linux System in Running Environment


If SAN team provided LUN to Linux system, Linux administrator has to detect the LUN disk into Linux system. This LUN disks can be detected into system without rebooting. Please follow the following commands to detect the LUN on system.


# echo "- - -" > /sys/class/scsi_host/hostX/scan


hostX will be on system according HBA card. If you have 2 HBA cards on system there will be 2 host on system host0 and host1.


For Ex-

For 2 HBA cards please run the following command.

# echo "- - -" > /sys/class/scsi_host/host0/scan
# echo "- - -" > /sys/class/scsi_host/host1/scan

After running above command you can check LUN disk using “fdisk –l” command.




Updation of dynamic DNS zones with nsupdate utility


 This Document is mainly for updation of Dynamic DNS from DHCP Server. If DNS is being dynamically updated from DHCP Server, static entry in DNS Server by editing files will not be reflected properly. In this scenario we have to update Dynamic DNS from DHCP Server by using nsupdate utility.

Before starting update we should get the DHCP key defined in Dynamic DNS Server configuration. You can find dhcpupdate key in named.conf file in DNS Server.

key "dhcpupdate" {
algorithm hmac-md5;
secret "XXX"
}

I mentioned dhcpupdate key with “XXX”, this value will be different generated by system. So use secret key from configuration file of named.conf.

Now by using following step we can add dynamic forward and Reverse DNS entry from DHCP Server.

1.      Adding Forward Zone Entry:

[root@dhcp named]#  nsupdate
> key dhcpupdate  XXX
>update add jitendrakumar.example.com in 604800 A 10.226.1.201
>send

Here 6048400 is TTL in DNS.

2.      Adding Reverse Zone Entry:

[root@dhcp named]# nsupdate
> key dhcpupdate  XXX
> update add 201.1.226.10.in-addr.arpa  604800 PTR jitendrakumar.example.com
>send

Here 6048400 is TTL in DNS.

3.      If you have to delete any entry, use delete in place of add command.