How to realize the shell script of real-time streaming files in the background
The purpose of this article is to share with you the content of the shell script on how to implement real-time streaming files in the background. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
Copy the files under the bill folder to the bill1,bill2 folder according to a certain rule (file name parity).
Update bill1,bill2 processing progress label (update file.max)
File3 is the tag for the latest files in the bill directory, which is normally updated every minute (format: 20121016122100)
The 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 "unequal, processing"
# judge file3 11-12 bits (parity)
Num1= `cut-c 11-12 file3`
# it will make an error if you encounter 08 when you do not add 1 inch to get the mold. (octal judgment? )
Num=$ ((10#$num1%2))
# num=$ (($num1%2))
# get 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 "give the latest value to file_max"
File_max= `cat file3`
Else
Echo "equal, do not handle, quit!"
# file_date= `cat $filename`
# exit 1
Fi
Echo "wait 10 seconds and judge next time."
Sleep 10
Done
Thank you for reading! This is the end of this article on "how to realize the shell script for real-time streaming files in the background". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it out for more people to see!