Skip to content

Instantly share code, notes, and snippets.

Let's say you have a Bash shell script, and you need to run a series of operations on another system (such as via ssh). There are a couple of ways to do this.

First, you can stage a child script on the remote system, then call it, passing along appropriate parameters. The problem with this is you will need to manually keep the remote script updated whenever you change it -- could be a bit of a challenge when you have something to execute on a number of remote servers (i.e., you have a backup script running on a central host, and it needs to put remote databases in hot backup mode before backing them up).

Another option is to embed the commands you want to run remotely within the ssh command line. But then you run into issues with escaping special characters, quoting, etc. This is ok if you only have a couple commands to run, but if it is a complex piece of Bash code, it can get a bit unwieldy.

So, to solve this, you can use a technique called rpcsh -- rpc in shell script, as follows:

First, place th

import os
import pprint
import fnmatch
import time
import subprocess
def find_services_needing_restart():
services = {}
pids = [ f for f in os.listdir('/proc') if f.isdigit() and os.path.isdir(os.path.join('/proc', f)) ]

How does ls work?

I wanted to be really able to explain to a fair amount of detail how does the program :command:`ls` actually work right from the moment you type the command name and hit ENTER. What goes on in user space and and in kernel space? This is my attempt and what I have learned so far on Linux (Fedora 19, 3.x kernel).

How does the shell find the location of 'ls' ?

@mrmichalis
mrmichalis / set-ssh.sh
Created September 17, 2014 02:24
Set SSH
#!/usr/bin/env bash
mkdir -p /root/.ssh
chmod 700 /root/.ssh
wget --no-check-certificate -nv 'https://github.com/mitchellh/vagrant/raw/master/keys/vagrant.pub' -O /root/.ssh/authorized_keys
wget --no-check-certificate -nv 'https://github.com/mitchellh/vagrant/raw/master/keys/vagrant' -O /root/.ssh/id_rsa
wget --no-check-certificate -nv 'https://github.com/mitchellh/vagrant/raw/master/keys/vagrant.pub' -O /root/.ssh/id_rsa.pub
chmod 600 /root/.ssh/authorized_keys /root/.ssh/id_rsa /root/.ssh/id_rsa.pub
chown -R root /root/.ssh
#!/bin/bash
# aeiocsr.bash
#http://pastebin.com/TaGAVJKw
#
# Script to auto-enroll an OS X 10.5 system via an AD CA's web enrollment.
#
# v. .2
@mrmichalis
mrmichalis / deploy_oracle.sh
Last active June 9, 2016 14:13
Deploy Oracle XE 11r2
# http://www.oracle.com/technetwork/database/database-technologies/express-edition/downloads/index.html
dd if=/dev/zero of=/tmp/swapfile bs=1024M count=2
mkswap /tmp/swapfile
free -m | grep Swap
swapon /tmp/swapfile
rpm -Uvh oracle-xe-11.2.0-1.0.x86_64.rpm
/etc/init.d/oracle-xe configure
. /u01/app/oracle/product/11.2.0/xe/bin/oracle_env.sh
sqlplus "sys as sysdba"
@mrmichalis
mrmichalis / main.py
Last active November 21, 2017 20:53 — forked from gear11/main.py
"""
A simple proxy server. Usage:
http://hostname:port/p/(URL to be proxied, minus protocol)
For example:
http://localhost:8080/p/www.google.com
"""
# source this code in a Bash shell ($ . django-csrftoken-login-demo.bash),
# and run with a DB name as parameter (e.g. $ django-csrftoken-login-demo demo)
django-csrftoken-login-demo() {
# -- CHANGE THESE VALUES TO MATCH YOUR ACCOUNT --
local HOSTING_USERID=9988
local HOSTING_PANEL_USER='[email protected]'
local HOSTING_PANEL_PASS='my secret login password'
local HOSTING_DB_PREFIX='username_'
local DB_NAME=$HOSTING_DB_PREFIX$1
@mrmichalis
mrmichalis / SSLPoke.java
Created October 9, 2015 21:05
Establish a SSL connection to a host and port, writes a byte and prints the response.
import javax.net.ssl.SSLSocket;
import javax.net.ssl.SSLSocketFactory;
import java.io.*;
/** Establish a SSL connection to a host and port, writes a byte and
* prints the response. See
* http://confluence.atlassian.com/display/JIRA/Connecting+to+SSL+services
* https://confluence.atlassian.com/download/attachments/117455/SSLPoke.java
*/
public class SSLPoke {
@mrmichalis
mrmichalis / centos_python_env_setup
Created October 20, 2015 16:10 — forked from floer32/centos_python_env_setup
CentOS 6: Install Python 2.7.4, pip, virtualenv, and virtualenvwrapper on CentOS (plus some bonus items at the end if you want). You should probably run with `sudo`.
#!/bin/bash
# Source: http://toomuchdata.com/2012/06/25/how-to-install-python-2-7-3-on-centos-6-2/
# Install stuff #
#################
# Install development tools and some misc. necessary packages
yum -y groupinstall "Development tools"
yum -y install zlib-devel # gen'l reqs