Tuesday, 17 May 2016

Shell Scripts you will love to use

In this article, I will share a few of my shell scripts which will be helpful in automating repetitive infrastructure task. All Scripts are written and tested on RHEL 6.1 x86.
What the shell Script does and the agenda behind writing each script are also mentioned. The scripts have been named as per my requirement, feel free to rename and use it as per your environment’s needs.
SCRIPT#1 – I call it InitialConfig.sh
In my environment, I need to create VMs and decommission them every now and then. The Count of RHEL6 VMs is on the higher scale than any other Linux Flavors.
Once RHEL6 VM creation and OS Installation is done, we need to perform configuration changes which are by default common for all RHEL6 VMs.The task is very time consuming and repetitive.Hence, I thought of writing a shell Script which will automate the repetitive task and hence save time.
Note:Static IP Address needs to be SET manually.
In case of Dynamic Address [DHCP], No changes required in Network Settings
Basically, the Script performs the following:
1. Configures /etc/hosts file.
2. Configures /etc/sysconfig/network file.3. Sets Hostname.4. Disables GUI Firewall and iptables.5. Disables SELINUX.6. Updates Time Zone.7. Verifies Date and Time.8. Change Run level from five to three.9. Finally Reboot the System in one minute.
Now, follows the InitialConfig.sh script.
####################################
#Created By Arindam Mitra###########
####################################
 
#UPDATE HOST FILE - /etc/hosts
 
IP=$(ifconfig eth0 | grep 'inet addr:' | cut -d: -f2 | awk '{ print $1}')
read -p "Specify FQDN of the System [Example - RH601.linuxrocks.org] : " FQDN
read -p "Specify Hostname of the System [Example - RH601] : " HNAME
echo "#Edited By Arindam Mitra" >> /etc/hosts
echo $IP $FQDN $HNAME >> /etc/hosts
 
#UPDATE HOSTNAME AND CONFIGURATION FILE - /etc/sysconfig/network
cat /etc/sysconfig/network | grep NETWORKING > /tmp/hostname.txt
echo "#Edited By Arindam Mitra" >> /tmp/hostname.txt
echo HOSTNAME=$HNAME >> /tmp/hostname.txt
sed -i'' '2 s/^/#/' /etc/sysconfig/network
cat /tmp/hostname.txt > /etc/sysconfig/network
hostname $HNAME
rm -rf /tmp/hostname.txt
 
#SERVICE IPTABLES STOPPED NOW AND DURING BOOT TIME
 
service iptables stop > /dev/null
chkconfig iptables off
 
#DISABLE GUI BASED FIREWALL
cat /etc/sysconfig/system-config-firewall | grep service > /tmp/firewall.txt
echo "#Edited By Arindam Mitra" >> /tmp/firewall.txt
echo "--disabled" >> /tmp/firewall.txt
cat /tmp/firewall.txt > /etc/sysconfig/system-config-firewall
rm -rf /tmp/firewall.txt
 
#DISABLE SELINUX
sed -i'' '7 s/^/#/' /etc/sysconfig/selinux
echo "#Edited By Arindam Mitra" >> /etc/sysconfig/selinux
echo "SELINUX=disabled" >> /etc/sysconfig/selinux
 
#UPDATE TIMEZONE
 
cat /etc/sysconfig/clock | grep ZONE > /tmp/clock.txt
sed -i'' '1 s/^/#/' /tmp/clock.txt
echo "#Edited By Arindam Mitra" >> /tmp/clock.txt
echo "ZONE=\"Europe/Amsterdam\"" >> /tmp/clock.txt
cat /tmp/clock.txt > /etc/sysconfig/clock
rm -rf /tmp/clock.txt
 
#UPDATE RUNLEVEL FROM 5 to 3
sed -i'' '26 s/^/#/' /etc/inittab
echo "#Edited By Arindam Mitra" >> /etc/inittab
echo "id:3:initdefault:" >> /etc/inittab
 
#OUTPUT ON TERMINAL :-
 
echo "#############################"
echo "UPDATED HOSTS FILE [/etc/hosts] :-"
cat /etc/hosts
echo "#############################"
echo "UPDATED HOSTNAME :-"
hostname
echo "#############################"
echo "UPDATED HOSTNAME CONFIGURATION FILE :-"
cat /etc/sysconfig/network
echo "#############################"
echo "UPDATED IPTABLES STATUS :-"
echo "CURRENT STATUS :-"
service iptables status
echo -ne "\n"
echo "DURING BOOT TIME :-"
chkconfig --list | grep iptables
echo "#############################"
echo "GUI BASED FIREWALL DISABLED."
echo "Pls, verify using GUI :- System -> Administration -> Firewall"
echo "#############################"
echo "UPDATED SELINUX STATUS :-"
echo "*************************"
echo "AS PER CONFIGURATION :-"
cat /etc/sysconfig/selinux | grep SELINUX=
echo -ne "\n"
echo "AS PER SYSTEM :-"
getenforce
echo "*************************"
echo "SELINUX has been Disabled but Reboot is Required to bring the changes into effect..."
echo "#############################"
echo "UPDATED TIME ZONE :-"
cat /etc/sysconfig/clock | grep ZONE
echo "##############################"
echo "CURRENT DATE AND TIME :-"
date
echo "##############################"
echo "UPDATED RUNLEVEL STATUS"
echo "*************************"
echo "AS PER CONFIGURATION :-"
cat /etc/inittab | grep id:
echo -ne "\n"
echo "AS PER SYSTEM :-"
runlevel
echo "*************************"
echo "RUNLEVEL has been changed from 5 to 3 but Reboot is Required to bring the changes into effect..."
echo "##############################"
 
 
#REBOOT INITIATED AFTER ONE MINUTE 
shutdown -r +1 "Please save your work ASAP."
echo "##############################"
SCRIPT#2 – I call it ChangeRootPassword.sh
In our infrastructure environment, root user password is common for all Linux VMs and is not shared with anyone expect the Linux Administrator.
Once a year or every six months, the password of root user is changed for all Linux VMs. The task is repetitive and pretty boring. Hence, I wrote this one liner shell script which automated the process and saved time.
Basically, the Script performs the below:
1. Set New Password for Root user.
Now, follows the ChangeRootPassword.sh script.
#!/bin/bash
###################################
#Created By Arindam Mitra##########
###################################
 
echo "admin123" | passwd --stdin root
echo "Root Password Changed!!!"
SCRIPT#3 – I call it DNSConfig.sh
It was during our Domain Migration Activity when we had to change DNS Suffix and DNS IP Address in all Linux Servers.
At that point, I wrote this shell script to automate the task.
Basically, the Script performs the below:
1. Makes a copy the DNS Configuration file [/etc/resolv.conf] prior making changes.
2. Then, Updates the DNS Configuration file with New Suffixes and IP Addresses.
Now, follows the DNSConfig.sh script.
#!/bin/bash
####################################
#Created By Arindam Mitra###########
####################################
 
cp /etc/resolv.conf /etc/resolv.conf.orig
cat <<EOF > /etc/resolv.conf
search delhi.linuxrocks.org pune.linuxrocks.org
nameserver X.X.X.X
nameserver Y.Y.Y.Y
EOF
SCRIPT#4 – I call it ServerConfigDetails.sh
For Server Implementation, I happened to travel to various customer locations. One thing which I have faced and is common for all projects is that every time I had to pull Server Inventory details before I start with the actual configuration – How much Disk Space available, memory, Swap Space, CPU, Sockets, IP Address etc.
To make my life easy, I wrote this shell script, which pulls Complete Server Inventory details and displays the output on the terminal:
Basically, the Script performs the below:
1. It Pulls the below Inventory Details of Linux server and displays the output.
Hostname, Operating System, Architecture, Hypervisor, Manufacturer, Product Name, CPU Type, CPU Usage, CPU OP-MODE(s), No. of CPU, No. of CPU Sockets, CPU Speed, Maximum Memory, Used Memory, % Memory Used, Swap Space Details, Disk Space Details, IP Address, Subnet Mask and MAC Address.
Now, follows the ServerConfigDetails.sh script.
#!/bin/bash
####################################
#Created By Arindam Mitra###########
####################################
 
#HOSTNAME :-
HOSTN=`/bin/hostname`
#OPERATING SYSTEM :-
OS=`cat /etc/redhat-release`
#ARCHITECTURE :-
ARCH=`/bin/uname -p`
#HYPERVISOR TYPE
HTYPE=`dmidecode | grep -m 1 "Product Name" | cut -d ":" -f 2`
if [ "$HTYPE"  = " VMware Virtual Platform" ]
        then HTYPE="VMware Hypervisor"
else
        HTYPE="OTHERS"
fi
 
#HYPERVISOR MANUFACTURER :-
MANUFAC=`/usr/sbin/dmidecode --type system | grep Manufacturer | cut -d ":" -f2`
 
#PRODUCT NAME :-
PRODUCTNAME=`/usr/sbin/dmidecode | grep "Product Name: V" | cut -d ":" -f2 | awk '$1=$1'`
 
#CPU Info/Type
CPUI=`cat /proc/cpuinfo | grep "model name" | cut -d ":" -f2`
 
#CPU Usage
CPU=`top -b -n1 | grep "Cpu(s)" | awk '{print $2 + $4}'`
 
#CPU Details
CPUOM=`/usr/bin/lscpu | grep "CPU op" | cut -d ":" -f2 | awk '$1=$1'`
CPUC=`/usr/bin/lscpu | grep -i "CPU(s):" | cut -d ":" -f2 | awk '$1=$1'`
CPUS=`/usr/bin/lscpu | grep -i "CPU socket(s)" | cut -d ":" -f2 | awk '$1=$1'`
CPUMHZ=`/usr/bin/lscpu | grep -i "CPU MHz" | cut -d ":" -f2 | awk '$1=$1'`
 
#MEMORY DETAILS
MEMUSAGE=`top -n 1 -b | grep "Mem"`
MAXMEM=`echo $MEMUSAGE | cut -d" " -f2 | awk '{print substr($0,1,length($0)-1)}'`
USEDMEM=`echo $MEMUSAGE | cut -d" " -f4 | awk '{print substr($0,1,length($0)-1)}'`
USEDMEM1=`expr $USEDMEM \* 100`
PERCENTAGE=`expr $USEDMEM1 / $MAXMEM`%
 
#SWAP DETAILS
SWAPFS=`swapon -s | grep -vE '^Filename' | awk '{ printf $1}'`
SWAPS=`swapon -s | grep -vE '^Filename' | awk '{ printf $3}'`
SWAPU=`swapon -s | grep -vE '^Filename' | awk '{ printf $4}'`
SWAPP=`swapon -s | grep -vE '^Filename' | awk '{ printf $5}'`
 
#DISK
DISK=`df -H | grep -vE '^Filesystem|tmpfs|cdrom' | awk '{ printf $5 " " $1" | "}'`
 
#NETWORK DETAILS
IP=`ifconfig eth0 | grep "inet addr" | cut -d ":" -f2 | awk '{printf $1}'`
SM=`ifconfig eth0 | grep "inet addr" | cut -d ":" -f4`
MAC=`cat /etc/sysconfig/network-scripts/ifcfg-eth[0123] | grep -i HWADDR | cut -d "=" -f2`
 
#OUTPUT :-
echo -ne "\n"
echo "###################SERVER-DETAILS######################"
echo "1.  HOSTNAME = $HOSTN "
echo "2.  OPERATING SYSTEM = $OS"
echo "3.  ARCHITECTURE = $ARCH"
echo "4.  HYPERVISOR = $HTYPE"
echo "5.  MANUFACTURER = $MANUFAC"
echo "6.  PRODUCT NAME = $PRODUCTNAME"
echo "7.  CPU TYPE = $CPUI"
echo "8.  CPU USAGE = $CPU"
echo "9.  CPU OP-MODE(s) = $CPUOM"
echo "10. NO. OF CPU = $CPUC"
echo "11. NO. OF CPU SOCKETS = $CPUS"
echo "12. CPU SPEED IN MHz = $CPUMHZ"
echo "13. MAXIMUM MEMORY = $MAXMEM"
echo "14. USED MEMORY = $USEDMEM"
echo "15. PERCENTAGE MEMORY USED = $PERCENTAGE"
echo "16. SWAP DETAILS :-"
echo "       a. File System = $SWAPFS"
echo "       b. Size = $SWAPS"
echo "       c. Used = $SWAPU"
echo "       d. Priority = $SWAPP"
echo "17. DISK DETAILS [% Usage, FileSystem] = $DISK"
echo "18. IP ADDRESS = $IP"
echo "19. SUBNET MASK = $SM"
echo "20. MAC ADDRESS = $MAC"
echo "###################SERVER-DETAILS######################"
echo -ne "\n"
 
Conclusion
This concludes the article. Hope you enjoyed while reading. Please do provide you valuable feedbacks. You can reach me at theja0473@mail.com theja0473@gmail.com for any queries or questions.

Learn the Art of Linux Troubleshooting

Here are some valuable tips to help you find important system files in RHEL 5, which get deleted by accident.
Everything seems fine when your Linux machine works just the way you want it to. But that feeling changes dramatically when your machine starts creating problems that you find really difficult to sort out. Not everyone can troubleshoot a Linux machine efficiently… but you can, if you are ready to stay with us for the next few minutes. Let’s look at what to do when some of your important system files are deleted or corrupted under Red Hat Enterprise Linux 5. The action begins now!
Scene 1: /etc/passwd is deleted
This is an important file in Linux as it contains information about user accounts and passwords. If it’s missing in your system and you try to log in to a user account, you get an error message stating Log-in incorrect and after restarting the system.
Now that you have seen the problem and its consequences, it’s time to solve it. Boot into single user mode. At the start of booting, press any key to enter into the GRUB menu. Here you will see a list of the operating systems installed. Just select the one you are working with and press.
It’s time to have some fun with kernel parameters. So highlight the kernel and again press e to edit its parameters.
Next, instruct the kernel to boot into single user mode, which is also known as maintenance mode. Just type 1 after a space and press the Enter key. Now press b to continue the booting process.
Now that you have booted into single user mode, you are probably asking yourself, What is next?. The tricky portion of this exercise is now over and it takes just one command to have your passwd file in its place. Actually, there is a file /etc/passwd-, which is nothing but the backup file for /etc/passwd. So all you need to do is to issue the following command:
cp /etc/passwd- /etc/passwd
…and you are done. Now you can issue the init 5 command to switch to the graphical mode. Everything is fine now. You can also find the backup of /etc/shadow and /etc/gshadow as /etc/shadow- and /etc/gshadow- respectively.
Scene 2: /etc/pam.d/login is deleted
If your /etc/pam.d/login file is deleted and you try to log in, it won’t ask you to enter your password after entering your username. Instead, it will continuously show the localhost login prompt. Here again, there is a single command that will solve the problem for you:
cp /etc/pam.d/system-auth /etc/pam.d/login
Just boot into the single user mode as done earlier, type this command and you’ll be able to log in normally. There is also a second solution to this problem, which we’ll look at after a while.
Scene 3: /etc/inittab is deleted
We know that in Linux, init is the first process to be started and it starts all the other processes. The /etc/inittab file contains instructions for the init process and if it’s missing, then no further process can be launched. On starting a system with no inittab file, it will show the following message:
INIT:No inittab file found …and will ask you to enter a runlevel. When you do that, it again shows the message that no more processes are left in this runlevel.
Fixing this problem is not easy because being in the single user mode doesn’t help in this case. Here, you need the Linux rescue environment to fix this problem. So set your first boot device to CD and boot with the RHEL5 CD. At the boot prompt, type ‘Linux rescue’ to enter the rescue environment.
Once you have entered into the rescue environment, your system will be mounted under /mnt/sysimage. Here, reinstall the package that provides the /etc/inittab file. The overall process is given below:
chroot /mnt/sysimage 
rpm -q --whatprovides /etc/inittab 
mkdir /a 
mount /dev/hdc /a 
 
Here /dev/hdc is the path of the CD. It may vary on your system, though. 
 
rpm –Uvh --force /a/Server/initscripts-8.45.25-1.el5.i386.rpm
You can also hit the Tab key after init to auto complete the name.
Now you’ll get your /etc/inittab file back. The same procedure can be applied to recover the /etc/pam.d/login file. In this case, you’ll have to install the util-linux package. Once you are done with it, type Exit to leave the rescue environment, set your first boot device to hard disk and boot normally.
Scene 4: /boot/grub/grub.conf is deleted
This file is the configuration file of the GRUB boot loader. If it is deleted and you start your machine, you will see a GRUB prompt that indicates that grub.conf is missing and there is no further instruction for GRUB to carry on its operation.
But don’t worry, as we’ll solve this problem, too, in the next few minutes. You don’t even need to enter single user mode or the Linux rescue environment for this. At the GRUB prompt, you can enter some command that can make your system boot. So here we go: Type root (and hit Tab to find out the hard disks attached to the system. In my case, I got hd0 and fd0—the hard disk and floppy disk, respectively). Now we know that GRUB is stored in the first sector of a hard disk, which is hd0,0. So the complete command would be root (hd0,0). Enter this command and press the Enter key to carry on.
You now need to find out the kernel image file. So enter kernel /v and hit Tab to auto complete it. In my system, it’s vmlinuz-2.6.18-128.el5. Please note it down as we’ll require this information further, and then press Enter.
Next, let’s figure out the initrd image file. So enter initrd /i and press Tab to auto complete it. For me, it’s initrd-2.6.18-128.el5.img. Again note it down and press Enter.
Type boot and press Enter, and the system will boot normally.
Now it’s time to create a grub.conf file manually. So create the /boot/grub/grub.conf file and enter the following data in it:
 
splashimage=(hd0,0)/grub/splash.xpm.gz 
default=0 
timeout=5 
title Red Hat 
root (hd0,0) 
kernel /vmlinuz-2.6.18-128.el5 
initrd /initrd-26.18-128.el5.img
Save the file and quit it. You have created a grub.conf file manually to resolve the problem. Don’t forget that the kernel and the initrd image file name may vary on your system. That’s why I asked you to note them down earlier. You can also find them in the /boot folder once you are logged in it’s not a big issue.
So we have looked at solutions to four different problems. I hope this information  assists you in learning Linux troubleshooting. Carry on this work and acquire more troubleshooting skills because that’s what makes you a true Linux geek.

How to set automatic email reminder using Cron Job?

Hello friends, today I am going to tell you how to set an email reminder or email notification. This can be done via Cron Jobs. Cron Jobs is helpful for reminder purposes or if you don't want to send same email every week or every single day then Cron Jobs is the best approach.  Cron Jobs can be set on the server or even on your own local system (Linux/Ubuntu). If you have Ubuntu or Linux then you can set Cron Jobs in your local system. Lets understand what is Cron Jobs first.
Cron Job is a way through which you can set and schedule routine background job at specific period of time. Now let us understand the syntax of how to set Cron:

  1. MIN HOUR DOM MON DOW CMD

MIN: First argument passed is Minute, at what minute do you want to set Cron to run. Value for minute ranges from 0 to 59.
Hour: Second argument passed is Hour, at what hour do you want to execute Cron. Value for Hour ranges from 0 to 23.
DOM: Third argument is DOM, this is day of month. Example: If you want cron to run every 29th day of the month then you can set DOM to 29. Value for DOM ranges from 1 to 31.
MON: Fourth argument is MON, this is month field. If you want to run the cron on June, then set MON to 6. Value for MON ranges from 1 to 12.
DOW: Fifth argument is DOW, this is day of week. You can set DOW to numeric from 0 to 6 or you can also set DOW to name of the day . For example: If you want to run the cron on sunday, then you can set DOW to "sun".
CMD: Last argument to be passed on cron is command. Here you will write the command that will be executed when cron will run.

Now lets write the code for sending email. Create file email.php

  1. <?php
  2. // the message wishing birthday to your friend
  3. $msg = "Wish you a very happy birthday....";
  4. // use wordwrap() if lines are longer than 100 characters
  5. $msg = wordwrap($msg,100);
  6. // send email
  7. mail("myfriend@example.com","Happy Birthday Subject",$msg);
  8. ?>

Now let us set an email notification or reminder for specific time say 29th May 7:00 AM:

  1. 0 07 29 05 * /home/amuk/email.php

0 - 0 Minute
07- 7 AM
28- 29th Day
05- 5th Month (May)
* - Every day of week
/home/amuk/email.php - Location of the file where your file is saved.

This is how you can schedule and set multiple cron jobs. Hope this blog helps you to create a cron job in Linux/Ubuntu. If you have purchased hosting then you can also set cron jobs by selecting cron jobs in cpanel and setting the command same way.

Thanks for reading the blog.
- See more at: http://findnerd.com/list/view/How-to-set-automatic-email-reminder-using-Cron-Job/19044/#sthash.V08ICw5k.dpuf

Monday, 16 May 2016

Netapp Hardware Interview Questions and Answers

1. What is NVRAM..?
Ans:- Non-volatile battery-backed memory (NVRAM) is used for write caching.

2. Do you know how data is written to the disk in Netapp.? Please explain..?
Ans:- As soon as the write to NVRAM is confirmed, the storage appliance acknowledges the write as completed to the client machine. At pre-determined triggers, this buffered write data is processed from storage device memory through the Write Anywhere File Layout (WAFL) and RAID layers and written to disk.

3. What is SP/RLM/BMC..?
Ans:- 
SP - Service processor
 SP monitors the system temperatures, voltages, currents, and fan speeds. When an environmental sensor has reached an abnormal condition, the SP logs the abnormal readings, notifies Data ONTAP of the issue, and sends alerts and 'down system' notifications as necessary through an AutoSupport message, regardless of whether the storage system can send AutoSupport messages

RLM - Remote LAN Module 
The RLM provides remote node management capabilities, including remote access, monitoring, troubleshooting, logging, and alerting features

BMC -  Baseboard management console
The AutoSupport settings are used for sending the alerts through e-mail over the BMC LAN interface.

4. What is difference between FAS and V-Series..?
Ans:- 
FAS - Fibre attached Storage
V-Series - Virtualized  Series 

FAS is used in Single node and HA pair configuration
V-Series is used when want to virtualize with third party Storage system

5. What is difference between 7-mode and C-mode..?
Ans:- 
7-mode either single node Or two controllers clustered for HA. Single node will support for single namespace. One controller will work as a single node. 

C-mode either single controller "pair" Or multi controller "pairs" connected as a clustered. Each VServer will work as a single entity. It will support for multi namespaces 

 6. What is the maximum capacity of volume in 7-mode 32bit..?
Ans:- 16TB

7. How many disk types can Netapp support..?
Ans:-   FC, SAS, SSD, Near Line SAS and SATA

8. How to check your Netapp serial number..?
Ans:- sysconfig -a

9. how to determine that FC port is working an which mode..?
Ans:- using fcadmin command we can verify

10. How to verify whether all the disk shelfs for connected in redundant..?
Ans:- sysconfig -d and storage show disk   

Commands Netappp

This post contains the list of commands that will be most used and will come handy when managing or monitoring or troubleshooting a Netapp filer in 7-mode.
  • sysconfig -a : shows hardware configuration with more verbose information
  • sysconfig -d : shows information of the disk attached to the filer
  • version : shows the netapp Ontap OS version.
  • uptime : shows the filer uptime
  • dns info : this shows the dns resolvers, the no of hits and misses and other info
  • nis info : this shows the nis domain name, yp servers etc.
  • rdfile : Like “cat” in Linux, used to read contents of text files/
  • wrfile : Creates/Overwrites a file.
  • aggr status : Shows the aggregate status
  • aggr status -r : Shows the raid configuration, reconstruction information of the disks in filer
  • aggr show_space : Shows the disk usage of the aggregate, WAFL reserve, overheads etc.
  • vol status : Shows the volume information
  • vol status -s : Displays the spare disks on the filer
  • vol status -f / aggr status -f : Displays the failed disks on the filer
  • vol status -r : Shows the raid configuration, reconstruction information of the disks
  • df -h : Displays volume disk usage
  • df -i : Shows the inode counts of all the volumes
  • df -Ah : Shows “df” information of the aggregate
  • license : Displays/add/removes license on a netapp filer
  • maxfiles : Displays and adds more inodes to a volume
  • aggr create <Aggr Name> <Disk Names> : Creates aggregate
  • vol create : Creates volume in an aggregate
  • vol offline : Offlines a volume
  • vol online : Onlines a volume
  • vol destroy : Destroys and removes an volume
  • vol size [+|-] : Resize a volume in netapp filer
  • vol options : Displays/Changes volume options in a netapp filer
  • qtree create : Creates qtree
  • qtree status : Displays the status of qtrees
  • quota on : Enables quota on a netapp filer
  • quota off : Disables quota
  • quota resize : Resizes quota
  • quota report : Reports the quota and usage
  • snap list : Displays all snapshots on a volume
  • snap create : Create snapshot
  • snap sched : Schedule snapshot creation
  • snap reserve : Display/set snapshot reserve space in volume
  • /etc/exports : File that manages the NFS exports
  • rdfile /etc/exports : Read the NFS exports file
  • wrfile /etc/exports : Write to NFS exports file
  • exportfs -a : Exports all the filesystems listed in /etc/exports
  • cifs setup : Setup cifs
  • cifs shares : Create/displays cifs shares
  • cifs access : Changes access of cifs shares
  • lun create : Creates iscsi or fcp luns on a netapp filer
  • lun map : Maps lun to an igroup
  • lun show : Show all the luns on a filer
  • igroup create : Creates netapp igroup
  • lun stats : Show lun I/O statistics
  • disk show : Shows all the disk on the filer
  • disk zero spares : Zeros the spare disks
  • disk_fw_update : Upgrades the disk firmware on all disks
  • options : Display/Set options on netapp filer
  • options nfs : Display/Set NFS options
  • options timed : Display/Set NTP options on netapp.
  • options autosupport : Display/Set autosupport options
  • options cifs : Display/Set cifs options
  • options tcp : Display/Set TCP options
  • options net : Display/Set network options
  • ndmpcopy : Initiates ndmpcopy
  • ndmpd status : Displays status of ndmpd
  • ndmpd killall : Terminates all the ndmpd processes.
  • ifconfig : Displays/Sets IP address on a network/vif interface
  • vif create : Creates a VIF (bonding/trunking/teaming)
  • vif status : Displays status of a vif
  • netstat : Displays network statistics
  • sysstat -us 1 : begins a 1 second sample of the filer’s current utilization (crtl – c to end)
  • nfsstat : Shows nfs statistics
  • nfsstat -l : Displays nfs stats per client
  • nfs_hist : Displays nfs historgram
  • statit : beings/ends a performance workload sampling [-b starts / -e ends]
  • stats : Displays stats for every counter on netapp. Read stats man page for more info
  • ifstat : Displays Network interface stats
  • qtree stats : displays I/O stats of qtree
  • environment : display environment status on shelves and chassis of the filer
  • storage show <disk|shelf|adapter> : Shows storage component details
  • snapmirror intialize : Initialize a snapmirror relation
  • snapmirror update : Manually Update snapmirror relation
  • snapmirror resync : Resyns a broken snapmirror
  • snapmirror quiesce : Quiesces a snapmirror bond
  • snapmirror break : Breakes a snapmirror relation
  • snapmirror abort : Abort a running snapmirror
  • snapmirror status : Shows snapmirror status
  • lock status -h : Displays locks held by filer
  • sm_mon : Manage the locks
  • storage download shelf : Installs the shelf firmware
  • software get : Download the Netapp OS software
  • software install : Installs OS
  • download : Updates the installed OS
  • cf status : Displays cluster status
  • cf takeover : Takes over the cluster partner
  • cf giveback : Gives back control to the cluster partner
  • reboot : Reboots a filer

Thursday, 12 May 2016

How to split a file in Linux

The specialty in Linux is that everything is a file. Here I am going to share you a small tip on how to split a file of particular size and get back to its original size. Consider an example, if we want to split a 900MB ISO image file, then do the following:
# split -b 900m image.iso
Now it will generate three files, namely image.iso1, image.iso2, image.iso3 each. Afterwards you can use the cat command to combine the three to get back the original file, as follows:
# cat image.iso* > new-image.iso
Thats it, we got file back with its original size………Cool!!!!!!!
split command in Unix is used to split a large file into smaller files. The splitting can be done on various criteria: on the basis of number of lines, or the number of output files or the byte count, etc.
$ cat file
Unix
Linux
AIX
Solaris
HPUX
Ubuntu

1. Split a file :

$ split file
The split command splits the file into multiple files with 1000 lines into each output file by default.
The output file generated in this case is:
$ ls x*
xaa
Since the input file does not contain 1000 lines, all the contents are put into only one output file “xaa”. By default, the output files generated contains the prefix “x”, and the suffix as “aa”, “ab”, “ac” and so on.

2. Split file into multiple files with 3 lines each:

$ split -l 3 file
The option -l specifies the number of lines per output file. Since the input file contains 7 lines, the output files contain 3, 3 and 1 respectively.
The output files generated are:
$ ls x*
xaa  xab  xac
$ cat xaa
Unix
Linux
AIX
The file “xab” contains the 4th till 6th line, and the file “xac” contains the last line.

3. Split file into multiple files with a user defined prefix:

$ split -l 3 file F
$ ls F*
Faa  Fab  Fac
The suffix, if provided, is the last argument of the split command. Since the suffix provided is “F”, the files created are “Faa”,”Fab”, and so on.

4. Split file into multiple files with a single character suffix:

$ split -l 3 -a 1 file F
$ ls F*
Fa  Fb  Fc
In the above examples, the suffixes generated are “aa”,”ab” and so on. If the number of output files to be created is huge, this makes sense. For our example, a single character suffix would suffice. The option -a of split allows to control the length of suffix. By providing the suffix length as 1, the files created are “Fa”,”Fb”, and so on.

5. Split file into multiple files with a numeric suffix:

$ split -l 3 -d file F
$ ls F*
F00  F01  F02
The option -d of split enables a numeric suffix. With this, the files generated will be “F00”, “F01”, “F02”, and so on. To get the single digit numeric suffix:
$ split -l 3 -a 1 -d file F
$ ls F*
F0  F1  F2
By enabling the option -a to 1, single digit numeric suffix is set.

6. Split file into multiple files with 10 bytes per OUTPUT file:

$ split -b 10 -a 1 -d file F
The -b option of split divides the file on the basis of byte count. The byte count includes the new line character present at the end of the line as well.
$ ls F*
F0  F1  F2  F3  F4

$ cat F0
Unix
Linux

$ cat F1
AIX
Solar
The file F0 contains 10 characters 5 characters of first line (Unix + new line) and 5 characters of second line (Linux). The new line character of the 2nd line moved to the 2nd output file.

7. Split file with Kilobytes or Megabytes of data per OUTPUT file:

$ split -b 1k file
This will split the file with 1 KB of data per OUTPUT file. Similarly, to split the file with 1MB of data per OUTPUT file:
$ split -b 1m file
Note: The commands below use the option -n which is not available in all Unix flavors.

8. Split a file into 2 files of equal length:

$ split -n 2 -a 1 -d file F
At times, the requirement can be to split a file equally into 2 files, unlike earlier case where the split is based on number of lines per output file. The n option of split does this. By specifying the “-n 2”, the file is split equally into 2 files as shown below:
$ ls F*
F0  F1

$ cat F0
Unix
Linux
AIX
Solari

$ cat F1
s
HPUX
Ubuntu
Cygwin
Note: -n divides the file into equal lengths on the basis of the byte count of the files. As shown above, since the file has 42 characters, it is divided into 21 characters each.

9. Split file into 2 files with complete lines of output:

$ split -n l/2 -a1 -d file F
The option “-n l/2” enables to split on the basis of complete lines. And hence, the file F0 contains the complete 4th line “Solaris”, and the rest goes to the 2nd file.
$ ls F*
F0  F1

$ cat F0
Unix
Linux
AIX
Solaris

10. split command to display only a section of the file:

$ split -n 1/4  file
Unix
Linux
The option “-n 1/4” does not create any output files. It simply displays the file. 4 indicates to split the file into 4 equal parts or sections, and 1/4 indicates to write to stdout the 1st of the 4 sections. In other words, it displays the 1st part in the terminal. Similarly, to display the 2nd of the 4 parts:
$ split -n 2/4 file

AIX
Solar
Note: As seen above, the output does not contain complete lines. The split is done purely on the basis of equal byte count.
Split file with complete lines:
$ split -n l/1/4  file
Unix
Linux

$ split -n l/2/4  file
AIX
Solaris
By specifying the l option, the split is done at the completion of the line.