Skip to content

Instantly share code, notes, and snippets.

View dedeibel's full-sized avatar

Benjamin Peter dedeibel

View GitHub Profile
@dedeibel
dedeibel / apply_inline
Last active July 1, 2019 16:55
apply given command to file and replacing it with it's content - sponge is used to replace it inline without copying
#!/bin/bash
set -e
if [ "$#" -lt 2 ]; then
>&2 echo "Usage: $0 FILE COMMAND [ARGS...]"
exit 1
fi
target="$1"
shift
"$@" < "$target" | sponge "$target"
@dedeibel
dedeibel / doall
Created September 4, 2014 12:25
Run all the given commands separated by terminal ;
#!/bin/sh
COMMAND=""
for arg in $@; do
if [ "$arg" = ";" ]; then
$COMMAND
COMMAND=""
else
COMMAND="$COMMAND $arg"
fi
@dedeibel
dedeibel / backup
Created September 18, 2014 07:57
run backup using rsync (see also archive and withbackupdevice)
#!/bin/bash
set -e
cd /
if [ ! -f /backup/ready ]; then
echo "backup device not ready"
exit
fi
DATE=`date +%Y-%m-%d`
STDOUT=/var/log/backup-${DATE}.log
@dedeibel
dedeibel / archive
Created September 18, 2014 07:59
create an archive using tar (see also backup and withbackupdevice)
#!/bin/bash
set -e
cd /
if [ ! -f /backup/ready ]; then
echo "backup device not ready"
exit
fi
DATE=`date +%Y-%m-%d`
STDOUT=/var/log/archive-${DATE}.log
@dedeibel
dedeibel / withbackupdevice
Created September 18, 2014 08:01
mount a network share before doing a specified action and umount it afterwards (see also backup and archive)
#!/bin/bash
#set -x
function failure() {
echo "backup failed " `date` >> /var/log/backup-mount-`date +%Y-%m-%d`
exit
}
function kill_childs() {
@dedeibel
dedeibel / crontab
Created September 18, 2014 08:06
backup crontab
# m h dom mon dow command
30 12 * * Mon,Wed,Fri /usr/bin/withbackupdevice /usr/bin/backup
# Every first tuesday
30 12 * * * [ `/bin/date +%u` -eq 2 -a `/bin/date +%e` -lt 8 ] && /usr/bin/withbackupdevice /usr/bin/archive
@dedeibel
dedeibel / portopen
Created October 7, 2014 14:13
check if single port is open
nmap -sS -p 5222 --open chat.hipchat.com | grep open 2>&1 > /dev/null
#!/bin/bash
fifo_name=$1;
if [ -z "$1" ]; then
echo "Usage "`basename $0`": <PATH>"
exit 1
fi
[ -p "$fifo_name" ] || mkfifo "$fifo_name";
chmod a+rw "$fifo_name"
#!/bin/bash
fifo_name=$1;
if [ -z "$1" ]; then
echo "Usage "`basename $0`": <PATH>"
exit 1
fi
[ -p "$fifo_name" ] || mkfifo "$fifo_name";
chmod a+rw "$fifo_name"
#!/bin/bash
PID=$1
if [ -z "$PID" ]; then
echo "no PID given"
exit 1
fi
while [[ ( -d "/proc/$PID" ) && ( -z `grep zombie "/proc/$PID/status"` ) ]]; do
sleep 0.5
done