Finding out which files are open and by which programs

Grrrrrrr ran into my inotify problem again. So I was wondering how I can see which program has files opened and how many. Well as with everything under Linux it is possible with a few “simple” commands. Try the following command for fun and entertainment.

$ lsof | awk ‘{print $1}’ | sort | uniq -c | sort -g -k 1 | tail

  • lsof: lists the open files
  • awk: takes the first column of the output
  • sort: yep it sorts the output
  • uniq: counts all the same value
  • sort: do you want me to repeat it? a little clarification is necessary -k tells which column to sort on and -g makes sure that the contents is treated like a number
  • tail: gives the last ten entries

Inotify limit reached under PT Magic

Today I ran into a problem with PT Magic (PTM) that the inotify limit was reached on Ubuntu. Inotify (inode notify) is a Linux kernel subsystem that acts to extend filesystems to notice changes to the filesystem, and report those changes to applications. Just as a future reference for myself and as a reference to others a very quick write up how to solve this.

You can get your current inotify file watch limit by executing:

$ cat /proc/sys/fs/inotify/max_user_watches

You can set a temporary new limit with:

$ sudo sysctl -w fs.inotify.max_user_watches=16384

If you like to make your limit permanent use:

$ echo fs.inotify.max_user_watches=16384 | sudo tee -a /etc/sysctl.conf
$ sudo sysctl -p

That’s it. The problem should be solved. At least this is the workaround. I have submitted an issue to TP Magic so that they can fix it properly. We will see.

Validating a json file from the command line in Linux

Today I needed to validate a json file on one of my servers. It turns out there is a simple nodejs program or actually a linter to do this with.

Just execute the following line and you are in business.

sudo npm install jsonlint -g

This assumes nodejs is already installed. If not, execute the following line.
sudo apt-get install -y nodejs npm

To validate a json file run the following command.

jsonlint -qc settings.analyzer.json

When running the program the first time I ran into the problem that the json file contains comments. Yes, I know this is not in line with the spec, but it is damn handy for understanding the file. So I needed to strip the comments to valiate the file. After googeling around a bit I found an awk command to do just this. Try the following command.

awk '{sub(/\/.*$/,"")}1' settings.analyzer.json > settings.analyzer.json

Now run jsonlint again and it should work.

P.s. I know the title of this post says Linux, but jsonlint will also work under any other system that nodejs runs on.

Hope this saves someone some time.

PT Magic setup on Ubuntu 17.10


In this post I will explain how to install, configure and run PT Magic (PTM), a free add-on for the Profit Trailer (PT) cryptocurrency trading bot, on a VPS using Ubuntu. As an extra security precaution the PTM GUI is only accessible through a SSH tunnel using PuTTY with port forwarding. This avoids opening additional ports on the VPS to the outside world.

Continue reading

Using the hosts file on Windows with ports

As you might or might not know I’m running Profit Trailer (PT) on a VPS. To be safe the GUI is not accessible to the outside world, but only through an SSH tunnel. It has been irritating me for a while that the URLs are not readable, e.g. localhost:8081. I wanted readable URLs without ports in them. Today I finally figured out how to do this using a combination of host file and the Windows networking tool netsh.

Continue reading