How to fix the iTerm keyboard bindings in OSX (readline configuration)
The keyboard bindings in iTerm on OSX Snow Leopard are fubar. To fix them either switch to Linux or put this in your zsh or bash configuration:
1 bindkey "^r" history-incremental-search-backward 2 bindkey '^E' end-of-line 3 bindkey '^A' beginning-of-line 4 bindkey 'ƒ' forward-word 5 bindkey '›' backward-word 6 bindkey "^F" forward-char 7 bindkey "^B" backward-char 8 bindkey "^k" kill-line 9 bindkey "^u" backward-kill-line
Bash scripting: change current Rails application directory
Put this in ~/.bashrc:
1 app () { cd "/var/www/$*/current"; }
Execute:
1 . ~/.bashrc
Now you can change to another Rails app directory like this:
1 app xxx.com
Using expect for automation of bulk scp copying.
Expect can come in handy when you can’t configure ssh public key authentication on the servers :) (and the system “architect” hasn’t yet realized the wonderfulness of a log host).
1 #!/bin/bash 2 # 3 # Usage: script <username> <password> <build> 4 # 5 # Example ./copy_logs_from_production.sh marko hubbabubba current 6 # 7 8 username=$1 9 password=$2 10 build=$3 11 mkdir $build 12 13 instance_1_server=10.0.0.1 14 instance_2_server=10.0.0.1 15 instance_3_server=10.0.0.2 16 instance_4_server=10.0.0.2 17 instance_5_server=10.0.0.3 18 instance_6_server=10.0.0.3 19 instance_7_server=10.0.0.4 20 instance_8_server=10.0.0.4 21 instance_9_server=10.0.0.5 22 23 servers=("$instance_1_server" "$instance_2_server" "$instance_3_server" "$instance_4_server" "$instance_5_server" "$instance_6_server" "$instance_7_server" "$instance_8_server" "$instance_9_server" ) 24 i=1 25 for server in ${servers[@]}; do 26 expect -c " 27 # exp_internal 1 # uncomment for debugging 28 spawn /usr/bin/scp $username@$server:/var/logs/application/$build/server${i}/error.log $build/error-${i}.log 29 expect { 30 "*password:*" { send $password\r\n; interact } 31 eof { exit } 32 } 33 exit 34 " 35 let "i=i+1" 36 done 37
Appending strings in bash without the line feed.
To append to a stream in bash without the trailing line feed use printf to format the output before appending it to the stream.
1 i=42 2 FILE=/tmp/atm 3 printf "%s" "${i}" > $FILE
Work around for "bash: /bin/rm: Argument list too long"
Use find instead of rm:
1 find . -name '*' | xargs rm
The command deletes all files in the current directory.