#!/bin/bash LOGFILE=imapsync.log FOLDERS=( 'Folder1' 'Folder2' 'Folder3' 'Folder4' '...' 'FolderN' 'INBOX' 'All Mail' 'Bin' 'Drafts' 'Starred' 'Sent Mail' ) TIMES=( '--minage 1090' '--maxage 1091 --minage 999' '--maxage 1000 --minage 908' '--maxage 909 --minage 817' '--maxage 818 --minage 726' '--maxage 727 --minage 635' '--maxage 636 --minage 544' '--maxage 545 --minage 453' '--maxage 454 --minage 362' '--maxage 363 --minage 271' '--maxage 272 --minage 180' '--maxage 181 --minage 89' '--maxage 90' ) echo "Starting" > $LOGFILE for FOLDER in "$@" do for ((j=0;j<${#TIMES};j++)) do TIME=${TIMES[${j}]} echo "" >> $LOGFILE echo "*** $FOLDER $TIME ***" >> $LOGFILE echo "" >> $LOGFILE while ! ~/imapsync-1.267/imapsync --host1 imap.gmail.com --port1 993 --user1 <a href="mailto:user@gmail.com">user@gmail.com</a> --passfile1 ./passfile --ssl1 --host2 imap.gmail.com --port2 993 --user2 <a href="mailto:user@domain.com">user@domain.com</a> --passfile2 ./passfile --ssl2 --syncinternaldates --split1 100 --split2 100 --authmech1 LOGIN --authmech2 LOGIN --include "$FOLDER" $TIME --useheader "Message-ID" --useheader "Date" --skipsize --regexmess 's/Delivered-To: <a href="mailto:user@gmail.com">user@gmail.com</a>/Delivered-To: <a href="mailto:user@domain.com">user@domain.com</a>/gi' --regexmess 's/<user@gmail.com>/<user@domain.com>/gi' --regexmess 's/^((To|From|Cc|Bcc):.*)user@gmail.com(.*)$/$1user@domain.com$3/gim' --regexmess 's/Subject:(s*)
/Subject: (no--subject)$1
/ig' --regexmess 's/Subject: ([Rr][Ee]):(s*)
/Subject: $1: (no--subject)$2
/gi' >> $LOGFILE 2>&1; do echo "" >> $LOGFILE echo "***** NOT COMPLETE - $FOLDER $TIME *****" >> $LOGFILE echo "" >> $LOGFILE tail -100 $LOGFILE | mail -s "Imapsync Restarting for $FOLDER $TIME" "user@domain.com" echo -n "Sleeping..." >> $LOGFILE sleep 1m echo "Done." >> $LOGFILE done echo "" >> $LOGFILE echo "***** COMPLETE - $FOLDER $TIME*****" >> $LOGFILE echo "" >> $LOGFILE tail -100 $LOGFILE | mail -s "Imapsync Complete for $FOLDER $TIME" "user@domain.com" done done echo "**** DONE ****" >> $LOGFILE tail -100 $LOGFILE | mail -s "Imapsync Complete" -c "user@domain.com"
Tag Archive for Bash
imapsync script to migrate Gmail to Google Apps
Change password in CVS directory (CVSROOT in Root files).
sed -i -e 's/oldpassword/newpassword/g' `grep -lR oldpassword *`
picasa upload directory of images
#!/bin/bash
# Usage $1 path to folder
#functions
capitalize_ichar ()
{
string0="$@"
firstchar=${string0:0:1}
string1=${string0:1}
FirstChar=`echo "$firstchar" | tr a-z A-Z`
echo "$FirstChar$string1"
}
full_path=$1
album_name=`basename $full_path`
### Your google account and password
username=
password=
cd $full_path
auth_key=$( curl -s <a href="https://www.google.com/accounts/ClientLogin" >https://www.google.com/accounts/ClientLogin</a> -d Email="$username"@gmail.com -d Passwd="$password" -d accountType=GOOGLE -d source=Google-cURL-Example -d service=lh2 | awk -F= '/^Auth=/{print $2}' )
picasa_default_out="picasa_default.tmp"
picasa_album_addrs="picasa_album_addrs.tmp"
picasa_album_names="picasa_album_names.tmp"
picasa_result="picasa_result.tmp"
picasa_new_album="picasa_new_album.tmp"
picasa_result_upload="picasa_result_upload.tmp"
curl -s --header "Authorization: GoogleLogin auth=$auth_key" "http://picasaweb.google.com/data/feed/api/user/default" > "$picasa_default_out"
idx=1
cat "$picasa_default_out" | tr '>' '
' | grep "</gphoto:name" | cut -d'<' -f 1 > "$picasa_album_names"
cap_album_name=`capitalize_ichar $album_name`
if grep -q $cap_album_name $picasa_album_names
then
echo "Album already exists"
else
echo "<entry xmlns='http://www.w3.org/2005/Atom' xmlns:gphoto='http://schemas.google.com/photos/2007'>" >> album.xml
echo "<category scheme='http://schemas.google.com/g/2005#kind' term='http://schemas.google.com/photos/2007#album' />" >> album.xml
echo "<title type='text'>$album_name</title>" >> album.xml
echo "<summary type='text'></summary>" >> album.xml
echo "<gphoto:location></gphoto:location>" >> album.xml
echo "<gphoto:access>public</gphoto:access>" >> album.xml
echo "<gphoto:commentingEnabled>true</gphoto:commentingEnabled>" >> album.xml
echo "</entry>" >> album.xml
curl --silent --request POST --data "@album.xml" --header "Content-Type: application/atom+xml" --header "Authorization: GoogleLogin auth=$auth_key" "http://picasaweb.google.com/data/feed/api/user/$username" > "$picasa_result"
cat "$picasa_result" | tr '>' '
' | grep "</gphoto:id" | cut -d'<' -f 1 > "$picasa_new_album"
album_addr=$( head -1 "$picasa_new_album" )
echo "---------------------------"
echo "Album $album_name added"
echo "---------------------------"
num_images=0
for f in *.JPG
do
echo "Processing $f file..."
mime_type=$( file -ib "$f" )
curl -s --request POST --data-binary "@$f" --header "Slug: $f" --header "Content-Type: $mime_type" --header "Authorization: GoogleLogin auth=$auth_key" "http://picasaweb.google.com/data/feed/api/user/$username/albumid/$album_addr" >> "$picasa_result_upload"
echo "Uploaded $f file..."
num_images=`expr $num_images + 1`;
done
echo "---------------------------"
echo "Uploaded $num_images file/s"
echo "---------------------------"
fi
#tidy up
files=$(ls $full_path/*.tm 2> /dev/null | wc -l)
if [ $files ]
then
rm *.tmp
fi
if [ -f album.xml ]
then
rm album.xml
fi
Line Number File And Copy To Clipboard
sed = /path/to/file | sed 'N;s/ /,/' | pbcopy
SSH Access Email Alert
echo ‘[SSH] – SSH access to SERVERNAME on:’ `date` `who` | mail -s “SSH access from `who | cut -dâ€(†-f2 | cut -dâ€)†-f1`†<a href="mailto:enter_email@address.here">enter_email@address.here</a>
Add a directory to your PYTHONPATH in Terminal.app using TextMate
#open your .bash_profile by typing this into Terminal. You'll need to be in your home directory. sudo mate edit .bash_profile # Paste something like this into your .bash_profile export PYTHONPATH=$HOME/Sites/dev:$PYTHONPATH
Remame files to lowercase in Linux
rename 'y/A-Z/a-z/' *
Update svn child folders (from a non SVN folder)
svn up `ls`
Grep for files that do not match a pattern
grep -L "the pattern" * # to recurse into subdirectories grep -RL "the pattern" *
comparing the checksums of two files with Perl and cksum
cksum file1 file2 | perl -ane '$x ||= $F[0]; warn if $x != $F[0]' # This can be shortened slightly, to: cksum file1 file2 | perl -ane 'warn if $F[0] != ($x ||= $F[0])' # If the checksum value we need to match is already known, that can be # shortened to: cksum file1 file2 | perl -ane 'warn if "664253628" != $F[0]' # on Mac, if you have copied a checksum value into the clipboard, use # pbpaste to do the comparison cksum file1 file2 | perl -ane 'warn if `pbpaste` != $F[0]'