I use this command to track changes on a file on ubuntu:
tail -f /var/log/auth.log
as the file changes I see the output printed on the console. It is very nice.
My bash script therefore looks something like this:
#!/bin/bash
tail -fn0 /var/log/auth.log | \
while read line ; do
x=$(echo "$line" | grep -o "sftp-server")
# if line contains sftp-server then:
if [ "$x" == "sftp-server" ]; then
# ... do work with line <------------------
fi
done
I need to run this bash script in mono (c#). So my question is how can I do that with c#? If I where to do something like the code in c# bellow will it be doing the same thing?
var fileStream = File.OpenRead("/var/log/auth.log");
while (true)
{
Thread.Sleep(500);
byte[] buffer = new byte[1024];
StreamReader reader = new StreamReader(fileStream);
if (fileStream.CanRead)
{
var line = reader.ReadLine();
if (string.IsNullOrEmpty(line) == false)
{
// do work with line.... <-----------------------
}
}
}