Shell file Mobile Script

Source: Internet
Author: User

Shell file Mobile Script

Script Function: moves the files in the specified directory several days ago to the target directory and keeps the structure unchanged.

Application Scenario: used to remove old data that does not need to be retained on the server (I am using the ftp server environment)

Instructions for use: Modify the source directory and target directory in the script and modify the data migrated several days ago

Script code:

#!/bin/bash wdir= "/ftp" # Source directory bdir= "/mvbackup/ftp" # Target directory fl= "/tmp/filelist" okl= "/tmp/oklist" erl= "/tmp/errlist" dl= "/tmp/dirlist" mvlog= "/var/log/mvfile.log" mdlog= "/var/log/mkdir.log" #enterworking(source)director cd $wdir #createsourcefilelist if [-f$fl]; then rm -f$fl fi find -mtime+300- type f| grep - v "\/\." >$fl # ^ Data generated before 300 days #filtersourcefilelist if [-f$okl]; then rm -f$okl fi if [-f$erl]; then rm -f$erl fi if [!-f$fl]; then echo stop:1 exit 1 fi oldIFS=$IFS IFS=$ '\n' for i in $( cat $fl) do if [-f$i]; then echo "$i" >>$okl else echo "$i" >>$erl fi done IFS=$oldIFS #createtragetdirectorlist if [-f$dl]; then rm -f$dl fi if [!-f$okl]; then echo stop:2 exit 2 fi cat $okl| awk -F '/' '{$1="";NF-=1;OFS="/";print}' | sort -u>$dl #createtragetdirector if [!-f$dl]; then echo stop:3 exit 3 fi oldIFS=$IFS IFS=$ '\n' for i in $( cat $dl) do if [!-d "$bdir$i" ]; then mkdir -p "$bdir$i" if [!$?=0]; then echo "$bdir$i" >>$mdlog fi #echo$bdir$i fi done IFS=$oldIFS #movefiletotragetfolder if [!-f$okl]; then echo stop:4 exit 4 fi oldIFS=$IFS IFS=$ '\n' for i in $( cat $okl) do if [-f "$i" ]; then j= "$bdir$(echo$i|awk-F'/''{$1=" ";NF-=1;OFS=" / ";print}')" fi if [-d "$j" ]; then echo s: "$i" echo d: "$j" mv -f "$i" "$j" if [!$?=0]; then echo "$i" >>$mvlog fi fi done IFS=$oldIFS

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.