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 […]

Set category in link

Will allow adding category in page url Add to functions.php function set_category () { global $post; //Check for a category parameter in our URL, and sanitize it as a string $category_slug = filter_input(INPUT_GET, ‘category’, FILTER_SANITIZE_STRING, array(“options” => array(“default” => 0))); //If we’ve got a category by that name, set the post terms for it […]

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

crontab -e hangs

I have only seen this on solaris # crontab -e 446 simple fix # export EDITOR=vi

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 […]

Host key verification failed ssh scp using cron

I was getting the following error when a script was being executed via cron. Host key verification failed. lost connection But when the script was executed manually from the command line it worked without any issues. * This worked for me in my particular case. This may not work in every case. I added the […]