Skip to content

Instantly share code, notes, and snippets.

@xtman
xtman / duration-single
Created August 21, 2012 01:33
Calculate the duration of the specified mr study directory.
#!/bin/bash
function adjust() {
local cwd=$(pwd)
local sd=$1
local total=$2
local mtime1=0
local mtime2=0
local gap=0
cd ${sd}
@xtman
xtman / duration
Created August 21, 2012 01:31
Calculate the duration of mr studies in Bruker's nmr directory.
#!/bin/bash
function adjust() {
local cwd=$(pwd)
local sd=$1
local total=$2
local mtime1=0
local mtime2=0
local gap=0
cd ${sd}
for ssd in $(ls -t -r -d */)
@xtman
xtman / chk_flashback
Created April 8, 2012 01:51
A shell script to detect if your Mac have Flashback Trojan infected
#!/bin/bash
SafariInfected=0
echo -n "Checking Safari... "
if [[ -z `defaults read /Applications/Safari.app/Contents/Info LSEnvironment 2>&1 | grep "does not exist"` ]]; then
SafariInfected=1
echo "INFECTED."
else
echo "NOT INFECTED."
fi
@xtman
xtman / stderr_stdout_redirection.sh
Created March 8, 2012 00:51
stderr and stdout redirections
# redirect stdout to a file
cat 1.txt > r.txt
# redirect stderr to a file
grep "error" 1.log 2> r.txt
# redirect stdout to a stderr
grep * 1>&2
# redirect stderr to a stdout
@xtman
xtman / genpassword.sh
Created March 4, 2012 23:11
Shell Script to generate a random string as password
# Works on Linux and Mac OS
cat /dev/urandom | strings | grep -m 1 -oEi '[a-zA-Z0-9_^!#]{8}'