Skip to content

Instantly share code, notes, and snippets.

View omar-yassin's full-sized avatar

Omar Yassin omar-yassin

View GitHub Profile
# 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: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)
@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: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: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:37d08da804da6e7c7787
Created May 6, 2015 15:15
Powershell: Install Patches Example
# This script will first install the "PSWindowsUpdate" PS Module and then install KBs we specify in this script
# KB_ID Description
# KB3042553 MS15-034 Critical: Vulnerability in HTTP.sys Could Allow Remote Code Execution - https://technet.microsoft.com/en-us/library/security/ms15-034.aspx
# TO DO make it more robust where we can pass kb articles by hash and loop check
$kb_to_patch="KB3042553"
$ps_windows_update_zip="C:\Windows\temp\PSWindowsUpdate.zip"
$ps_modules_dir="C:\Windows\System32\WindowsPowerShell\v1.0\Modules"
@omar-yassin
omar-yassin / gist:f25b5a17f0f7084eecfd
Created April 30, 2015 14:11
AWS EC2 Powershell Cheatlist
$EC2_launch_time = Get-Date (Get-EC2Instance -Instance $instanceId | % { $_.RunningInstance } | Select-Object -expand LaunchTime) -format "M/d/yyyy hh:mm:ss tt"
$Windows_bootTime = Get-Date (Get-CimInstance -ClassName win32_operatingsystem | select -expand lastbootuptime).tostring().trim() -format "M/d/yyyy hh:mm:ss tt"
@omar-yassin
omar-yassin / gist:97b281bb13ce74747f43
Last active August 29, 2015 14:08
awk-ing CSV with quotes with delimiter
gawk -vFPAT='[^,]*|"[^"]*"' '{print $1,$2,$3}'
@omar-yassin
omar-yassin / gist:2e480f12057eb8cdd52f
Created October 3, 2014 14:30
BASH: error catching pipes
tar ... | ssh ...
pipe_exit_status="${PIPESTATUS[@]}"
tar_status=`echo $pipe_exit_status | awk '{print $1}'`
ssh_status=`echo $pipe_exit_status | awk '{print $2}'`
@omar-yassin
omar-yassin / gist:666bdf8ef137b1a64d36
Created July 8, 2014 20:25
Namecheap: Dynamic DNS
python:
# -*- coding: utf-8 -*-
import urllib2
urllib2.urlopen("https://dynamicdns.park-your-domain.com/update?host=%s&domain=%s&password=%s" % ("SUBDOMAIN", "DOMAIN", "namecheap.dynamicDNS.PASSWORD"))