Skip to content

Instantly share code, notes, and snippets.

View omar-yassin's full-sized avatar

Omar Yassin omar-yassin

View GitHub Profile
@omar-yassin
omar-yassin / gist:83bdd9cbce2846a68d37
Created May 8, 2015 20:33
BASH SKELETON: Read from file from the last place you left off
## incomplete; just a guide so I can remember
$log_file
last_length = `cat /tmp/${log_file}_last_length`
current_legnth = 'wc -c $log_file'
if [[ $last_file_length > 0 ]] ; then
diff_length = current_length - last_length
if [[ diff_length >= 0 ]] ; then
@omar-yassin
omar-yassin / gist:1a042d7608a4b0fb6371
Last active August 29, 2015 14:23
Windows: Change service startup argument
sc.exe config $ServiceName start= "delayed-auto"
@omar-yassin
omar-yassin / gist:7cff92c999e71fb3184a
Created June 19, 2015 19:31
PowerShell: Dealing with XML
# load xml
[xml]$xml = `what evber out put that prints xml - or can load xml from file path`
# read xml contents
$xml.nodeName.ChildNodes
@omar-yassin
omar-yassin / gist:07caf8abfe843c7b8714
Created July 8, 2015 15:41
Powershell: Modifying XML
$path = 'C:\omar\Web.config'
$xml = [xml](Get-Content $path)
$UseWebResourceCDN=$xml.configuration.appSettings.add | where {$_.key -eq 'UseWebResourceCDN'}
$UseWebResourceCDN.Value = 'True'
$xml.save($path)
# prints stdout and logs to file
function logger ()
{
echo "${1}" | tee -a $LOG_FILE
}
# function to wrap errors and exit
# USAGE: rc=${PIPESTATUS[0]} ; check_return_value
rc=0
function check_return_value
@omar-yassin
omar-yassin / gist:a88a7b610c5356b039cc
Created August 24, 2015 18:19
SED: Convert New Lines to \n (to keep new lines in JSON)
sed ':a;N;$!ba;s/\n/\\n/g'
@omar-yassin
omar-yassin / gist:223f7904e27738e3b2e3
Created August 26, 2015 18:52
AWS CLI SES send-email
# email using aws ses
function send-email ()
{
email_message="/tmp/email_message"
email_cleanup="/tmp/email_cleanup"
email_destination="/tmp/email_destination"
# we need to clean up our logs so we can send via json; remove new line and quotes
# and I don't understand the bash issue with running cat | sed in the $email_message declaration. Fun TODO to understand why?
cat $LOG_FILE | sed ':a;N;$!ba;s/\n/\\n/g' | tr -d '"' > $email_cleanup
select key/value
aws --profile xxx --output json ec2 describe-instances --instance-ids i-xxxxxx | jq -r '.Reservations[].Instances[].Tags[] | select(.Key | contains("computername")) | .Value'
@omar-yassin
omar-yassin / gist:49252a62e45cbf49b641
Last active March 9, 2023 19:09
SUDOERS cheatsheet
# REMEMBER TO USE VISUDO - you can potentially lock yourself out if sudoers file has parse error
# change visudo editor to VIM
Defaults editor=/usr/bin/vim
# example of /etc/sudoers.d/lbbackup
Cmnd_Alias LS_HARDWARE = /usr/bin/lshw
Cmnd_Alias MOUNT_UDF = /bin/mount -oloop\,rw *
Cmnd_Alias UNMOUNT_UDF = /bin/umount /data/TEMP_UDF_DIR/MOUNT_UDF
@omar-yassin
omar-yassin / gist:5d3ad496d570b35a721e
Created September 24, 2015 19:17
# Install chef-server
# ON SERVER:
1. install chef-server
2. intialize new chef instance `sudo chef-server-ctl reconfigure`