Storage handling with users in Linux – or – The Land of Forgotten Inodes

In my years in IT I’ve handled a lot of storage (proprietary and open source solutions).
But one of the main issues that I had (beside design of large storage and backup) is the rouge user/script/program – sometime one of them will act up and fill the storage with large amount of files or one massive file (for example a big log file).

From time to time someone comes to me and say “Well my script isn’t working” – one of the first things I do is running “quota -u <USERNAME>” and 90% of the time We both see that the user filled his size or inodes quota and hist script fail.
From time to time I collected a lot of scripts and one liners to help me search for the problematic dir/file that contain the issue.

Here are some nice one-liners that can help you find the culprit:

Beware! Using some of this one liners on a directory that have under it local or NAS mount (example: nfs) won’t yield the correct result!
Make sure you run this lines where the you only scan one “device” (local mount, nfs mount etc…) at a time!

  •  Find the largest file amount in current directory (it will only show the current level of directories)
for x in .*/ */; do if [ "$x" != './' ] && [ "$x" != '../' ]; then x=${x#*\'}; x=${x%\'*}; y=`find "$x"|wc -l`; echo -e "$y\t $x";fi; done|sort -k1 -h
  •  Find big directory under your current location (You will need to keep following the path deeper until you find the problematic directory)
du --block-size=1G --max-depth=2|sort -rh|head
  • Find large files:
    (Replace <path/to/dir/> with the path to the directory you want to search in)
find </path/to/dir/> -printf '%s %p\n'| sort -nr | head -10
  • Check your current location device free space (this work even if there is another mount under it):
df -h .


Entire Wiki in your EBook Reader

From time to time I find myself in a need to learn some new programming language or some new program/fs/feature. Now this thing is straight forward mostly – Find a good book on the subject and sit your ass down and read all about it. But alas! Some of the program I need to work with does not have a book on them, Moreover there are some good free guides and wikis out there for programming languages and programs.
The problem with these sites is that you will need an internet connection and a browser

Some time back I’ve needed to learn about LVM and BTRFS over a weekend and found some good guides for that. Yet the guides where online and I didn’t want my tablet or laptop with for the weekend while travelling.
I thought to myself – I have a small kindle with me and it’s been faithful these past years in reading all kinds of books – What about reading Wiki/Guide with my kindle? Continue reading Entire Wiki in your EBook Reader

Python textwrap – Wrap your text to terminal size

Following the last post “Python textwrap – Fix Your Multiline Strings Indentations” – where we learned how to fix the indentation caused by the python indentation standards.
In this post I want to show you how to create a wrap to your text that support multiline and smart indent.

This might sound old to you but the original terminal (standard) was and still is 80 characters width. Long ago when I’ve started working on CLI applications and scripts my boss asked me to see the “usage/help” of one of them, then he looked at me and said – This is not 80 characters width! This is not terminal standard – Fix this!”
Back then I’ve just trimmed my lined and fix this.
More then 500 scripts later and 4 languages into the future I’ve looked at this and thought – There might be a better way to do this.
And there in python was the answer.

Let’s start with example:

>>> import textwrap
>>> x = "This is the first line of the text - This line is far more then then 80 characters and will need to be wraped to 80 characters width"
>>> print x
This is the first line of the text - This line is far more then then 80 characters and will need to be wraped to 80 characters width
>>> #Lets wrap it to 80 characters
>>> print textwrap.fill(x, width=80)
This is the first line of the text - This line is far more then then 80
characters and will need to be wraped to 80 characters width
SyntaxError: invalid syntax
>>> #See that the words won't break (Unless this is a long word)

Now let’s try that with a multiline string:

>>> x = '''
This is a mltiline string, now this is the first line and it will be more then 50 characters width for the example.
Now we create a new line with more then 50 width as the second line'''
>>> print textwrap.fill(x, width=50)
 This is a mltiline string, now this is the first
line and it will be more then 50 characters width
for the example. Now we create a new line with
more then 50 width as the second line

As you can see the second line was integrated into the first line instead of being on it’s own line – This is one of the problems with textwrap – it works only on a single line. Continue reading Python textwrap – Wrap your text to terminal size

Python textwrap – Fix Your Multiline Strings Indentation

I’ve been writing a lot in python the last couple of months and most of my code is for a CLI oriented environment (Mostly Linux/Unix shell).

One of the most important things when you create CLI is the help and usage string – Mostly because other people will try to use it – But lets face it, that script you’ve written a month ago? You’ve probably completely forgotten how it works.

So writing help or usage usually means that you work with an external file or multiline string. Continue reading Python textwrap – Fix Your Multiline Strings Indentation

UEFI + GPT for windows – Why so difficult

The first time I’ve laid my eye on a server with UEFI was couple of years ago. My work place bought new IBM servers and they kept crushing down mid boot or taking a very long time to boot.
I asked myself why use this new replacment for BIOS? Why do we need it – especially back then when the UEFI was very young and not that stable.

The real reason back then (to my knowledge) was the Nehalem architecture which benefited faster boot, 2T+ hard drive support and better memory access.
As said I didn’t like it back then.

Don’t take me wrong – UEFI is the future Continue reading UEFI + GPT for windows – Why so difficult

SshFS for Windows and Why

As an IT and Information Security administrator in the past and the present I’ve needed time and time again to find elaborate solutions to protect the company I’m in (several companies in the past) against threats from outside and from within (also against user’s mistakes or stupidity).

One of the main issues IT guys face are user permissions and specifically data access permissions.
For example, you don’t want a user to be able to see company bills, employee’s salaries and management documents.

One particular issue that has risen again and again in several companies I’ve worked for is the main storage handled with NFS. Continue reading SshFS for Windows and Why

32Bit in 64Bit world – or how to run Fortinet SSLVPN Client on 64Bit Ubuntu + Debian

In this new and limitless world we have 64bit cpu’s and OS (Even MinuetOS is in 64bit)
Some legacy programs insist on running in 32bit because well … the company don’t have the resources, legacy reasons or any other reason why not to (I have no real idea actually why).
Most of the new OS can also run 32bit in 64bit OS, for example: windows 64bit can seamlessly use 32bit programs without hindering. Linux on the same hand – can do that too.

So this makes me mad that despite that 64bit OSs and software; not only available for the major part of the last 7-8 years; but also in the last 4 years 64bit OSs and softwares are the majority (by far) in the industry, and yet some companies think it is O.K. to deliver only 32bit software.

Last week a colleague came to me and asked me about his 64bit Ubuntu 13.10 – for some reason the Forticlient SSLVPN Client just won’t start working. The result is unpleasant after trying to run the file, the error:

bash: ./forticlientsslvpn: No such file or directory

A little search in the internet explained that this is 32bit software and you will need to install 32bit liberaries.
My first response was – why? I’ll just login to the Fortinet site and download the 64bit version right? Wrong – they didn’t have any (but oddly for window they had 32 and 64 bit)
So ok I’ve tried to install the liberaries all the answers in the web said:

$ sudo apt-get install ia32-libs
E: Unable to locate package ia32-libs

Wait? What? Why there is no package?
Rampaging through the forums and finally after 10 minutes I’ve got to a post saying – “Sorry folks – no more ia32-libs packages in Ubuntu 13.10 they removed it”
Wait what? What should I do now?
After alot oaf searching and a lucky guess I’ve decided to install gtklib 32bit – I recalled this is the one the Fortigate SSLVPN Client is using:

$ sudo apt-get install libgtk2.0-0:i386

That did the trick!
After the installation finished no more “No such file or directory” Error; now a new and more constructive error arise:

can't find

Well that’s easy – little search and:

$ sudo apt-cache search libSM
libsm6 Description: ...
$ subo apt-get install libsm6:i386

I’ve continued  on until I’ve installed them all.
Finally after 5 more minutes the Fortinet SSLVPN Client was running!

The trick was easy:
After an error for library arose I’ve search the package containing it either with “apt-cache” “apt-file” or Googled it.
After I’ve found which liberary I need to install I’ll install it with the suffix of “:386” (so: <PACKAGE_NAME>:386) this the 32bit libs will be installed.

This trick will probably work for any 32bit software.

For the impatient one here is what you need to run in order to get Fortinet SSLVPN Client running is:

$ sudo apt-get install libgtk2.0-0:i386 libsm6:i386 libstdc++6:i386
Ubuntu 16.04 updates:

By Arnon (thank you very much!):

sudo apt-get install libcanberra-gtk-module:i386

It appears that ubuntu 16.04 have spread the files over more packages now you should add:

For those who use Debian you can follow this instruction:

By Debian – (Thank you very much!)

Under Debian you need to do this first:

# dpkg –add-architecture i386
# apt-get update

SSH Escape Characters or How to kill Dead SSH Connection

Have you ever got ssh stuck?
For years every time I’ve wanted to close the ssh session I’ve used “kill” command – Guess what? no need to.

By pressing Enter followed by Shift~ and without leaving the Shift press “.”

More options available – Just press “?” instead of “.”:

root@vps:~# ~?
Supported escape sequences:
  ~.  - terminate connection (and any multiplexed sessions)
  ~B  - send a BREAK to the remote system
  ~C  - open a command line
  ~R  - Request rekey (SSH protocol 2 only)
  ~^Z - suspend ssh
  ~#  - list forwarded connections
  ~&  - background ssh (when waiting for connections to terminate)
  ~?  - this message
  ~~  - send the escape character by typing it twice
(Note that escapes are only recognized immediately after newline.)