Generate a random string - really useful for random passwords for new user creation

>> Friday, 9 August 2019




cat /dev/urandom | strings --bytes 1 | tr -d '\n\t ' | head -c32

Read more...

Conditional awk - for when grep is finding duplicates

>> Friday, 12 July 2019

My files that contain information about my databases often look like this (It's a dirty way to maintain a database inventory on a server with multiple databases when the database product itself doesn't have a concept of inventory):


Mydatabasename:/path/to/product/home:/path/to/conf/myfile.conf
Anotherdatabasename:/path/to/product/home:/path/to/conf/myfile2.conf


When the database name appears in 2 lines of the file a simple grep would bring back multiple lines:

mydb=$1
DBHome=grep -w $1 ${myfilelistingdbs}| awk -F ":" '{print $2}'



So do THIS instead:

mydb=$1
awk -F ":" -vx=$mydb '$1==x {print $2}' ${myfilelistingdbs}


It says: if the first field matches this then tell me second field contents

this solves problem of db name popping up in a home path

e.g
database_cola:/data/database_pepsi/product:/data/database_pepsi/conf/database_cola.conf
database_pepsi:/data/database_pepsi/product:/data/database_pepsi/conf/database_pepsi.conf


A grep on database_pepsi returned two product homes (and upset my scripts expecting only one line!)
Awk on first field means you only get one product home returned

Read more...

How to change the attributes of a file in linux

>> Tuesday, 12 February 2019



I often want to change the timestamp of files when testing scripts so I can see whether the logic works with different ages of files etc.

use touch:


touch -a -m -t 201512180130.09 myfile


-a  change the access time
-m change the modification time
-t STAMP use [[CC]YY]MMDDhhmm[.ss] instead of current time


Read more...

  © Blogger template Simple n' Sweet by Ourblogtemplates.com 2009

Back to TOP