Skip to content

Instantly share code, notes, and snippets.

View pbrandiezs's full-sized avatar

Perry Brandiezs pbrandiezs

View GitHub Profile
@pbrandiezs
pbrandiezs / gist:0f8fc51f322df7a3fdf19d0b4f28d40f
Last active February 22, 2018 21:29
BASH - parse a config file and create users - sample code.
#!/bin/bash
SFTP_USERS="./sftp_users.txt"
cat ${SFTP_USERS} | while IFS='' read -r LINE || [[ -n "$LINE" ]]
do
ID=`echo $LINE|cut -d: -f1`
PASSWORD=`echo $LINE|cut -d: -f2`
NEWUID=`echo $LINE|cut -d: -f3`
NEWGID=`echo $LINE|cut -d: -f4`
if ! id -u ${ID} > /dev/null 2>&1; then
@pbrandiezs
pbrandiezs / docker_gists
Last active June 29, 2018 21:37
Quick docker command samples
Sample using a filter to run a command in the container:
docker exec `docker ps -q --filter name=frosty_goldberg` /bin/echo Hello
Start the container with a label:
docker run --label="the_label" -td ubuntu
Use the label to identify the container and run a command in it:
@pbrandiezs
pbrandiezs / do_I_have_ruby.rb
Created June 30, 2018 23:55
Do I have ruby?
puts "Yes, you have Ruby!"
@pbrandiezs
pbrandiezs / getIOWait.rb
Created July 10, 2018 20:34
Ruby example using %Q to parse iowait
def getIOWait
command_to_run = %Q[iostat 15 2 | awk 'BEGIN{RS=ORS="\\n\\n";FS=OFS="\\n"}/avg-cpu:/' | tail -2 | head -1 | awk {'print $4'}]
result = `#{command_to_run}`
# result = '20.0'
result.to_f
end
@pbrandiezs
pbrandiezs / checkport.rb
Created July 12, 2018 20:28
Check open ports from an array
require 'socket'
require 'timeout'
def is_port_open?(ip, port)
begin
Timeout::timeout(1) do
begin
s = TCPSocket.new(ip, port)
s.close
return true
@pbrandiezs
pbrandiezs / checkportWithArray.rb
Created July 23, 2018 23:10
Check open ports using an array
require 'socket'
require 'timeout'
def is_port_open?(ip, port)
begin
Timeout::timeout(1) do
begin
s = TCPSocket.new(ip, port)
s.close
return true
@pbrandiezs
pbrandiezs / PureAppGetIPAddr.py
Created October 9, 2018 23:17
Python code to get ipaddr in PureApp
#!/usr/bin/python
import json
from pprint import pprint
with open('/0config/network.json') as json_data:
d = json.load(json_data)
myNetworkInfo = d["networkInfo"]
# pprint(myNetworkInfo)
@pbrandiezs
pbrandiezs / run_each.pp
Created November 30, 2018 22:32
Puppet example of iterating through using each
$values = ['aaa', 'bbb', 'ccc', 'ddd']
$values.each | String $value | {
notify { $value:
message => "Value is ${value}"
}
}
@pbrandiezs
pbrandiezs / file_mode.pp
Created November 30, 2018 22:39
Puppet example code using a selector to set the mode of a file.
$file_mode = $facts['os']['family'] ? {
'Debian' => '0600',
'RedHat' => '0655',
default => '0700',
}
file { '/tmp/test_mode.txt':
ensure => file,
mode => $file_mode,
owner => 'root',
@pbrandiezs
pbrandiezs / file_dependencies.pp
Created November 30, 2018 22:45
Puppet code example showing dependencies
group { 'file_group':
ensure => present,
}
user { 'file_user':
ensure => present,
gid => 'file_group',
}
file { '/tmp/my_files':