Last active
September 19, 2017 08:57
-
-
Save thonixx/2f9050cc60323ff134653713938e1480 to your computer and use it in GitHub Desktop.
One liner collection (and short things)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# open gist for oneliner (or very short bash things) collection |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Anti-HTTP-DoS iptables rule | |
iptables -A INPUT -p tcp --syn --dport 80 -m connlimit --connlimit-above 30 -j REJECT --reject-with tcp-reset | |
# this will reject http traffic if there are more than 30 per second |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Batch multi password change for users | |
for u in user1 user2 user3 user4; do pw="$(apg -m8 -x8 -n1 -a0 -MNCL)"; echo -e "Benutzername: $u\nPasswort: $pw"; echo "$u:$pw" | chpasswd; sleep 0.5; echo ""; done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Block IP ranges of Facebook | |
for i in $(whois -h whois.radb.net '!gAS32934' | head -n2 | tail -n1); do sudo iptables -A OUTPUT -d $i -j REJECT; done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Check PDNS database for corrupt entries (non-ASCII records) | |
mysql pdns -e "select * from records where content <> convert(content using ASCII);" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Check SPF lookup errors and also check for already whitelisted IP addresses | |
for ip in `grep -i spf /var/log/mail.log | grep -i lookups | grep -i rejec | awk -F\[ '{print $3}' | awk -F\] '{print $1}' | sort | uniq`; do if [ ! -d "/var/lib/tumgreyspf/config/client_address/`echo $ip | tr "." "/"`" ] ; then echo "IP $ip -> `host $ip | awk '{print $5}'`" ; fi; done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Date evaluation in cronjob command | |
/path/to/script | mail -s "Subject with calendar week `date +\%V`" recipient@domain.tld |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Get default outbound IP address | |
ip addr show dev $(ip route show | grep default | awk '{print $5}') | grep inet | awk '{print $2}' | awk -F\/ '{print $1}' | head -n 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if var['something'].respond_to?('each') | |
puts "It is an array" | |
else | |
puts "It is not an array" | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Fast, secure and convenient way to transfer a secret key to another server | |
gpg --export-secret-key --armor <your key id> | ssh <remotehost> gpg --import |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Find X-PHP-Originating-Script headers in /var/spool/postfix | |
find /var/spool/postfix/ -type f -exec grep -l X-PHP {} \; | cut -d / -f 7 | xargs -n1 postcat -q | grep X-PHP | |
# OR: Search for "X-PHP-Originating-Script" in all undelivered Postfix mails | |
grep -rinl "X-PHP-Originating-Script" /var/spool/postfix | xargs -n 1 -I {} bash -c "echo {} | cut -d/ -f7" | xargs -n1 postcat -q | grep PHP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Fix igneg_nice bug on vserver guests and hosts | |
for i in `vserver-stat | awk '{ print $1; }'` ; do if [ $i != "CTX" ] ; then vattribute --xid $i --set --flag igneg_nice ; fi ; done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Git from outside of repository | |
git --git-dir=/home/user/example-repo/.git --work-tree=/home/user/example-repo $GITCOMMAND_HERE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Search for IP addresses and print all IPs found | |
# complex IP regex | |
# matches: | |
# - 1.3.3.7 | |
# - 001.003.003.007 | |
# - 0.0.0.0 (also valid) | |
# - 01.255.255.255 | |
"(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Lists all GPG recipients of a file | |
gpg --list-only --no-default-keyring --secret-keyring /dev/null $infile |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Mute bash output the short way | |
command &> /dev/null |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Rename non-ascii filenames in one line for shell | |
for f in * ; do mv "$f" `echo $f | tr -cd "a-zA-Z0-9.-_"`; done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Install numix GTK theme | |
sudo add-apt-repository ppa:numix/ppa | |
sudo apt-get update | |
sudo apt-get install numix-plymouth-theme numix-gtk-theme numix-icon-theme numix-icon-theme-circle |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Connect with openvpn config file on ChromeOS | |
# 0. shill shouldn't kill tun0 | |
sudo stop shill | |
sudo start shill BLACKLISTED_DEVICES=tun0 | |
# 1. create tun0 (or tunX) device | |
/usr/sbin/openvpn --dev tun0 --mktun | |
# 2. change to directory where .ovpn is stored | |
/home/chronos/user/some_folder_name/ | |
# 3. connect using .ovpn file with device tun0 (or tunX) | |
/usr/sbin/openvpn --config some_file_name.conf --dev tun0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Perl variant of sed search replace (with multi line support) | |
DATA="data with multiple | |
lines" | |
cat /tmp/template | perl -i -0pe "s/_DATA_/${DATA}/g" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# PFX to PEM cert and key | |
# crt | |
openssl pkcs12 -in $file -out zertifikat.crt -clcerts -nokeys | |
# key | |
openssl pkcs12 -in $file -out schluessel.key -nocerts -nodes | |
# ca certs | |
openssl pkcs12 -in $file -out chain.crt-cacerts -nokeys |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Print all users from /var/log/auth.log w/o CRON | |
grep -v CRON /var/log/auth.log | grep -E "user (.*)$" | sed -r "s/(from|by) (.*)//g" | awk '{print $NF}' | sort | uniq -c | sort -n |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Print all open (and listening) ports | |
netstat -anp --tcp --udp | grep LISTEN |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# variable with current script directory | |
dir=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Search all access log directories | |
# grep through all access logs (with zipped ones) | |
for s in <server>; do ssh $s "grep -rin access.log /etc/apache2/sites-enabled /etc/apache2/puppet-vhosts /etc/apache2/user-vhosts -h | egrep -o \"\ /.*access.log\" | tr -d \"\ \" | awk -F/ '{\$NF=\"\"}1' | tr \"\ \" \"/\" | sort | uniq | xargs -n 1 -I {} sh -c \"find {} -iname '*access*' 2> /dev/null\" | while read line; do zgrep --no-filename '<grep-for-something>' \$line; done" | tee -a log_$s.log; done | |
# list all access log files (with zipped ones) | |
for s in <server>; do ssh $s "grep -rin access.log /etc/apache2/sites-enabled /etc/apache2/puppet-vhosts /etc/apache2/user-vhosts -h | egrep -o \"\ /.*access.log\" | tr -d \"\ \" | awk -F/ '{\$NF=\"\"}1' | tr \"\ \" \"/\" | sort | uniq | xargs -n 1 -I {} sh -c \"find {} -iname '*access*' 2> /dev/null\"" | tee -a log_$s.log; done | |
# maybe there is a better way for this but I had to to do it by myself without research |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
curl -s --url "imaps://$IMAPSERVER/$FOLDER" -X "FETCH $msgID BODY.PEEK[HEADER.FIELDS (Subject)]" --user "$USERNAME:$PASSWORD" -D - | grep Subject | perl -pe 'use MIME::Words(decode_mimewords); $_=decode_mimewords($_);' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Show me all active connections in a timestamp loop | |
while true; do echo "`date | awk '{print $4}'` connections `netstat -antp | grep -vi LISTEN | wc -l`"; sleep 0.5; done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Show me the ten biggest MySQL tables | |
mysql -e "SELECT CONCAT(table_schema, '.', table_name), | |
CONCAT(ROUND(table_rows / 1000000, 2), 'M') rows, | |
CONCAT(ROUND(data_length / ( 1024 * 1024 * 1024 ), 2), 'G') DATA, | |
CONCAT(ROUND(index_length / ( 1024 * 1024 * 1024 ), 2), 'G') idx, | |
CONCAT(ROUND(( data_length + index_length ) / ( 1024 * 1024 * 1024 ), 2), 'G') total_size, | |
ROUND(index_length / data_length, 2) idxfrac | |
FROM information_schema.TABLES | |
ORDER BY data_length + index_length DESC | |
LIMIT 10;" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# from http://stackoverflow.com/a/24289918 | |
toBytes() { | |
echo $1 | echo $((`sed 's/.*/\L\0/;s/t/Xg/;s/g/Xm/;s/m/Xk/;s/k/X/;s/b//;s/X/ *1024/g'`)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment