#_ITandME blog

March 28, 2019: Running list of *nix scripts I find useful...

Getting password expiration date using 'chage' command

echo $j $(ssh -t -o "BatchMode yes" $j 'sudo chage -l $(for i in $(who); do echo $i | grep ""; done) | grep "Password expires"')

Getting password last change data using 'who' and 'passwd' command

echo $j $(ssh -t -o "BatchMode yes" $j sudo passwd -S $(for i in $(who); do echo $i | grep "USERID"; done)

Bind a remote port to my localhost over SSH...in this case while pivoting through another server

ssh -L localport:remotehostIP:remoteport username@pivothost

NOTE: This connection allows one to 'double-back' on devices like routers from inside the "trusted" network: After authentication, point browser to 'localhost:80' to access a webconsole, but can be used for other ports/protocols.

List all file owners in directory, then rip their ID info...

for owner in $(ls -alR | awk -F ' ' '{print $3}' | sort -u); do grep $owner /etc/passwd; grep $owner /etc/shadow; grep $owner /etc/group; echo "---------------"; done

List the number of files owned by each creator in a particular directory

for owner in $(ls -alR | awk -F ' ' '{print $3}' | sort -u); do echo $owner" has "$(ls -alR | grep $owner | wc-l); done

SOLARIS

Getting password last change data useing 'who' and 'passwd' command

echo $j $(ssh -t -o "BatchMode yes" $j sudo passwd -s $(for i in $(who); do echo $i | grep ""; done)

Random pieces...

# Getting list of unique IP hits on Apache webserver

sudo /var/log/apache2/cat other_vhosts_access.log | awk -F ' ' '{print $1" "$2}' | uniq

# Getting more detailed IP hit info on Apache webserver

sudo cat /var/log/apache2/other_vhosts_access.log | awk -F ' ' '{print $1" "$2$5}' | tr '[' ' '

# AWK using a single quote dilimeter

awk -F "\'" '{print $1}'

Here are some commands for cleanly replacing a virtual Linux FS with a smaller one. EXT filesystems can be shrunk, but NOT XFS.

Note! Data distructive!

		
		# umount /u01
		# lvremove /dev/mapper/vg0-u01
		# vgreduce vg0 /dev/sdb1
		# pvremove /dev/sdb1
		# fdisk /dev/sdb
		d
		w
		Hypervisor: Delete vdisk
		Hypervisor: Add smaller vdisk
		# fdisk /dev/sdb
		n
		p (accept defaults)
		t
		8e
		w
		# pvcreate /dev/sdb1
		# vgextend vg0 /dev/sdb1
		# lvcreate -n u01 -L250G vg0
		# mkfs.xfs /dev/mapper/vg0-u01
		# mount -a
		# df -h (check your work)