This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
[[ -r $1 ]] || { echo "Usage: $0 <videofile-to-be-resized> [<videofile2> ...]"; exit 1; } | |
for INPUT_FILE in "$@"; do | |
OUTPUT_MP4_FILE=$(echo "$INPUT_FILE" | sed 's/\.[^.]*$/_resized.mp4/g') | |
#See https://trac.ffmpeg.org/wiki/x264EncodingGuide | |
avconv -y -i "$INPUT_FILE" -threads auto -c:v libx264 -preset medium -b:v 988k -pass 1 -an -f mp4 /dev/null && \ | |
avconv -i "$INPUT_FILE" -threads auto -c:v libx264 -preset medium -b:v 988k -pass 2 -c:a libmp3lame -b:a 192k "$OUTPUT_MP4_FILE" | |
rm -f av2pass* &>/dev/null |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
[[ $# -gt 1 ]] || { echo "Usage: $0 <arg1> <arg2> ... <argN>"; exit 255; } | |
echo 'Dont forget to surround the "$@" with the double-quotes '' so that it does not divide arguments that contain spaces.' | |
echo 'Samewise, you also need to surround the "$ARG_I" var' | |
for ARG_I in "$@"; do | |
echo '$@ = '"$@" | |
echo '$ARG_I = '"$ARG_I" | |
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function run_as_user { | |
local NEW_USER=$1 | |
local CMDS=$2 | |
sudo -u $NEW_USER -i bash -l -c "$CMDS" | |
} | |
#Use it like | |
run_as_user luke "echo $PWD; id" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# In bash all variables are defined by default as GLOBAL, even if defined inside functions | |
# To define a variable as LOCAL to a function, we have to prepend "local" in the definition | |
# This makes the variable only defined in the current function scope and so not global. | |
VAR_GLOBAL="im global - you can read and change me from anywhere, even inside functions - which may not always be a good thing" | |
echo "Seen from outside: $VAR_GLOBAL" | |
function my_func { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# This gist is related to C Evan's comment on | |
# http://zipizap.wordpress.com/2012/10/15/xkl-ubuntu-install-resizing-ntfs-partition-takes-too-long-check-ntfsresize-from-console-with-strace/ | |
# | |
# Hi Evans :) | |
# | |
# I see what you mean: only strace the writes to stdout, and not all writes that | |
# also contain moved data of the resize... And it got me interested in better understanding | |
# the strace options, so I did a little "man strace" study and then a little program in C |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
red@ownc:/tmp$ cat a.sh | |
#!/bin/bash | |
# Activate debug | |
set -x | |
echo "hi" | |
ls | |
pwd |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
du -k . | egrep -v '\/.*\/' | sort -n |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
[[ -r $1 ]] || { echo "Usage: $0 <videofile-to-be-resized> [<videofile2> ...]"; exit 1; } | |
for INPUT_FILE in $@; do | |
OUTPUT_MP4_FILE=$(echo $INPUT_FILE | sed 's/\.[^.]*$/.mp4/g') | |
#See https://trac.ffmpeg.org/wiki/x264EncodingGuide | |
avconv -y -i $INPUT_FILE -threads auto -c:v libx264 -preset medium -b:v 988k -pass 1 -an -f mp4 /dev/null && \ | |
avconv -i $INPUT_FILE -threads auto -c:v libx264 -preset medium -b:v 988k -pass 2 -c:a libmp3lame -b:a 192k $OUTPUT_MP4_FILE | |
rm -f av2pass* &>/dev/null |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
function shw_grey { echo -e '\033[1;30m'"$1"'\033[0m'; } | |
function shw_norm { echo "$1"; } | |
function shw_info { echo -e '\033[1;34m'"$1"'\033[0m'; } | |
function shw_warn { echo -e '\033[1;33m'"$1"'\033[0m'; } | |
function shw_err { echo -e '\033[1;31mERROR: '"$1"'\033[0m'; } | |
shw_info "Check starting..." | |
find . -type f -exec wc -l \{\} 2>&1 \; | grep error | |
shw_info "Check finished" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# If you put this check inside ~/.bashrc you can detect bash session opened by ssh-logins :) | |
[ "$SSH_CONNECTION" -a "$SSH_TTY" == $(tty) ] && echo "This bash session was opened from an ssh login :)" |