Tuesday, April 29, 2014

Creating vSphere VM Snapshot for a given list of servers



#Taking the input from user
$File_Name = Read-Host "Provide the filename that contains the list of Servers "
$VM_list = Get-Content "$File_Name"

Write-Host "VMName`t`t`t      SnapShot Name`t`t`t`t`t    Size of Snapshot"
# Checking each Server one by one
foreach($CHK_VM in $VM_List) {
$Cap_VM_Info = Get-VM $CHK_VM | Get-Snapshot | Select VM, Name, SizeGB
$Name = $Cap_VM_Info.VM
              $SnapshotName = $Cap_VM_Info.Name
              $SizeOfSnapshot = $Cap_VM_Info.SizeGB

Write-Host "$Name`t`t$SnapshotName`t`t`t$SizeOfSnapshot"
}



Get-VM | Sort Name | Get-Snapshot | Where { $_.Name.Length -gt 0 } | Select VM,Name,Created,SizeMB

Tuesday, April 15, 2014

Script to scan for new disks added to a Linux server

#!/bin/bash

for channel in `ls /sys/class/scsi_host`
do
    echo "rescanning $channel"
    echo "- - -" > /sys/class/scsi_host/$channel/rescan
done

Friday, April 4, 2014

appending string after end of each line

I have a File that contains list of servers and I just want to append a domain-name (say .xyz.com ) at the end of line.

# head -5 serverlist.txt
server1
server2
server3
server4
server5
# sed  -ie 's/$/.xyz.com/' serverlist.txt
# head -5 serverlist.txt
server1.xyz.com
server2.xyz.com
server3.xyz.com
server4.xyz.com
server5.xyz.com
#

Another method using Awk:
awk '{ print $0 ".xyz.com" }' < serverlist.txt > resultfile.txt

Wednesday, February 19, 2014

Writing infinite loop in Perl

for (;;) {
  # perform some tasks
}

while (1) {
   # perform some tasks
}

Popular Posts

About Me

My photo
I have started this blog to share my work experience and spread some smart solutions on Linux to Internet community. I'm hoping more people will get benefited from this blog. Brief about me: I have 14+ years experience working as System Admin and currently work with VMware.