Skip to content

Instantly share code, notes, and snippets.

@simbalinux
simbalinux / strap_lamp7_ssl
Last active June 13, 2018 21:40
Centos 7 LAMP
#!/usr/bin/bash
set -x
# check hostname
hostname -f
# update and install Apache
yum -y update
yum -y install vim httpd
systemctl restart httpd
# backup of the httpd.conf file
@simbalinux
simbalinux / insert only once
Last active June 14, 2018 05:27
insert only once
grep -q -F 'include "/configs/projectname.conf"' foo.bar || echo 'include "/configs/projectname.conf"' >> foo.bar
@simbalinux
simbalinux / check_if_installed
Last active June 14, 2018 15:44
check_if_installed
#!/usr/bin/bash
if [ $(command -v httpd) ]; then echo 'installed'; else echo 'not installed'; fi
# or
if [ $(which httpd) ]; then echo 'installed'; else echo 'not installed'; fi
@simbalinux
simbalinux / append_hostsfile
Last active June 14, 2018 15:45
append /etc/hosts
#!/usr/bin/bash
grep -q -F '192.168.49.10 web1.example.com web1' /etc/hosts || echo '192.168.49.10 web1.example.com web1' >> /etc/hosts
@simbalinux
simbalinux / append_w_sed
Created June 15, 2018 15:34
append after a line in a file
#!/bin/bash
sed -i '/ServerName web2.example.com:443/a CustomLog /var/log/httpd/example.com/logs/web2.example.com-access.log combined' ssl.conf
@simbalinux
simbalinux / append_to_config
Created June 25, 2018 15:24
Appending a string to an existing configuration file
global_entry="
global
log 127.0.0.1 local0
log 127.0.0.1 local1 debug
maxconn 45000 # Total Max Connections.
daemon
nbproc 1 # Number of processing cores."
echo "$global_entry"
file=tester
grep -qF "$global_entry" "$file" || echo "$global_entry" | sudo tee --append "$file"
@simbalinux
simbalinux / check_sites
Created June 25, 2018 16:25
check uptime of sites
#!/bin/bash
SITESFILE=sites.txt #list the sites you want to monitor in this file
#EMAILS="you@email.com,someoneelse@email.com" #list of email addresses to receive alerts (comma separated)
while read site; do
if [ ! -z "${site}" ]; then
CURL=$(curl -s --head $site)
@simbalinux
simbalinux / socks5proxy
Created June 25, 2018 17:30
socks 5 proxy
#Create a secure server on your lan e.g. raspi
#invoke the following command from the server you will use as socks5 proxy specify port.
ssh -o ServerAliveInterval=60 -D0.0.0.0:8888 -f -N "host_with_www_connection"
#we have forked a background ssh process creating a socks5 proxy dynamically on ALL interfaces using 8888 on localhost, check with...
netstat -ntlp
#turn on the firewalld service
systemctl status firewalld.service
raw=/path/to/dir
files=("$raw"/*)
for each in "${files[@]}"; do
echo "$each"
sleep 3
done
count=${#files[@]}
files_ordered=()
for (( i = 0; i < count; i++ )); do
@simbalinux
simbalinux / shell_eval
Last active July 12, 2018 23:59
CGI program written in shell to evaluate filesystem
#!/usr/bin/env bash
shopt -s nullglob
exec > /path/to/logfile
# Variables
sql_path="/path/to/backup"
data_path="/path/to/backup"
days=7
testvalue=1
# Arrays
mapfile -t sql < <(find "$sql_path" -type f -mtime -"$days")