Category Archives: Uncategorized

Check cass healthiness every hour and send out notification if down

cass hourly check and email

scripts can be reused for some other commands too. You just need to run this nohup or open a screen for it.


Most convenient way of regex searching recursively for files in python

def find_files(directory, pattern):
for root, dirs, files in os.walk(directory):
for basename in files:
if fnmatch.fnmatch(basename.lower(), pattern):
filename = os.path.join(root, basename)
yield filename

Its copied from stackoverflow, but it shows a really good example on when to use yield. Basically it returns a generator and thats far more memory efficient than returning a list.

Send messages to different users log on to the same server.

One of the cool features of UNIX is that you don’t need to have any software installed to send message to users logged on to that machine. There is a handy command called “write” which enables you to do this. Here is the syntax of this command:

$write username tty

Now the question arises, how to know the tty of a particular user. The “who” command of UNIX comes in to play here. Just shoot “who” command on your terminal and see the magic. You will receive the list of all users logged on to that machine with their tty. Below is an example.

root     :0           May  7 03:51
root     pts/1        May  7 03:51 (:0.0)
root     pts/2        May  7 03:51 (:0.0)
user5    pts/10       May  7 04:17 (dhcp-dwf1-4-10-176-162-74)
user8    pts/13       May  7 04:12 (dhcp-dwf1-4-10-176-162-180)
user9    pts/15       May  7 04:12 (
user7    pts/14       May  7 04:23 (dhcp-dwf1-4-10-176-162-118)
user12   pts/18       May  7 04:14 (dhcp-dwf1-4-10-176-162-119)
user11   pts/23       May  7 04:14 (dhcp-dwf1-4-10-176-162-31)
user1    pts/22       May  7 04:27 (dhcp-dwf1-4-10-176-162-125)
user15   pts/24       May  7 04:14 (dhcp-dwf1-4-10-176-162-65)
user6    pts/12       May  7 04:14 (dhcp-dwf1-4-10-176-162-120)
user2    pts/28       May  7 04:14 (dhcp-dwf1-4-10-176-162-60)
user7    pts/30       May  7 04:14 (dhcp-dwf1-4-10-176-162-118)
user4    pts/31       May  7 04:14 (dhcp-dwf1-4-10-176-162-72)
user10   pts/32       May  7 04:14 (dhcp-dwf1-4-10-176-162-68)
user14   pts/33       May  7 04:14 (dhcp-dwf1-4-10-176-162-27)

If you want to send message to user8, issue following command at your terminal:

$write user8 pts/13

Now write any message you want. To end the message, press Ctrl+D. Your message would be sent.

(copied from) Reference: