Shell script for real-time file shunting in the background

Source: Internet
Author: User

Copy the files in the bill folder to the bill1 and bill2 folders according to certain rules (file name parity.
Update the progress tag of bill1 and bill2 (Update file. max)
File3 is the label of the latest file under the bill directory. It is updated every minute under normal circumstances (Format: 20121016122100)

Copy codeThe Code is as follows :#! /Bin/bash
# For wanggy 2012/10/16
Bill1 =/infosms/bill1
Bill2 =/infosms/bill2
File_max = 'cat file3'
Cd/infosms/bill
While:
Echo "start"
Do
If [$ file_max! = 'Cat file3']; then
Echo "not equal, processing"
# Determine file3 11-12 bits (parity)
Num1 = 'cut-c 11-12 file3'
# If 10 is not added #08 is encountered when the modulo is obtained, an error occurs. (Octal judgment ?)
Num = $(10 # $ num1 % 2 ))
# Num = $ ($ num1 % 2 ))
# Obtain the current file under bill (latest)
File_name = B 'cat file3'
Echo "latest file: $ file_name"
Case $ num in
1)
Echo "odd"
Cp-a $ file_name ../bill1
Echo 'cat file3'> ../bill1/file. max

0)
Echo "even"
Cp-a $ file_name ../bill2
Echo 'cat file3'> ../bill2/file. max

Esac
Echo "returns the latest value to file_max"
File_max = 'cat file3'
Else
Echo "equal, not processed, quit! "
# File_date = 'cat $ filename'
# Exit 1
Fi
Echo "wait 10 seconds, next time judge ..."
Sleep 10
Done

Related Article

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.