Skip to content

Instantly share code, notes, and snippets.

@dcaughill
dcaughill / chef-cheatsheet.sh
Last active January 14, 2019 20:37
chef_cheatsheet.sh
#Uninstalling chef on CentOS
sudo yum remove -y chef.x86_64
sudo rm -rf /var/chef; sudo rm -rf /etc/chef; sudo rm -rf /opt/chef
@dcaughill
dcaughill / terraform_cheatsheet.sh
Created October 22, 2018 21:54
terraform_cheatsheet
# Removing a borked terraform lock
terraform force-unlock bcf8815f-53db-ad60-45d5-488829a83e5d
@dcaughill
dcaughill / crontabTricks.sh
Created August 20, 2018 21:25
cron and crontab tricks
#Nightly crontab cleanup of docker images with a 36 hour rentention window
# To implement:
# 1. > sudo crontab -e
# 2. insert the following into the crontab file to implement cleanups at 7 am server local time
0 7 * * * /usr/bin/docker image prune -a --force --filter "until=36h"
#3 Verifly successful run in log at: /var/spool/cron
@dcaughill
dcaughill / chmod-chown.sh
Created August 17, 2018 19:01
chmod and chown
//Change owning user and group of file
sudo chown centos:centos main-config.xml
//Give read privs to user
chmod u+r main-config.xml
//Give write/update privs to user
chmod u+u main-config.xml
//Give execute privs to user
chmod u+x main-config.xml
//Find the name of the related process by PID
ps -p 1234 -o command=
////journalctl////
//Reference: https://www.digitalocean.com/community/tutorials/how-to-use-journalctl-to-view-and-manipulate-systemd-logs
//Display n number of most recent journalctl entries (with paging)
journalctl -n 500
//Display n number of most recent journalctl entries (no paging, starting with most recent)
journalctl | tail -n 500
@dcaughill
dcaughill / DBCC_DBInfo_Dump.sql
Created June 7, 2018 14:03
Quick and dirty dump of DBCC DBINFO() for each DB on the instance
CREATE TABLE dbo.DBCCInfoDump (ID INT IDENTITY(1,1),parentInfo VARCHAR(256), Object VARCHAR(256), field VARCHAR(256), value VARCHAR(256))
GO
sp_msforeachdb @command1 = 'INSERT INTO DBCCInfoDump (parentInfo, Object, field, value)
EXEC (''DBCC DBINFO(?) WITH TABLERESULTS'')'
@dcaughill
dcaughill / checkBackupAndRestoreStatus.sql
Created June 7, 2018 14:03
Check MS SQL Server database Restore/Backup status
--Check Database Restore/Backup status
SELECT percent_complete,
session_id,
start_time,
status,
command,
wait_type,
last_wait_type
FROM sys.dm_exec_requests
@dcaughill
dcaughill / pyMongoAuthTest.py
Created June 7, 2018 14:02
Testing MongoDB auth: SCRAM-SHA-1
from pymongo import MongoClient
#setup connection
uri = "mongodb://testUser:xyz123@localhost/testDB?authMechanism=SCRAM-SHA-1"
client = MongoClient(uri)
db = client.TestDB
#setup query
cursor = db.TestCollection.find().limit(10)
--Find the last IDENTITY value generated for each table in a database
set nocount on
create table #CurrentIdentValues (tableName varchar(100), curIdent bigint)
exec sp_MSforeachtable 'insert #CurrentIdentValues select ''?'', IDENT_CURRENT( ''?'' )';
select * from #CurrentIdentValues
ORDER by curIdent desc;