Skip to content

Instantly share code, notes, and snippets.

@simbalinux
simbalinux / loadnewarray.php
Created February 22, 2018 19:00
push last x lines of open file to new array
<?php
$lines=array();
$fp = fopen("../log/simplelogger.log", "r");
//tail off last x lines of the log file
while(!feof($fp))
{
$line = fgets($fp);
array_push($lines, $line);
if (count($lines)>10)
@simbalinux
simbalinux / selinux disable
Created February 22, 2018 19:56
disabling selinux before and after reboot
#disable selinux on next reboot
sed -i 's/enforcing/disabled/g' /etc/selinux/config /etc/selinux/config
sestatus
#put in permissive mode
setenforce 0
@simbalinux
simbalinux / pipe_webpage
Created July 13, 2018 00:22
pipe_webpage
#!/usr/bin/env bash
(echo "Content-Type: text/html"; curl localhost/cgi-bin/report.cgi) | /usr/sbin/sendmail user@domain.com
#!/usr/bin/env bash
IFS=$'\n'
arr=($(dig @dns.server domain_to_search axfr))
unset IFS
for i in "${arr[@]:6:92}"
do
echo "$i" | awk '{print $5,$1}'
done
@simbalinux
simbalinux / pipe_apachelogs
Created July 13, 2018 01:06
When logs cannot be truncated on a NAS and you need to pipe logs files and rotate forcefully
#!/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";
@simbalinux
simbalinux / logrotate_config
Created July 13, 2018 01:09
logrotation configuration
#place this file in /etc/logrotate.d/
/var/log/vhosts/*.log {
su root root
copytruncate
rotate 30
missingok
notifempty
sharedscripts
compress
@simbalinux
simbalinux / strap_nrpe
Created July 13, 2018 01:11
bootstrap an nrpe client in the network
# 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 / stat_compare
Created July 13, 2018 17:19
stat compare on directory
#!/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.cfg
Created July 14, 2018 18:38
HAproxy frontend/backend configuration
#---------------------------------------------------------------------
# FrontEnd Configuration
#---------------------------------------------------------------------
frontend http
bind *:80
option http-server-close
option forwardfor
default_backend backend
frontend https
@simbalinux
simbalinux / create_repo
Created July 13, 2018 00:16
create_repo
#!/usr/bin/env bash
repo_name=$1
test -z $repo_name && echo "Repo name required." 1>&2 && exit 1
curl -u 'username_github' https://api.github.com/user/repos -d "{\"name\":\"$repo_name\"}"