NetApp - Copy LUN mappings

Well, today I had another idea (basically like the one I wrote for SVC’s VDisk mappings a while back) for a script: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 #!/bin/bash KEY_FILE="/root/.ssh/netapp.dsa" SSH_OPTS="/root/.ssh/netapp-ssh_config" if [ $# -ne 3 ] ; then echo "fas-copy-lunmap: FAS_CONTROLLER SOURCE_IGROUP TARGET_IGROUP" echo echo "Copy the LUN map from one igroup to another, ie for ESX reinstallation" echo echo " Usage:" echo " - FAS_CONTROLLER: Hostname/IP-adress of the DATA ONTAP controller" echo " - SOURCE_IGROUP: igroup that is used as a reference for the copy process" echo " - TARGET_IGROUP: igroup that is actually modified" echo exit 1 fi FAS_CTRL=$1 SOURCE=$2 TARGET=$3 ssh_fas() { # $@: commands for Data ONTAP COMMANDS="$@" /usr/bin/ssh -i $KEY_FILE -l root -F $SSH_OPTS $COMMANDS } #set -x # Get the lun list. for lun in $( ssh_fas $FAS_CTRL lun show -g $SOURCE | awk '{ print $1 }' | sort -u ); do # Get the LUN number its mapped LUN_ID="$( ssh_fas $FAS_CTRL lun show -m $lun | grep "^/vol" | awk '{ print $3 }' )" # If the LUN id is 0, skip otherwise we would copy the boot LUN if [ "$LUN_ID" != "0" ] ; then # Actually map the lun to our host echo "Mapping $lun to $TARGET as LUN_ID $LUN_ID" ssh_fas $FAS_CTRL lun map $lun $TARGET $LUN_ID fi done #set +x I’ll post the counterpart of the script (to remove the LUNs) in a second post later on.

August 8, 2014 · 2 min · 279 words · christian

NetScaler: Generate a simple usage statistic per Vserver

One of my co-workers recently approached me, that he needed a simple shell script which would generate a simple report about a Vserver’s current connections. After ironing out a few things with him (he had the intention of it being on a CIFS share on our file-server - which I changed to a simple HTML page) I went to work. Out came two scripts. One is the collection instance, and the other is the processing instance. First the collection script runs, finds the current HA master node and then collects the Vserver’s current connections. After that script has dumped the information (date, time, current connections) into a file, the processing script will go and create a simple HTML page that’ll show exactly those informations. ...

November 21, 2013 · 4 min · 820 words · christian

Finding files bigger than 20MiB

Well, up till now I’ve been using du -sh * | grep G, however that didn’t quite do what I wanted. So I looked at the manpage of find a little bit today, and I found this: 1 find . -type f -size +20000k -exec ls {} ; | sort

December 15, 2012 · 1 min · 50 words · christian

NetApp - Get a list of volumes containing too much LUNs

Well, after figuring things out (and realizing that if you create a LUN in the same size as the volume it’ll break), I decided to write yet another script to figure out which LUNs needed fixing. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 #!/bin/bash KEY_FILE="/root/.ssh/netapp.dsa" SSH_OPTS="/root/.ssh/netapp-ssh_config" FAS_CTRL=$1 ssh_fas() { # $@: commands for Data ONTAP COMMANDS="$@" /usr/bin/ssh -i $KEY_FILE -l root -F $SSH_OPTS $COMMANDS } for volume in $( ssh_fas $FAS_CTRL vol status | grep "vol.* online" | awk '{ print $1 }' ); do VOL_SIZE="$( ssh_fas $FAS_CTRL vol size $volume | awk '{ print $8 }' | sed "s,.,," )" VOL_UNIT_PARAM="$( echo "${#VOL_SIZE} - 1" | bc )" VOL_UNIT="${VOL_SIZE:$VOL_UNIT_PARAM:1}" case $VOL_UNIT in k) CONV="1024";; m) CONV="1024 * 1024";; g) CONV="1024 * 1024 * 1024";; esac VOL_SIZE="$( echo "scale=0; ${VOL_SIZE/$VOL_UNIT/} * $CONV" | bc )" # Subtract the snap reserve (if any) SNAP="$( ssh_fas $FAS_CTRL snap reserve $volume | cut -d -f7 | sed "s,%,," )" if [ $SNAP -gt 0 ] ; then SNAP_SIZE="$( echo "$VOL_SIZE * $SNAP / 100" | bc )" REMAINING_VOL_SIZE="$( echo "$VOL_SIZE - $SNAP_SIZE" | bc )" else SNAP_SIZE=0 REMAINING_VOL_SIZE=$VOL_SIZE fi # Get the luns created inside the volume LUN_SIZE_TOTAL=0 for lunsize in $( ssh_fas $FAS_CTRL lun show -l ${volume} | awk '{ print $3 }' | sed -e "s,(,," -e "s,),," ); do LUN_SIZE_TOTAL="$( echo "$LUN_SIZE_TOTAL + $lunsize" | bc )" REMAINING_VOL_SIZE="$( echo "$REMAINING_VOL_SIZE - $lunsize" | bc )" done # Get the estimated space necessary. VOL_RESERVE="$( echo "$VOL_SIZE * 3 / 100" | bc )" echo " VOL_NAME: $volume" echo " VOLUME_SIZE: $( echo "scale=2; $VOL_SIZE / 1024 / 1024 / 1024" | bc )G" echo " - SNAP_SIZE: $( echo "scale=2; $SNAP_SIZE / 1024 / 1024 / 1024" | bc )G" echo " SUB_TOTAL: $( echo "scale=2; ($VOL_SIZE - $SNAP_SIZE) / 1024 / 1024 / 1024" | bc )G" echo echo " - TOTAL_LUN_SIZE: $( echo "scale=2; $LUN_SIZE_TOTAL / 1024 / 1024 / 1024" | bc )G" echo " SUB_TOTAL: $( echo "scale=2; ($VOL_SIZE - $SNAP_SIZE - $LUN_SIZE_TOTAL) / 1024 / 1024 / 1024" | bc )G" echo echo " MISSING_SPACE:" DIFFERENCE_VOL_LUN="$( echo "scale=2; ($VOL_SIZE - $SNAP_SIZE - $LUN_SIZE_TOTAL)" | bc | sed "s,-,," )" echo " DIFFERENCE_VOL_LUN: $( echo "scale=2; $DIFFERENCE_VOL_LUN / 1024 / 1024 / 1024" | bc )G" echo " + VOL_RESERVE: $( echo "scale=2; $VOL_RESERVE / 1024 / 1024 / 1024" | bc )G" echo " SUB_TOTAL: $( echo "scale=2; ($DIFFERENCE_VOL_LUN + $VOL_RESERVE) / 1024 / 1024 / 1024" | bc )G" echo echo echo done And with that you have a list of volumes, with the amount of space they need to resized in order to accomodate the contained LUNs and the snapshots.

June 8, 2012 · 3 min · 501 words · christian

Convert a bunch of PDF documents to JPEG

Well, I found a bunch of PDF documents on my disk today, which I wanted converted to JPEG. Now, Debian replaced ImageMagick in the past for GraphicsMagick, which is supposedly a bit faster and leaner than ImageMagick. So first you need to install graphicsmagick – or rewrite the script to use /usr/bin/convert instead. The script basically takes every .PDF you have in your current working directory, creates a sub-directory, and then extracts each page of the PDF into a single JPEG image in that subdirectory. ...

February 15, 2012 · 2 min · 242 words · christian

Handling files/directories with spaces in `for'-loops

So I have one or the other file, that needs to be extracted to a directory. And why not name it as the archive itself .. Only problem with it is the handling of variables with bash … Try it yourself, stuff some directories with a space in inside a variables, and use something like this: 1 2 3 epimetheus tmp [0] $ mkdir files epimetheus tmp [0] $ touch files/"I hate directories.archive" files/"Me luuv you looong time.archive" epimetheus tmp [0] $ for i in $( /bin/ls --color=none files/ ); do mkdir "${i/.archive/}"; done And now take a look at the output of that .. ...

July 8, 2007 · 1 min · 199 words · christian