When you are a Linux user who uses the "tail -f" command a lot, and switching to windows for some reasons(temporarily of course ) you will feel the absence of this useful command.
tail
as the name of command somehow implies, it has something to do with the end of the file, by using tail you can read n lines of end of a file and you can monitor lines appending to end of file.
my reaction to the absence of tail command
as I was sitting behind my computer and mourning over the tail command , I got to the idea of writing my own tail command(actually I did some searches and saw some sources as alternatives for tail but I had some time to kill, so I decided to write it myself).
below is my code in python 3, it is not that perceptional, I didn't spend that much time on it , so it could be handled better(feel free to edit it and make it better).
the way it works is that you simply throw a file at it and it is going to show you any line appending to the end of the file.
link for exe file, it is compressed in .rar
https://www.dropbox.com/s/en2phublxa5iyx7/Tail.rar?dl=0
- Download the file
- unzip it
- open a cmd
- execute tail.exe with a file name as parameter
example:
D:\Python\Tail\tail.exe E:\seclog.txt
the source code written in python 3.x
import signal
import sys
from optparse import OptionParser
last = 0
sleepInterval = 1.0
def signal_handler(signal, frame):
while True:
print()
print("Thank you guys for using this tool")
print()
print("@meysam")
print("steemit.com")
sys.exit(0)
signal.signal(signal.SIGINT, signal_handler)
def rl_t_tail(mey):
global last
while True:
line = mey.readline()
if line:
if last == 1:
yield line
else:
last = 1
tail(mey)
def tail(mey):
while True:
end = mey.tell()
line = mey.readline()
if not line:
time.sleep(sleepInterval)
mey.seek(end)
else:
yield line
def main():
f = OptionParser("usage: tail.py file")
(options, args) = f.parse_args()
if len(args) < 1:
f.error("Specify a file first")
with open(args[0], 'r') as mey:
for line in rl_t_tail(mey):
print(line.rstrip("\n"))
if __name__ == '__main__':
main()
##@meysam
this is a short video of how it works
Thanks for reading my post, your feedback means a lot to me :)
this post is 100% powered up
if you liked it
if you find it useful
if you like to see more
Fri Jan 20 14:57:04 IRST 2017
Hello @meysam,
Congratulations! Your post has been chosen by the communities of SteemTrail as one of our top picks today.
Also, as a selection for being a top pick today, you have been awarded a TRAIL token for your participation on our innovative platform...STEEM.
Please visit SteemTrail to get instructions on how to claim your TRAIL token today.
If you wish to learn more about receiving additional TRAIL tokens and SteemTrail, stop by and chat with us.
If you choose not to receive any comments or TRAIL rewards from SteemTrail, you can reply with "Stop" to opt out. Thank you.
Happy TRAIL!
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
thank you guys again :)
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
AWESOME. Stupid windows machines at work.... I'll be plugging this into them asap. Cheers for this, its so helpful! Followed for brilliant techie help :)
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
@ilovebatcatstew
thank you for your feedback, I really appreciate it, I hope you find it useful :)
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Pretty cool that you ported it to windows. I do use tail in Linux to monitor ssh log in attempts for example. Quite the useful command. Upvoted and followed.
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
as I said it could be better, but it does the job for now.
thank you for your feedback, hope you find it useful :)
and followed back too
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
well done :)
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit