Find Your Happy Balance

I’ll start by acknowledging that this newsletter comes out randomly without a schedule…  From time to time someone asks .. “Why don’t you send out weekly newsletters or send emails on a regular schedule?” Initially, I tried to be like the “big guys,” sending out 4+ weekly emails. Great for them and glad it works for […]

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 https://mysite.com/wp-admin/post-new.php?post_title=mytitle&category=mycat 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 […]