Skip to content

Instantly share code, notes, and snippets.

@baerla
baerla / backup.sh
Last active April 10, 2022 17:07
A bash script used for uploading a second script over ssh to a server and invoking it with given parameters. Using bash interal argument parsing.
#!/bin/bash
# set -e: Fail if some command exits with non-zero status
# set -u: Fail on use of uninitialized variable
set -eu
# Usage
if [[ $# -lt 2 ]]; then
echo "Usage: $0 -h|--host <host> -u|--user <username> -p|--password <password> [-c|--compression <'gz'|'zip'|'xz'>]"
exit 2
@baerla
baerla / timediff.sh
Last active March 3, 2022 17:59
A simple shellscript to calculate your time worked between two timestamps excluding your pause
#!/bin/bash
# Usage: ./timediff.sh <starttime in format <hour><minutes>> <endtime> <minutes of pause in between>
if [[ $# -lt 2 ]]; then
echo 'No time given'
fi
if [[ $# -lt 3 ]]; then
echo 'No pause given'
echo "Usage e.g.: $1 0800 1700 60"
exit 1
@baerla
baerla / test.sh
Created February 3, 2021 13:25
Skript to run .cpp and .h C++ files
#!/bin/bash
# syntax: ./test.sh <file.h> <arguments>
createdNewFile=false
file=${1##*/}
echo $file
filename=${file%.h}
echo $filename
path=${1%$file}
@baerla
baerla / getLineCount.sh
Created January 14, 2021 12:39
Get line count in directory for given file extension
#!/bin/bash
# usage: ./getLineCount.sh *.cs
find . -name "$1" -exec wc -l {} \; | mawk '{s+=$1} END {print s}'
@baerla
baerla / installedGit.sh
Created December 29, 2020 13:43
Returns all remote urls from all git repositories on beneath <dir> saved at <file>
#!/bin/bash
if [[ -z $1 ]]; then
echo "no search place given!"
exit 1
fi
if [[ -z $2 ]]; then
echo "no file for saving given!"
exit 1
@baerla
baerla / clearCache.sh
Created December 14, 2020 11:52
Clear Linux Cache (needed for WSL)
#!/bin/sh
sync; echo 1 > /proc/sys/vm/drop_caches