Skip to content

Instantly share code, notes, and snippets.

View rcmorano's full-sized avatar
🏠
Working from home

Roberto C. Morano rcmorano

🏠
Working from home
View GitHub Profile
@rcmorano
rcmorano / export-users-logon.bat
Created November 30, 2011 12:20
Backup your Active Directory users' logon scripts
@echo off
rd c:\users-logon-dump /q /s
md c:\users-logon-dump
setlocal ENABLEDELAYEDEXPANSION
set qry=dsquery * -filter "(scriptPath=*)" -attr cn,scriptPath -limit 0
for /f "Skip=1 Tokens=*" %%a in ('%qry%') do (
set rawline=%%a
@rcmorano
rcmorano / upload_chef_databag.rb
Created December 20, 2011 12:45
Create a databag through Chef's REST API
#!/usr/bin/ruby
require 'chef/config'
require 'chef/log'
require 'chef/rest'
$chef_server_url = "https://localhost"
$client_name = "chef-admin"
$signing_key_filename="/root/.chef/chef-admin.pem"
@rcmorano
rcmorano / mu
Last active December 14, 2015 07:49
'mu' is a simple script to get real memory usage (not VSZ, not RSS but PSS) of a given PID or process pattern (uses pgrep).Check these didactic URLs for a nice explanation about memory consumption [1] and cache [2]:[1] http://emilics.com/blog/article/mconsumption.html[2] http://blog.scoutapp.com/articles/2010/10/06/determining-free-memory-on-lin…
#!/bin/bash
#
# Copyright (C) 2013, Roberto C. Morano <rcmova@gmail.com>
#
# This software is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This software is distributed in the hope that it will be useful,
@rcmorano
rcmorano / mutop
Last active December 14, 2015 07:49
'mutop' uses my other script 'mu' to sort any process listed in "ps aux" by memory usage. The last, the most [memory consumer]. COPY PASTE TO DOWNLOAD: wget -O /tmp/mutop.tgz https://gist.github.com/rcmorano/5053427/download; sudo mv /tmp/$(tar zxvf /tmp/mutop.tgz -C /tmp |grep mutop) /usr/local/bin/; sudo chmod +x /usr/local/bin/mutop
#!/bin/bash
#
# Copyright (C) 2013, Roberto C. Morano <rcmova@gmail.com>
#
# This software is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This software is distributed in the hope that it will be useful,
@rcmorano
rcmorano / .bash_aliases
Last active November 24, 2021 16:37
'.bash_aliases' useful bits (recopilation)
# do not check certs when connecting thru ssh NOTE: you shouldn't use it as default
alias ssh-no-check='ssh -o StrictHostKeyChecking=no'
# 'ps' that shows cgroupped processes
#
# check url for more info: http://0pointer.de/blog/projects/systemd-for-admins-2.html
#
alias psc='ps xawf -eo pid,user,cgroup,args'
# docker
@rcmorano
rcmorano / .gitconfig
Last active April 26, 2021 06:00
my '.gitconfig' that uses https://github.com/SixArm/sixarm_git_gitconfig HOW TO USE: copy-paste to download: wget --no-check-certificate -O /tmp/gitconfig.zip "https://gist.github.com/rcmorano/5056379/download"; mv $(unzip /tmp/gitconfig.zip -d /tmp/|grep inflating.*gitconfig|awk '{print $NF}') ~/.gitconfig
[user]
name = Roberto C. Morano
email = rcmova@gmail.com
[include]
path = ~/.gitconfig.d/alias.txt
path = ~/.gitconfig.d/alias-for-cvs.txt
path = ~/.gitconfig.d/alias-for-gitk.txt
path = ~/.gitconfig.d/alias-for-rails.txt
path = ~/.gitconfig.d/alias-for-svn.txt
@rcmorano
rcmorano / chef-server-bootstrap.sh
Last active January 4, 2016 14:48
Debian 'chef-server' bootstrap script that deploys with rvm, librarian (automagical cookbook download) and chef-solo. It's supposed to be easily maintenable since it completely relays on community cookbooks :] COPY PASTE: wget -O /tmp/bootstrap.tgz https://gist.github.com/rcmorano/5056474/download; bash /tmp/$(tar zxvf /tmp/bootstrap.tgz -C /tmp…
#!/bin/bash
CHEF_REPO=/var/lib/chef-repo
CHEF_FILE=/tmp/Cheffile; test -d $(dirname $CHEF_FILE) || mkdir -p $(dirname $CHEF_FILE)
SOLO_RB=/etc/chef/solo.rb; test -d $(dirname $SOLO_RB) || mkdir -p $(dirname $SOLO_RB)
SOLO_JSON=/etc/chef/solo.json; test -d $(dirname $SOLO_JSON) || mkdir -p $(dirname $SOLO_JSON)
GEM_PREDEPENDS="librarian chef"
RVM_RUBY_VER=1.9.2
# changed rvm installation from rvm-cookbook to rvm.io scripts again
@rcmorano
rcmorano / awk-print-column-if
Created May 10, 2013 19:53
Print a column selectively with #awk. Think about it like selecting a complete row (or just a column) when a column in the row matches your needs.
awk -F: '$NF == "/bin/tcsh" {print $1}' /etc/passwd
awk -F: '$1 == "johndoe" {print $1}' /etc/passwd
# Postfix stuff
QUEUEID (?:[A-F0-9]+|NOQUEUE)
EMAILADDRESSPART [a-zA-Z0-9_.+-=:]+
EMAILADDRESS %{EMAILADDRESSPART:local}@%{EMAILADDRESSPART:remote}
RELAY (?:%{HOSTNAME:relayhost}(?:\[%{IP:relayip}\](?::[0-9]+(.[0-9]+)?)?)?)
#RELAY (?:%{HOSTNAME:relayhost}(?:\[%{IP:relayip}\](?:%{POSREAL:relayport})))
POSREAL [0-9]+(.[0-9]+)?
#DELAYS %{POSREAL:a}/%{POSREAL:b}/%{POSREAL:c}/%{POSREAL:d}
DELAYS (%{POSREAL}[/]*)+
DSN %{NONNEGINT}.%{NONNEGINT}.%{NONNEGINT}
@rcmorano
rcmorano / focus-on-window
Last active December 20, 2015 23:28
get focus on a window that matches the process name pattern defined by $WINDOW_PROCESS_PATTERN and if it's already focused, minimizes it## IT DEPENDS ON 'wmctrl' and 'xdotool' packages ##
#!/bin/bash
#
# Copyright (C) 2013, Roberto C. Morano <rcmova@gmail.com>
#
# This software is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This software is distributed in the hope that it will be useful,