Advertisement
oquidave

bash arrays

May 4th, 2016
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.87 KB | None | 0 0
  1. #!/usr/local/bin/bash
  2. #move mail files older than 6 month(180 days) of domains to /mnt/mailsback/
  3.  
  4. backup_email_folder(){
  5.     d=$1
  6.     folder=$2
  7.     days=$3
  8.     ddest="/mnt/mailsback/$d"
  9.     echo "making dir $ddest"
  10.     exit 1
  11.     [ -d "$ddest" ] || mkdir "$ddest"
  12.     dpath="/usr2/mail/$d"
  13.     email_adds=`ls $dpath`
  14.     for email in $email_adds; do
  15.         echo -e "\n+++++++working on Email: $email+++++ \n" ; sleep 5
  16.         search_fp="$dpath/$email/$folder"
  17.         if [ ! -d "$search_fp" ]; then echo "dir $search_fp does not exist, skip"; continue; fi
  18.         find $search_fp -mtime +${days} | while read f; do
  19.             if [ ! -f "$f" ]; then echo "no files older than 1 months found, skip"; continue; fi
  20.             dest_folder=$ddest/$email/$folder
  21.             echo "making directory: $dest_folder"
  22.             [ -d "$dest_folder" ] || mkdir -p "$dest_folder"
  23.             fd=`ls -lh $f`; printf "\n MOVING: $fd \n"
  24.             mv -v "$f" "$dest_folder"
  25.         done
  26.     done
  27.     echo "####======AM DONE WITH $d DOMAIN=======###"
  28. }
  29.  
  30. backup_domain_emails(){
  31.     domain=$1
  32.     days =$2
  33.     searchp_read="Maildir/cur"
  34.     searchp_unread="Maildir/new"
  35.     searchp_sent="Maildir/.Sent/cur"
  36.     email_folders=($searchp_read $searchp_unread $searchp_sent)
  37.     for folder in ${email_folders[@]}; do
  38.         backup_email_folder $domain $folder $days
  39.     done
  40. }
  41.  
  42. loop_domains(){
  43.     domains_f=$1
  44.     days=$2
  45.     #loop thru file with domains to backup
  46.     while read domain; do
  47.     echo -e "\n====working on domain $domain ========\n"
  48.     continue
  49.             backup_domain_emails $domain $days
  50.     done < $domains_f
  51. }
  52.  
  53. if [ $# -eq 0 ]; then
  54.         echo "No arguments provided"
  55.         echo "provide dir path where domain emails files are"
  56.         exit 1
  57. fi
  58.  
  59. given_p=$1
  60. days=$2
  61. if [  -f "$given_p" ]; then
  62.         loop_domains $given_p $2
  63. else
  64.         backup_domain_emails $given_p $days
  65. fi
  66.  
  67. echo -e "\n #################Am done migrating the domain emails #################\n"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement