Rename Logical Volumes Redhat 6 7

I had to rename a bunch of logical volumes and filesystems. This script is based on the lvrename command. It will go line by line of the fs file formated cat fs oldfs01a:newfs01b oldfs02a:newfs02b oldfs03a:newfs03b In my case the lvname and fs were were similar except for the last three characters. It will umount the […]

repeat scp x number of times

Create an empty 500m file ( linux ) # truncate –s 500m 500mb.file Copy a file 10 times in a row via a loop. for X in {1..10} do scp -p -r 500m.file myhost:/tmp done

ssh script hanging

I had an issue where an ssh loop script was exiting after 1 host. The fix use the -n flag. Ensure ssh isn’t reading from standard input by using the -n option: ZFSHEALTH=`/usr/local/bin/ssh -n $MACHINE “/sbin/zpool get health rpool” | grep ONLINE | wc -l`

The nc command

To test a connection use nc # nc -vz myhost 22 -w 15 > /dev/null 2>&1 -w 15 is the timeout Will return 0 if the host connects on ssh port 22 or 1 if it does not connect. Updated: 03/29/2016 The new update to the nc command takes this option away. Instead the following […]

Add basic options to script

#!/bin/bash if [ $# -ne 1 ] then echo “Usage: $0 ” exit 0 fi host=$1 If no hostname is specified output will be: ./1.myscript.bash Usage: ./1.myscript.bash

Shell Script : Calculate Between Two Days

I tested this on LINUX Use as you please. # date Mon May 18 16:16:29 EDT 2015 # date ‘+%s’ -d “now” 1431980193 # date ‘+%s’ -d “May 18 2014” 1400385600 # echo $(( (1431980193 – 1400385600) / 86400 )) 365

awk substitution using gsub

Handy gsub examples: Removing the trailing % in the 5th field. # echo “1 2 3 4 85%” | awk ‘/%/{gsub( /%/,” “,$5); print}’ 1 2 3 4 85 /%/ operate only on lines with a % (this means empty lines are skipped) gsub(a,b,c) match the regular expression a, replace it with b, and do all […]

best find command

This is just one of the best find statements I have ever seen. # find /sbin -xdev -type f -size +1024 -exec ll {} \; | awk ‘{print $9, $5}’ | sort -rn +1 | awk ‘{print $1, $2/1024/1024 “MB”}’ | more /sbin/powermig 2.67188MB /sbin/powercf 1.70703MB /sbin/emc/emcpmgr 1.58984MB /sbin/vxdisk 1.50439MB /sbin/vxdg 1.45749MB /sbin/vxrelayout 1.37262MB /sbin/vxrecover […]

awk : print column if it contains certain text

The following awk statement will print any user id that has a group id of 3. In other words if the number in column 4 is a 3 , print column 1. # awk -F: ‘{if ($4 ==”3″) print $1}’ /etc/passwd root sys uucp $0 will print the entire line if the group id is […]


HANDY ONE-LINERS FOR AWK 22 July 2003 compiled by Eric Pement version 0.22 Latest version of this file is usually at: USAGE: Unix: awk ‘/pattern/ {print “$1”}’ # standard Unix shells DOS/Win: awk ‘/pattern/ {print “$1”}’ # okay for DJGPP compiled awk “/pattern/ {print “$1″}” # required for Mingw32 Most of my experience comes […]