Posts Tagged ‘chunk’

Linux bash: Add line numbering to text file with NL – number lines command

Friday, March 22nd, 2013

Lets say you have a plainjt text TXT file with sentences and you would like to put quickly line numbering in a Linux bash shell. First thing that might pop up to your mind is to use a loop cat text file and print it line by one together with output of incremental values counted from 0 to the number of lines the file contains. This would work but is useless work. As coreutils package already contains a tool called nl ( /usr/bin/nl ). Here is paste from header of nl manual page;


       nl – number lines of files

       nl [OPTION]… [FILE]…

Thus to put line numbering to lets say this fortune's bible quotes plain text file;

$ nl bible > bible_quotes_numbered.txt

Here is a small chunk of bible_quotes_numbered.txt;


$ cat bible_quotes_numbered.txt

 1  In the beginning God created the heaven and the earth.
     2                  — Genesis 1:1
     3  %
     4  And the earth was without form, and void; and darkness was upon
     5  the face of the deep. And the Spirit of God moved upon the face of
     6  the waters.
     7                  — Genesis 1:2
     8  %
     9  And God said, Let there be light: and there was light.
    10                  — Genesis 1:3
    11  %
    12  And God saw the light, that it was good: and God divided the light
    13  from the darkness.
    14                  — Genesis 1:4
    15  %
    16  And God called the light Day, and the darkness he called Night.
    17  And the evening and the morning were the first day.
    18                  — Genesis 1:5
    19  %
    20  And God said, Let there be a firmament in the midst of the waters,
    21  and let it divide the waters from the waters.
    22                  — Genesis 1:6
    23  %
    24  And God made the firmament, and divided the waters which were under
    25  the firmament from the waters which were above the firmament: and
    26  it was so.
    27                  — Genesis 1:7
    28  %
    29  And God called the firmament Heaven. And the evening and the morning
    30  were the second day.
    31                  — Genesis 1:8
    32  %
    33  And God said, Let the waters under the heaven be gathered together
    34  unto one place, and let the dry land appear: and it was so.
    35                  — Genesis 1:9
    36  %
    37  And God called the dry land Earth; and the gathering together of
    38  the waters called he Seas: and God saw that it was good.
    39                  — Genesis 1:10
    40  %
    41  And God said, Let the earth bring forth grass, the herb yielding
    42  seed, and the fruit tree yielding fruit after his kind, whose seed
    43  is in itself, upon the earth: and it was so.
    44                  — Genesis 1:11


It is worthy mentioning the same opeartion can be achieved with good old /bin/cat with cat -n, e.g.;

$ cat -n bible >bible_quotes_numbered.txt


On *BSDs nl command is not available, thus cat -n is very good to know of since it works for numbering ASCII plain text files on Free/Net/OpenBSDs

How to get full host and IP address of last month logged in users on GNU / Linux

Friday, December 21st, 2012

This post might be a bit trivial for the Linux gurus, but for novices Linux users hopefully helpful. I bet, all Linux users know and use the so common used last command.

last cmd provides information on last logged in users over the last 1 month time as well as shows if at present time of execution there are logged in users. It has plenty of options and is quite useful. The problem with it I have often, since I don't get into the habit to use it with arguments different from the so classical and often used:

last | less

back in time when learning Linux, is that whether run it like this I can't see full hostname of users who logged in or is currently logged in from remote hosts consisting of longer host names strings than 16 characters.

To show you what I mean, here is a chunk of  last | less output taken from my home router

# last|less
root     pts/1        ip156-108-174-82 Fri Dec 21 13:20   still logged in  
root     pts/0        ip156-108-174-82 Fri Dec 21 13:18   still logged in  
hipo     pts/0        ip156-108-174-82 Thu Dec 20 23:14 - 23:50  (00:36)   
root     pts/0        g45066.upc-g.che Thu Dec 20 22:31 - 22:42  (00:11)   
root     pts/0        g45066.upc-g.che Thu Dec 20 21:56 - 21:56  (00:00)   
play     pts/2 Thu Dec 20 17:30 - 17:31  (00:00)   
play     pts/2 Thu Dec 20 17:29 - 17:30  (00:00)   
play     pts/1 Thu Dec 20 17:27 - 17:29  (00:01)   
play     pts/1 Thu Dec 20 17:23 - 17:27  (00:03)   
play     pts/1 Thu Dec 20 17:21 - 17:23  (00:02)   

root     pts/0        ip156-108-174-82 Thu Dec 20 13:42 - 19:39  (05:56)   
reboot   system boot  2.6.32-5-amd64   Thu Dec 20 11:29 - 13:57 (1+02:27)  
root     pts/0        e59234.upc-e.che Wed Dec 19 20:53 - 23:24  (02:31)   

The hostname last cmd output as you can see is sliced, so one cannot see full hostname. This is quite inconvenient, especially, if you have on your system some users who logged in with suspicious hostnames like the user play which is a user, I've opened for people to be able to play my system installed Cool  Linux ASCII (text) Games. In normal means, I would skip worrying about the…..  user, however as I've noticed one of the ascii games similar to nethack called hunt was kept hanging on the system putting a load of about 50% on the CPU   and was run with the play user and according to logs, the last logged in username with play was containing a hostname with "" as a hostname.

This looked to me very much like a script kiddie, attempt to root my system, so I killed hunt, huntd and HUNT hanging processes and decided investigate on the case.

I wanted to do whois on the host, but since the host was showing incomplete in last | less, I needed a way to get the full host. The first idea I got is to get the info from binary file /var/log/wtmp – storing the hostname records for all logged in users:

# strings /var/log/wtmp | grep -i vexploit | uniq

To get in a bit raw format, all the hostnames and IPs (whether IP did not have a PTR record assigned):

strings /var/log/wtmp|grep -i 'ts/' -A 1|less

Another way to get the full host info is to check in /var/log/auth.log – this is the Debian Linux file storing ssh user login info; in Fedora and CentOS the file is /var/log/secure.

# grep -i vexploit auth.log
Dec 20 17:30:22 pcfreak sshd[13073]: pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser=  user=play

Finally, I decided to also check last man page and see if last is capable of showing full hostname or IPS of previously logged in hosts. It appears, last is having already an argument for that so my upper suggested methods, turned to be useless overcomplexity. To show full hostname of all hosts logged in on Linux over the last month:

# last -a |less

root     pts/2        Fri Dec 21 14:04   still logged in
root     pts/1        Fri Dec 21 13:20   still logged in
root     pts/0        Fri Dec 21 13:18   still logged in
hipo     pts/0        Thu Dec 20 23:14 - 23:50  (00:36)
root     pts/0        Thu Dec 20 22:31 - 22:42  (00:11)
root     pts/0        Thu Dec 20 21:56 - 21:56  (00:00)
play     pts/2        Thu Dec 20 17:30 - 17:31  (00:00)
play     pts/2        Thu Dec 20 17:29 - 17:30  (00:00)
play     pts/1        Thu Dec 20 17:27 - 17:29  (00:01)
play     pts/1        Thu Dec 20 17:23 - 17:27  (00:03)
play     pts/1        Thu Dec 20 17:21 - 17:23  (00:02)
root     pts/0        Thu Dec 20 13:42 - 19:39  (05:56)
reboot   system boot  Thu Dec 20 11:29 - 14:58 (1+03:28)    2.6.32-5-amd64
root     pts/0        Wed Dec 19 20:53 - 23:24  (02:31)

Listing all logged in users remote host IPs (only) is done with last's "-i" argument:

# last -i
root     pts/2   Fri Dec 21 14:04   still logged in  
root     pts/1   Fri Dec 21 13:20   still logged in  
root     pts/0   Fri Dec 21 13:18   still logged in  
hipo     pts/0   Thu Dec 20 23:14 - 23:50  (00:36)   
root     pts/0      Thu Dec 20 22:31 - 22:42  (00:11)   
root     pts/0      Thu Dec 20 21:56 - 21:56  (00:00)   
play     pts/2  Thu Dec 20 17:30 - 17:31  (00:00)   
play     pts/2  Thu Dec 20 17:29 - 17:30  (00:00)   
play     pts/1  Thu Dec 20 17:27 - 17:29  (00:01)   
play     pts/1  Thu Dec 20 17:23 - 17:27  (00:03)   
play     pts/1  Thu Dec 20 17:21 - 17:23  (00:02)   
root     pts/0   Thu Dec 20 13:42 - 19:39  (05:56)   
reboot   system boot          Thu Dec 20 11:29 - 15:01 (1+03:31)  

One note to make here is on every 1st number of month last command  clear ups the records storing for user logins in /var/log/wtmp and nullifies the file.

Though the other 2 suggested, methods are not necessary, as they are provided in last argument. They're surely a mus do routine, t when checking a system for which doubting it could have been intruded (hacked). Checking both /var/log/wtmp and /var/log/auth.log / and /var/log/auth.log.1 content and comparing if the records on user logins match is a good way to check if your login logs are not forged. It is not a 100% guarantee however, since sometimes attacker scripts wipe out their records from both files. Out of security interest some time, ago I've written a small script  to clean logged in user recordfrom /var/log/wtmp and /var/log/auth.log – – the script has to be run as a super to have write access to /var/log/wtmp and /var/log/auth.log. It is good to mention for those who don't know, that last reads and displays its records from /var/log/wtmp file, thus altering records in this files will alter  last displayed login info.

Thanks God in my case after examing this files as well as super users in /etc/passwd,  there was no  "signs", of any succesful breach.


Three Ways to Reduce Addiction to Mobile Phone ( GSM ) use

Wednesday, June 27th, 2012

Mobile Phone Caricature Reduce Mobile Addiction / 3 ways to reduce mobile phone addiction / Use your Mobile less

1.: Don't use a ring tone or use a short landline phone ringtone on incoming calls

In the past, we all had a local stand line phones, most of the landline phones rung using a very specific ring sound which was almost identical on all phones around the world. This ringing tone used was following some telephone standards. The result was everyone could distinguish a ringing phone in a room or closed space and tell for sure, this sound is generated by a phone. Nowdays with the boom of cellular phone ringtones, there is almost noone who uses a standard old-fashioned telephone ringtone as a ring melody.

The consequence of this is in our minds we start loosing the boundary between whether communicating on the phone or communicating without it.
In younger people this boundary between phone line and a physical communication is more evident than in adults (as youngsters has grown in society where mobile was used everywhere). The implication of this is more and more people are starting to perceive mobile communication as so natural as the person to person communication. Spending big part of the day talking over the phone mostly senseless things, not being consciously aware that this is done due to a heavy phone addiction and repeating behaviour trait stored sub-consciously.

Today everyone chooses a custom mobile phone ringtone melody (popular or impopular) song and sets it up to be a standard incoming call signal. As you can guess there are consequences on the mind, as the ringtone set is heard ten times or more a day during each and every phone call. The result is just like with alcoholics or drug addicts, the more you take from a certain "good" the more attached you become to it. Hence the more we listen to a certain song chunk daily on incoming calls, the sub-conscious becomes dependent on hearing this sound at least a number of times daily. If a day passes without no-one calling us and we don't hear the ringtone indicating a call the sub-conscious stored dependency starts popping up and we could start feeling lonely and we feel like calling someone (and we often do). Obviously this is dependency and even if someone might argue me this is a severe addiction which as every other addiction could be very dangerous and hard to fight.

As I prior said due to the fact that the phone use dependency is built in our minds starting with the phone ring melody, we can reduce this dependency by switching off the phone ringtone completely or at least changing it to a unique beep which is not likely to be heard or seen somewhere in your surrounding environment.

By setting the ringtone to some popular song we see on (TV, Radio or Internet on daily basis) this might become a trigger for us to associate hearing this sound with talking on the phone and hence make you increase the time you spend on the phone ,,, so be careful ,,,,

2.:: Stop Mobile Beeps and sounds on menu navigation

All new mobiles sold on the market are configured to have buzzling sounds on events and various beeps on keypad lock / unlock and menu navigation.
This sounds are there mostly to make you more alert and concentrated on using your mobile and often as a consequence whether one uses his mobile his awareness is comletely taken by the phone screen (you're totally "absorbed" by the phone use).
Besides designed to alert you the Managers and CEO's who decided to have a heavy beep sounds on mobiles made it having probably something else on mind? The beeps on keypad navigation makes the user emotionally and sub-consciously attached to the Cell Phone. The idea here is like in popular music streamed on radios and TVs and mostly everywhere …. The more you listen to a song, the higher the mind trait it leaves in you, so later when one hears a music pattern or a whole song, which he / she listened already thousands of times this brings back "good" old memories. It is very simple actually our minds are constructed in a way that the mor certain "information" is heard / saw / smell the bigger the mind influence this leaves on us. Back to the mobile sounds, the more you use the mobile phone with turned on sounds, the more addicted and mind stucked the beep and melodies during use of the cell phone becomes in the mind. For example many people take a look at their mobile automatically (without being consciously aware) and do the activity of (unlock) and (lock) the phone screen not knowing they do it automatic. More or less we all do such an auto-mated learned behaviour because of the subconscious dependency that is built in our minds. Whether we lock and unlock the mobile phone almost robotically, we do it because our sub-conscious mind plays a trick on us and "force" us to do a previous learned activity (association in our mind with the unlock / lock beep sound).

3.::: Use your mobile in different ways

Any modern mobile is quite advanced in functionality and there is more than one way to initiate a phone call. E.g. the mobile has a shortcut buttons assigned to do quick phone calls, quickly evoke SMS menu etc.
Learn them and occasionally use the shortcut buttons instead of the menu navigation. Our minds like changing patterns and doing things different.

Even if you have no chance to do a things via a certain menu, you can always change the position of the phone screen to different distance to eyesight 🙂 You can for example type on the keypad following the menu steps by watching from left or right eye periphery or you can use the menus with your phone screen turned backwards 🙂 If you're used to type on the keypad or touch screen with right hand try doing it with the left hand 🙂

This will take time but the fun worths it. Plus the most valuable thing in using the mobile in different ways each time is there is no specific inflicting pattern associated in your mind and hence the depepdency set in your sub-conscious mind on phone use is lesser.
Actually there are too many various "hacks" one could come up with on how to use mobile as differently as possible. It is up to your imagination. Though using the mobile "each-time-different" can be sometimes more time-consuming it surely makes your phone use amusing.

How to reduce spam in PHPBB based internet forum on Debian GNU / Linux

Monday, March 26th, 2012

phpbb reduce spam bot registrations on Debian Linux tiny script

I had to install two PHPBB based internet forums, some long time ago. Since long time passed and I haven't checked what's happening with them I just noticed. They start filling up spam threads. The phpbb installations are done using the standard shipped deb packages in Debian Linux Lenny.

After checking online, I found one smart solution to . The idea is very simple most spam bots are written in a way that they don't have a properly set timezone. Therefore the quickest way to get rid of spam bots which try to auto register and put spam content inside the a forum category or post is to add a simple if condition in php to check the browser set timezone:

The file to add the php if condition is ucp_register.phpThe phpbb package install places default phpbb path on Debian is /usr/share/phpbb3/ and hence the file I had to modify is located in:


To make the TZ check one needs to modify ../www/includes/ucp/ucp_register.php and look for php array definition:

$data = array(
'username' => utf8_normalize_nfc(request_var('username', '', true)),
'new_password' => request_var('new_password', '', true),
'password_confirm' => request_var('password_confirm', '', true),
'email' => strtolower(request_var('email', '')),
'email_confirm' => strtolower(request_var('email_confirm', '')),
'confirm_code' => request_var('confirm_code', ''),
'lang' => basename(request_var('lang', $user->lang_name)),
'tz' => request_var('tz', (float) $timezone),

Right after this chunk of code add the if condition code which is like so:

if ($data['tz'] == '-12.00')
die('Die, bot! Die.');

From now onwards, any attempt for new user registration with an incorrect timezone of -12.00 will be immediately stopped while the forum spammer bot will be offered an empty page 🙂

Another good practice is to disable Birthday Listing from phpbb Admin Control panel (ACP). Go to menus:

ACP -> General -> Board Settings -> Enable Birthday listing: (No)

Enable birthday listing phpbb forum screenshot

I like disabling birthday listing, as when it is enabled and you have some spammer registrations, which even though didn't succeeded to contaminate your forum content has specified a birthday and therefore there profiles gets popping up each different day on the main page of the forum.
This will not eradicate all spammer bots, but at least will significantly decrease spammer bot registrations.

How to check if newly installed SSL certificate for IMAP and IMAPS is properly installed

Tuesday, June 28th, 2011

Did you have to regenerate your SSL certificate for your mail server’s IMAP and IMAP SSL service?
Did you have to find out if the newly installed certificates are fine after install?

Here is how:

          root@server-hosting [/usr/local ]# openssl s_client -connect
root@server-hosting [/usr/local ]# openssl s_client -connect -starttls imap

The output returned by this two commands will be the imap and imaps configured certificates as well as extensive info concerning the installed SSL, the last chunk of info to be spit is most crucial to know if certificate is fine.
It should be something like:

New, TLSv1/SSLv3, Cipher is AES256-SHA
Server public key is 1024 bit
Secure Renegotiation IS supported
Compression: NONE
Expansion: NONE
Protocol : TLSv1
Cipher : AES256-SHA
Session-ID: 0B69E91022CB56D64F56CFA08405944D9C4C0069EE4097890B98F1406CF084D5
Master-Key: 13745B94E0C5A0604EB7529E7409251961DFD5F4134F3A8F
Key-Arg : None
Start Time: 1309265383
Timeout : 300 (sec)
Verify return code: 18 (self signed certificate)
. OK CAPABILITY completed

The no-ego deadly body and soul (anti-christian) philosophy a trend in modern Business – think always positive be always positive

Friday, June 17th, 2011

Modern day Business training Sect picture

These days it’s ultra modern in Business and Business Communities, that the way business is made or business possibilities are discussed are directly influenced by altered understanding of Buddhistic world views.

Today less and less people realize that the modern day Western and Eastern Christian countries are rapidly loosing their Christian mark.
It was Christianity and Christian philosophy, thanks to which Christian countries has advanced to the material goodness level, architectural greatness, science improvements and civilization achievements that we the Europeans and other Western societies like Americans enjoy today.

As time ticks on the world is constantly becoming more and more Anti-Christian. From the times when Christianity was officially wide-spread and accepted and being a Christian was a sign for personal qualities and goodness, it’s now considered to be almost a crime or being insane if you have faith in Jesus Christ as God’s Son and a Saviour of mankind.

Business ethics practices from the past, which were often based on Christian ethics has also seriously changed these days.

It was due to Christianity and the Christian civillization due to which we had a dozens of genuine musician like: J. S. Bach, Beethoven, Verdi, Brahms, Tschaikovsky etc. the list of great people and musicians goes innumerous here.

The Roman Catholic and Easter Orthodox Christians thanks to which works, science has advanced is also innumerous, just to name a few for instance:

Nicolaus Copernicus, Galileo Galilei, Max Planck, Marie Curie, Theodosius Dobzhansky, Isaac Newton, James Clerk Maxwell, Johannes Kepler

again this is just a small chunk of all the great Christian people who by their talents has revolutionized the world for good.

However nowdays education is changed seriously and as many people should have noticed Christianity and historic relation between science and Christianity is trying to be covered.
Moreover the historic importance of Christian faith and it’s surrounding philosophy is forgotten, not to mention that officially the history of the world until the 18 century is mostly, a history of Christianity and it’s influence on society.

In these days of Christian apostacy, many of the business people in their look up for ways to become superior and rule over the masses has turned into various long forgotten sects and heresies which were publicly announced by ancient Christian Church as body and soul destroying dangerous teachings.

It’s trendy today that the confucionism or hindu influenced beliefs about the world and the way stuff works, are preached and used in businesses and business organizations.
Dalai Lama Enemy of Christianity

It’s classics nowdays that people run a business, after building a group of people, over which hierarchical manipulation based leadership is exercised.

Most oftenly people who enter into a new business field, try build a groups of people who are introduced without having conscious idea to veiled alterated buddhistic philosophy to match certain people’s idea or beliefs about the world.

These groups usually consist of people ranging from hundereds to thousands. Usually each of these business groups created, has a leader who is both leader in terms of (being the group boss / executive) and also a spiritual leader.

Interaction between the group members are purely based on manipulation. People are teached they have some special sensitivity for the surrounding environment which they can develop.
They’re teached they must always be positive, the group leaders (teachers) does try to suggest to the group what the group members understanding of positive should be.

In those business groups, people are taught by the leaders to be positive, while the leaders themselves are not positive (one cannot be positive without God!). People are constantly told “be positive”, “be positive”, while the people who teach them this are not positive at all and evil often cruel!
In other words group members are being re-taught the basics of how they perceive themselves and how they should perceive the world around them in a light that fits well with the business organization they’re membering in.
Consequently people are taught to loose their ego.
Loose Ego surrealism picture

This is one of the most essential parts of this modern day business false teachings. In reality loosing the ego is loosing one’s standing ground and through that the person in the group becomes easily manipulated by other group members.

When people loose their ego basicly they loose their protection against being easily manipulated, they loose their idea about what is good and what is bad, what is right and what is wrong and who in reality they’re.

I believe also the no-ego philosophy has also a straight relation with the modern day society problem of NO IDENTITY issue , I have previously blogged about.

Being exposed to this “business” approaches in that poor state one start easily accepting suggestions from the group leaders or other group members and could end up in a state where he is totally manipulated (a spiritual slave of the group leader GURU).

After time passes and a person is involved in so many meetings, the group members gets so much bounded together that they have to constantly meet each other and discuss things, (often senseless things), nevertheless the pointlessness of the many discussions this meetings starts giving them the feeling of great importance or in other words reveals them the ultimate life meaning.

Consequently, when the new business group entity is tight enough, the group is instructed by the leaders about what kind of business moves will be best for each of the group individuals and the overall business the group belongs to.
At this state each of the members should obey wholeheartedly, if somebody tries to question the leadership decisions, the leader does incite the whole group members against the disobeying member and usually the members gets destroyed.

These business group building philophy is also influenced by antrophology and observence of animal behaviour’s let’s say coyottes or wolves.

In animal world usually each pack of wolves had their leader and the pack only attacks if the leader hits and if the whole group is together.
Same kind of thing comes to business built entities based on this loose your ego / no-ego philosophies.
modern business group building - a spiritual babylon

A lot of pseudo beliefs about para-psychology and experimental western psychology is also involved and preached to the group members.
Loosing the ego philosophy in Business is directly influenced by buddhistic idea about Nirvana and spilling the self in the ultimate worldly reality (e.g. becoming one with the whole nature).
This kind of belief is seriously anti-christian and against the spiritual goal in christianity which is not the emptiness like in buddhism and the other eastern religions, but the goal is fullness in God.

We the Christians are striving to fill ourselves with God’s Spirit – The Holy Spirit, whether buddhists are trying to empty themselves by everything that’s binding them to reality (obviously they also try to empty themselves by God who has initially created man as his vessel).

Also in business, I’ve noticed in my experience that it’s common people who are taught business in universities or are introduced to business are taught philosophies which are very typical for western buddhist teachings.
Just like in buddhism people are taught there is no absolute good or evil and there is no good and bad and everything one does is good, if he sees it as good (we’re the one who define our lifes and realities)!!

Think for a while and see for yourself how insane this kind of philosophy is, let’s say I kill a man who I hate, that’s fine according to this philo because I believe this man’s existence was not good in my view and his unexistence will make the world a better place, since I believe it’s that way then it’s that way DOT!!!As a Christian I must confess this is ULTIMATE INSANITY, AN ULTIMATE LIE obviously inspired by the evil which is an enemy to us the Christians as the Holy Bible teaches.

This kind of “no good and bad” philosophy is a hidden assault against our Christian roots society, faith and civillization. In Christianity we’re clearly taught there is ultimate good an ultimate evil and there is no in between!
We are also taught one can become part of the ultimate good or ultimate evil by his daily choice, e.g. (get closer to God and his Holy Angels or distance himself from God and come near the devil and his fallen angels).

Mixing spirituality and business concepts has become a sad reality of our age, I’ve seen many books being sold which were claiming to teach, “how to do business based on Zen Buddhism and other eastern religions and philosophies.

What’s even worse is that people who are involved into this kind of “innovative” taught business approaches guarantee themselves to get exposed to the ultimate evil spirituality (devilish spiritual influence), as they openly reject God’s dominion over one’s self and the world around them.

The good news is that they’re many Christian Business communities as I’ve checked online, there are many people yet who do their best to do business with other Christians or people who still keep the Christian faith and morale.