Skip to content

Instantly share code, notes, and snippets.

@simbalinux
simbalinux / find_examples
Last active Sep 23, 2018
using find command in linux
View find_examples
#!/usr/bin/env bash
# different ways to use the linux find command preferred choice typically.
find . -exec grep chrome {} +
#find will execute grep and will substitute {} with the filename(s) found. The difference between ; and + #is that with ; a single grep command for each file is executed whereas with + as many files as possible #are given as parameters to grep at once.
#If you use the \; ending construct grep is passed one file at a time, so it doesn't display the file name by default, only the matched lines. To get a file list instead add use grep -ls inside of the find construct.
@simbalinux
simbalinux / haproxy_setup
Last active Sep 23, 2018
provision script for haproxy
View haproxy_setup
#!/usr/bin/bash
# use this script to provision/configure haproxy when CM is not setup or applicable
set -x
#enable ssh
sed -i 's/PasswordAuthentication no/PasswordAuthentication yes/g' /etc/ssh/sshd_config
#disable selinux
sed -i 's/enforcing/disabled/g' /etc/selinux/config /etc/selinux/config
if [ ! $(command -v haproxy) ]; then
@simbalinux
simbalinux / lamp_7ssl
Last active Sep 23, 2018
LAMP PHP 7 w/ ssl provision script
View lamp_7ssl
#!/usr/bin/bash
set -x
#enable ssh to the host
sed -i 's/PasswordAuthentication no/PasswordAuthentication yes/g' /etc/ssh/sshd_config
#disable selinux
sed -i 's/enforcing/disabled/g' /etc/selinux/config /etc/selinux/config
# check hostname
hostname -f
# update and install Apache
@simbalinux
simbalinux / haproxy.cfg
Created Jul 14, 2018
HAproxy frontend/backend configuration
View haproxy.cfg
#---------------------------------------------------------------------
# FrontEnd Configuration
#---------------------------------------------------------------------
frontend http
bind *:80
option http-server-close
option forwardfor
default_backend backend
frontend https
@simbalinux
simbalinux / stat_compare
Created Jul 13, 2018
stat compare on directory
View stat_compare
#!/usr/bin/env bash
DIR_TO_CHECK='./'
OLD_STAT_FILE='./old_stat.txt'
if [ -e $OLD_STAT_FILE ]
then
OLD_STAT=$(cat $OLD_STAT_FILE)
else
@simbalinux
simbalinux / haproxy.pem
Last active Sep 23, 2018
create new .pem for use on haproxy when ssl certs exist on apache
View haproxy.pem
/etc/ssl/private/apache-selfsigned.key > /etc/ssl/private/haproxy.pem; /etc/ssl/certs/apache-selfsigned.crt >> /etc/ssl/private/haproxy.pem; cat /etc/ssl/certs/dhparam.pem >> /etc/ssl/private/haproxy.pem
@simbalinux
simbalinux / sed_check.py
Last active Sep 23, 2018
sed alternative in python
View sed_check.py
#!/usr/bin/python
import subprocess
from shutil import copyfile
copyfile("/etc/nagios/nrpe.cfg","/etc/nagios/nrpe.cfg.bak")
f = open("/etc/nagios/nrpe.cfg",'r')
filedata = f.read()
f.close()
@simbalinux
simbalinux / strap_nrpe
Created Jul 13, 2018
bootstrap an nrpe client in the network
View strap_nrpe
# Enable Debug
set -x
# Install requirements
yum -y install nrpe nagios-plugins-ping nagios-plugins-load nagios-plugins-check-updates nagios-plugins-ssh nagios-plugins-disk nagios-plugins-mysql nagios-plugins-http
# Create new firewall XML rules save as Monitoring2 so as not to chagne existing xml configs
echo "<?xml version=\"1.0\" encoding=\"utf-8\"?>
<zone>
<short>Monitoring</short>
@simbalinux
simbalinux / logrotate_config
Created Jul 13, 2018
logrotation configuration
View logrotate_config
#place this file in /etc/logrotate.d/
/var/log/vhosts/*.log {
su root root
copytruncate
rotate 30
missingok
notifempty
sharedscripts
compress
@simbalinux
simbalinux / pipe_apachelogs
Created Jul 13, 2018
When logs cannot be truncated on a NAS and you need to pipe logs files and rotate forcefully
View pipe_apachelogs
#!/bin/bash
## non ssl
exec >> "/var/www/vhosts/application/log/archive/test_ops/devel.domain.com_$(date +%Y-%m-%d).log";
while IFS= read -r line; do
if (( SECONDS > 10 )); then
exec >> "/var/www/vhosts/application/log/archive/test_ops/devel.domain.com_$(date +%Y-%m-%d).log"
SECONDS=0
fi
printf '%s\n' "$line";