Monitor things with CLI
I use to ls
or df
repeatly to monitor some status. Then I come with the for loop of each shell I use... but it's really painful to change the syntax every time...
Finally I wrote a small script python that work on linux and windows
! /usr/bin/python
import os
import sys
import time
cmd = " ".join(sys.argv[1:])
clear = ['clear','cls'][os.name == 'nt']
while True:
try:
os.system(clear)
os.system(cmd)
time.sleep(1)
except KeyboardInterrupt:
break
Once you have put this script in your PATH
, you just need to run monitor ls -al
(the script name is monitor) to see the result of ls refreshed every second.
And press Ctrl + c
to interrupt the program
Written by gahtune
Related protips
4 Responses

Clever. There is unix command that does this called 'watch'
watch -- du -h errorlog
(updated to correct mistakes)

@kablamo Thanks for the hint. I will try to use the same command api to port it to windows ;)
@kablamo Well "tail -f" with watch is bad idea :) just tail or "tail -f" without watch.

@alhafoudh yup he makes a small mistake, but not so important, every one understand.