Skip to content

Instantly share code, notes, and snippets.

@counter2015
Created December 14, 2018 02:52
Show Gist options
  • Save counter2015/59cae296be66999565742cc82f6976a3 to your computer and use it in GitHub Desktop.
Save counter2015/59cae296be66999565742cc82f6976a3 to your computer and use it in GitHub Desktop.
a simple tail script which can detect file change of symbol link
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)
#####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