Alpha
Share and Organize Code
login register
HotNewTop
F.A.Q.
1. To begin adding code first register.
2. Create your own tags for code that you add.
3. To see your own code click Me, to see all code click Everyone, or filter by people rob.
4. To follow a user, click on their username, rob and hit follow.
5. Add other code to your library by clicking the
button near the code titles (note that you can not edit these codes).
6. To create a copy of a code that you can edit use fork.
7. If you can't find your code, double check your filter settings as you can filter by Category, User and Tag simultaneously.
8. Add comments to a code by clicking on it's title or the comments link underneath it.

File Descriptor Limit (plain)

1
2
3
4
5
6
7
8
9
10
11
12
# Total file descriptor limit
sysctl fs.file-nr
# User limit
ulimit -Hn
# Find out how many file descriptors are in use by user
sudo lsof -u <username> 2>/dev/null | wc -l

# Increase file descriptor limit for a user
echo "username hard nofile 64000" >> /etc/security/limits.conf
echo "ulimit -n 64000" >> /home/username/.bashrc ; echo "ulimit -n 64000" >> /home/username/.bash_profile*

# tested in centos
[+] (8) more...
comments (1) flag fork

Remove Comments and Empty Lines (plain)

1
2
3
4
5
6
7
# Example using /etc/my.cnf to easily view DB config in Linux
grep -v -e ^# -e ^$ /etc/my.cnf

# copy to new file...
grep -v -e ^# -e ^$ /etc/my.cnf > /etc/my-nocomments.cnf

# tested in bash amazon ec2 instance ubuntu 12.04
[+] (3) more...
comments (0) flag fork

Bash While Loop (plain)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#!/bin/bash
# Tested & Created in CentOS

ENVARRAY=(
dev
qa
prd
)

ENV=${#ENVARRAY[*]}
i=0

while [ $i -lt $ENV ]; do
        echo "${ENVARRAY[$i]}"
let i++
done

# Output will be
# dev
# qa
# prd
[+] (17) more...
comments (0) flag fork

Top 3 Processes Using RAM (plain)

1
2
3
4
# after using free -m OR free -g ... you may like to know what's using up the RAM:
ps auxf | sort -nr -k 4 | head -3

# Tested / used on Ubuntu and CentOS
comments (0) flag fork

SSH - Convert Win Pub Key to Linux (plain)

1
2
3
4
5
6
7
# This assumes you generated a keypair on a Windows client with puttygen for a Linux server
ssh-keygen -i -f ~/.ssh/id_rsa_win.pub > ~/.ssh/id_rsa.pub
# OR convert it and add it directly to ~/.ssh/authorized_keys file on Linux server
ssh-keygen -i -f ~/.ssh/id_rsa_win.pub >> ~/.ssh/authorized_keys

# SSH key pair notes:
# PUB key always goes on server / PRIVATE key saved on local client
[+] (3) more...
comments (0) flag fork

Monitor Network, Disc, CPU, RAM Simultaneously (plain) (source)

1
2
3
4
# --- Install dstat: Improved systat like system monitoring tool
dstat -talm

# --- Very useful for any Sys Admin
comments (1) flag fork

Execute Shell Script on Multiple Servers from 1 Host (plain)

1
2
3
4
5
6
7
8
9
# Bash Script
ssh -p 22 user@remotehost exec /bin/bash -s "$LE_PATH" < /usr/local/bin/shellscript
# Perl Script
ssh -p 22 user@remotehost exec /bin/perl -s "$LE_PATH" < /usr/local/bin/shellscript

# --- If you have a script you normally execute locally on a machine and you want to run your scripts on multiple machines from a centralized location, this is a good method.
# --- Just ensure you have key pair access set up accordingly between machines
#
#
[+] (5) more...
comments (1) flag fork

Monitor Who's on Server (plain)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#!/bin/bash
# --- Script: /usr/local/bin/monitor-who
# --- Author: Paul Greene
# --- Objective: Monitor who's on local server (NODE1) and a remote server (NODE2), from local
# --- server and log it on NODE1
# --- PRE-REQUISISTE: SSH key pair access NEEDS to be set up between NODE1 and NODE2
WHONODE1=`/usr/local/bin/security-who`
WHONODE2=`ssh -p 22 monitor@192.168.1.11 exec /bin/bash -s "$LE_PATH" < /usr/local/bin/security-who`
echo "NODE1: $WHONODE1" | /usr/local/bin/timestamp | tee -ai /var/log/monitor-security-who.log
echo "NODE2: $WHONODE2" | /usr/local/bin/timestamp | tee -ai /var/log/monitor-security-who.log

#!/bin/bash
# --- Script: /usr/local/bin/timestamp
# --- Author: Paul Greene
# --- Objective: Act as a timestamp for log output
while read line ; do
    echo "$(date): ${line}"
done

#!/bin/bash
# --- Script: /usr/local/bin/security-who
# --- Author: Paul Greene
# --- Objective: Capture who's on the server
who -u --lookup

# Enjoy!
[+] (22) more...
comments (1) flag fork

Network Test (plain)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#!/bin/bash
# --- Script: /usr/local/sbin/commtest
# --- Permissions: Ensure you execute 'chmod 0700 commtest'
# --- Author: Paul Greene
# --- Objective: Verify ports are open to or on your server for applications to run
# --- Notes: This will simply output PASS or FAILED. Ensure nmap is installed.

# --- Verify Network communication is open to your MySQL Database
echo ""
echo "TEST 1 - Verify Network communication is open to DB"
portchk=`nmap -v -p 3306 localhost | awk '{print $2}' | awk 'NR==6'`
if [ "$portchk" = "open" ]; then
        echo "MySQL port 3306 is open to web server ...PASSED"
else
        echo "MySQL port 3306 is closed to web server ...FAILED"
fi
[+] (12) more...
comments (1) flag fork