Skip to content

Instantly share code, notes, and snippets.

View spy86's full-sized avatar
🎯
Focusing

Maciej Michalski spy86

🎯
Focusing
View GitHub Profile
@spy86
spy86 / service-check.sh
Created October 25, 2019 17:52
Simple bash script to check if a service is running
#!/bin/bash
service=zabbix_server
if (( $(ps -ef | grep -v grep | grep $service | wc -l) > 0 ))
then
echo "$service is running!!!"
else
echo "$service is not running on $HOSTNAME!!!"
/etc/init.d/zabbix-server start
fi
@spy86
spy86 / fw-config.sh
Created October 25, 2019 18:05
Example FW configuration script
#!/bin/bash
#define where iptables is
IPT=/sbin/iptables
############# Begin the NAT table operations ######
#Flush all the rules in the nat table
$IPT -t nat -F
#Load some modules needed for NAT
/sbin/modprobe ip_nat_ftp
/sbin/modprobe ip_nat_irc
#DNAT the gaming device ports 6500 and 6700 UDP for hosting games
@spy86
spy86 / qos-config.sh
Created October 25, 2019 18:07
Example QoS Script
#!/bin/bash
#delete root qdisc (this will destroy all classes)
tc qdisc del dev eth1 root
#attach root qdisc and create the 100Mbps root class
tc qdisc add dev eth1 root handle 1: htb
tc class add dev eth1 parent 1:0 classid 1:10 htb rate 100Mbit
#create the 1Mbps class for the whole bandwidth
tc class add dev eth1 parent 1:10 classid 1:20 htb rate 1Mbit
#Xboxβ€Š-β€Š128kbit
tc class add dev eth1 parent 1:20 classid 1:100 htb rate 128Kbit ceil 1Mbit
@spy86
spy86 / sysinfo.sh
Created October 25, 2019 18:15
Bash script that displays information about the linux server
#!/bin/bash
cname=$(cat /proc/cpuinfo|grep name|head -1|awk '{ $1=$2=$3=""; print }')
cores=$(cat /proc/cpuinfo|grep MHz|wc -l)
freq=$(cat /proc/cpuinfo|grep MHz|head -1|awk '{ print $4 }')
tram=$(free -m | awk 'NR==2'|awk '{ print $2 }')
swap=$(free -m | awk 'NR==4'| awk '{ print $2 }')
up=$(uptime|awk '{ $1=$2=$(NF-6)=$(NF-5)=$(NF-4)=$(NF-3)=$(NF-2)=$(NF-1)=$NF=""; print }')
cache=$((wget -O /dev/null http://cachefly.cachefly.net/100mb.test) 2>&1 | tail -2 | head -1 | awk '{print $3 $4 }')
io=$( (dd if=/dev/zero of=test_$$ bs=64k count=16k conv=fdatasync &&rm -f test_$$) 2>&1 | tail -1| awk '{ print $(NF-1) $NF }')
@spy86
spy86 / php_-scanner.php
Created October 25, 2019 18:16
Simple port Scanner in PHP
<?php
/**
* This script allows you to scan hosts
* Detection of open and closed ports.
*
*
*/
// Insert a style sheet to the results properly looked
echo '<html>'."\n"
@spy86
spy86 / zbx_nginx_stats.sh
Created October 28, 2019 21:06
Simple script to show nginx status:
#!/bin/bash
HOST=`/bin/hostname`
SERVER='zabbix.yourdomain.com'
CURL=/usr/bin/curl
read -a stat <<< `$CURL -sm3 "http://${HOST}/nginx_status"`
[ ! -z $stat ] && {
echo "\
#!/usr/bin/expect -f
# Zabbix IRC sender script
set force_conservative 0 ;# set to 1 to force conservative mode even if
;# script wasn't run conservatively originally
if {$force_conservative} {
set send_slow {1 .1}
proc send {ignore arg} {
sleep .1
exp_send -s -- $arg
@spy86
spy86 / last_user_logon.ps1
Created October 28, 2019 21:16
Powershell script to List User Last Logon
param(
$domain,
$users ) #end param
# Begin Functions
Function funWhatIf()
{
"what if: Perform operation obtain lastlogon time for user $user from
the $domain domain"
$date = Get-Date -UFormat %Y-%m-%d;
$backupFolder = $date;
$basePath = "F:\mongodb_backup";
$destinationPath = Join-Path $basePath $backupFolder;
if(!(Test-Path -Path $destinationPath)) {
New-Item -ItemType directory -Path $destinationPath;
(C:\mongodump.exe --out $destinationPath);
}
@spy86
spy86 / AD_user_lastL_logged.ps1
Created October 28, 2019 21:22
Get Active Directory user account last logged on time
#Check if the account exists.
If($Results.Count -eq 0)
{
Write-Warning "The SamAccountName '$UserName' cannot find. Please make sure that it exists."
}
Else
{
Foreach($Result in $Results)
{
$DistinguishedName = $Result.Properties.Item("DistinguishedName")