Skip to content

Instantly share code, notes, and snippets.

View strap_lamp7_ssl
#!/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 Jun 14, 2018
insert only once
View 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 Jun 14, 2018
check_if_installed
View 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 Jun 14, 2018
append /etc/hosts
View append_hostsfile
#!/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 Jun 15, 2018
append after a line in a file
View append_w_sed
#!/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 Jun 25, 2018
Appending a string to an existing configuration file
View append_to_config
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 Jun 25, 2018
check uptime of sites
View check_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)
View socks5proxy
#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
View load array & a new array
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 Jul 12, 2018
CGI program written in shell to evaluate filesystem
View shell_eval
#!/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")