Skip to content

Instantly share code, notes, and snippets.

View crazy-max's full-sized avatar

CrazyMax crazy-max

View GitHub Profile
@crazy-max
crazy-max / wget-file-size.sh
Created June 3, 2013 00:43
file size with wget
#! /bin/sh
echo wget -S --spider -O - "http://www.foo.com/file" >&1 2>&1 | grep '^213' | awk '{print $2}'
@crazy-max
crazy-max / filter-wget-progress
Created June 3, 2013 00:42
filter wget progress - to display the progress bar only
#! /bin/sh
function wgetFilter() {
local flag=2 c count cr=$'\r' nl=$'\n'
while IFS='' read -d '' -rn 1 c
do
if [ $flag == 1 ]
then
printf '%c' "$c"
if [[ "$c" =~ (s$) ]]
@crazy-max
crazy-max / log-all-output.sh
Last active December 18, 2015 00:19
Log all output
#! /bin/sh
LOG_FILE="/tmp/script-output.log"
function watchTail() {
local cur_pid=$$
local tail_args=`echo "tail -f $LOG_FILE" | cut -c1-79`
local pid=`ps -e -o pid,ppid,args | grep ${cur_pid} | grep "${tail_args}"| grep -v grep | nawk '{print $1}'`
if [ "$pid" = "" ]
@crazy-max
crazy-max / timing.sh
Created June 3, 2013 00:32
Timing a script
#! /bin/sh
function formatSeconds() {
local s=${1}
((h=s/3600))
((m=s%3600/60))
((s=s%60))
if [ "${#h}" == 1 ]; then h="0"$h; fi
if [ "${#m}" == 1 ]; then m="0"$m; fi
if [ "${#s}" == 1 ]; then s="0"$s; fi
#! /bin/sh
echo "http%3A%2F%2Fwww.foo.com%2Findex.php%3Fid%3Dqwerty" | sed -e "s/%\([0-9A-F][0-9A-F]\)/\\\\\x\1/g" | xargs -0 echo -e
# http://www.foo.com/index.php?id=qwerty
@crazy-max
crazy-max / wget-file-list-recursively.sh
Created June 3, 2013 00:54
wget file list recursively see url decode gist to decode files found : https://gist.github.com/crazy-max/5695521
#! /bin/sh
function wgetFind() {
local host="$1"
local path="$2"
local files=$(wget -q -O - "$host$path" | grep -o 'ftp:[^"]*')
while read -r line
do
local file=$(echo "$line" | sed "s#&\#32;#%20#g" | sed "s#$host# #g" | cut -c2-)
if [ "${file#${file%?}}" == "/" ]
@crazy-max
crazy-max / retry-function.sh
Created June 3, 2013 01:01
retry a function
#! /bin/sh
MAX_RETRIES=3
function sayHelloTo() {
echo "Hello $1!"
if [ -z "$2" ]; then local retry=0; else local retry=$2; fi
# Make something and test
if [ -d "/tmp/" ]
@crazy-max
crazy-max / tree-folder.sh
Last active August 13, 2017 13:50
List all files and folders of a directory and send it by email
#!/bin/sh
FOLDER="/mnt"
MAIL="root"
tree -ah -H $FOLDER --nolinks -- $FOLDER > /tmp/tree-folder.html
echo "See attachment." | mutt -a "/tmp/tree-folder.html" -s "Tree of $FOLDER on `hostname`" -- $MAIL
@crazy-max
crazy-max / check-smart-errors.sh
Created August 13, 2017 15:17
Checking disks for important SMART errors
#/bin/bash
TMP_FILE=/tmp/check-smart-errors.log
for I in $(ls /sys/block); do
smartctl -a /dev/$I > $TMP_FILE
if [ "$?" -ne "1" ]; then
DEVICE_MODEL="$(smartctl -a /dev/$I | grep -i 'device model')"
echo "DISK $I - $DEVICE_MODEL"
cat "$TMP_FILE" | grep -v "\- 0" | grep Raw_Read_Error_Rate
@crazy-max
crazy-max / docker-compose.yml
Created December 20, 2019 21:58
medium-diun-2-docker-labels
version: "3.5"
services:
diun:
image: crazymax/diun:latest
volumes:
- "./data:/data"
- "./diun.yml:/diun.yml:ro"
- "/var/run/docker.sock:/var/run/docker.sock"
environment: