Created
December 14, 2018 02:52
-
-
Save counter2015/59cae296be66999565742cc82f6976a3 to your computer and use it in GitHub Desktop.
a simple tail script which can detect file change of symbol link
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import scala.sys.process._ | |
def someProcessing(line: String): Unit = { | |
print("[just read this line] ") | |
println(line) | |
} | |
val file = "1.txt" | |
val tail = Seq("tail", "-F", file) | |
tail.lineStream.foreach(someProcessing) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#####Usage###### | |
# | |
# in shell one, start the script, and in another shell, do the file operation in such order: | |
# 1. echo "1" >> 2.txt | |
# 2. ln -s 2.txt 1.txt | |
# 3. echo "2" >> 2.txt | |
# 4. echo "3" >> 1.txt | |
# 5. ln -snf 3.txt 1.txt | |
# 6. echo "4" >> 3.txt | |
# 7. echo "5" >> 1.txt | |
######### | |
$ scala tail.scala |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment