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
Delete messages containing a keyword in mutt
Bulk operations in mutt, a console based email client, are easy. Here’s how to delete messages containing the keyword ‘Newsletter’.
1 T 2 Newsletter 3 ; 4 d 5 $T – asks which messages you want to tag and you reply with ‘Newsletter’.
; – asks which action you want to run on the tagged messages.
d – tells that the action you want is delete.
$ – synchronizes the view with the underlying persistence layer.
Bulk renaming of files
Rename the files in a directory by replacing a space with an underscore. The rename program comes with most modern Linux distros.
1 rename 's/\ /_/g' *.*