Thursday, May 8, 2014

The watch command

A very nice command to watch something in linux

watch -n1 "sudo netstat -antp | grep -i listen"

this will show you on the screen the output of sudo netstat -antp | grep -i listen every "1" second. 

Screen command in Linux

Its the end of your day at work and at the last moment , you were asked to run a script to generate a report. This script would take around 30 mins to run and you only have 5 mins to catch the bus that takes you home.. what do you  do???

One option is for you to run the script as a backgroup nohup process and redirect logs to a file, get back home and look at the logs.

Screen is the other thing that can help you here. With screen you can leave the script running on the machine and get back home and connect back to see the output terminal instead of the log file. 

How to use screen:

- screen -S "screen-name"                  to start a screen

eg: screen -S 70mm 

This will start the screen-name with 70mm in it.


- screen -ls                                        to list all screens
There is a screen on:
        15902.70mm      (Attached)
1 Socket in /var/run/screen/S-sanjeevn.

Attached means that you are right now inside the screen itself i.e: connected to the screen. You can start runnign the script here wil make it run continusoulsy

example:

while true
> do
> echo "Press [CTRL+C] to stop.."
> sleep 1
> done
Press [CTRL+C] to stop..
Press [CTRL+C] to stop..
Press [CTRL+C] to stop..

- ctrl-a-d                                            to detach from a screen

This will detach you form the screen and bring you back to the original terminal

[detached]
["user-name"@greenshot-dl image]

- screen -r "screen-name"                     to connect to a screen name obtained from the above command
eg: 
screen -r 15902.70mm  (obtained form the screen -ls command )

lo and behold the script is still running

Press [CTRL+C] to stop..
Press [CTRL+C] to stop..
Press [CTRL+C] to stop..
Press [CTRL+C] to stop..
Press [CTRL+C] to stop..
Press [CTRL+C] to stop..
Press [CTRL+C] to stop..
Press [CTRL+C] to stop..
Press [CTRL+C] to stop..
Press [CTRL+C] to stop..

- ctrl-d                                               to stop a screen
[screen is terminating]

Friday, February 18, 2011

LD_LIBRARY_PATH: how to make sure nelwy installed binaries' locations are a part of the LD_LIBRARY_PATH

This was on a Suse Linux 11 64 bit machine.

I installed two thridparty softwares freetds and unixodbc. After the customary installation steps of unixodbc. I installed freetds with the following set of commands

./configure --with-unixodbc=/usr/local
make
make install

Both the softwares generated a few so files and placed it under /usr/local/lib ( could be lib64 as well). If it places in lib64 , then you will not need to worry about the next few steps. However in my case the binaries were put into /usr/local/lib

To make the binaries available in the LD_LIBRARY_PATH, I followed the below steps

vi /etc/ld.so.conf; add /usr/local/lib i.e: the path where both freetds and unixodbc binaries are installed
ldconfig ; this is run to include the newly added lib path into the LD_LIBRARY_PATH
ldconfig -p | grep libtdsodb; to check if I will be able to find the newly added nbinaries eg: libtdsodb using the LD_LIBRARY_PATH set by the system

Just to check if my database connections were working

cp *.ini /usr/local/etc/ ; these ini's are pre configured with the database ip addresses and the

connection details
To test if DB connects, use the below command

isql -v MSSQLTestServer sa admin
+---------------------------------------+
| Connected! |
| |
| sql-statement |
| help [tablename] |
| quit |
| |
+---------------------------------------+
SQL>

Bullseye error while executing through hudson/jenkins job on windows

I was unable to execute any commands of cov01.exe on windows through hudson . whereas form the systems command prompt all commands worked fine. Through the hudson job , I was getting an error

Exception: cannot determine home directory

I could not find out the exact solution to this. But I did find a workaround. I had to set a few environment variables

set APPDATA=C:\Documents and Settings\build\Application Data
set HOMEDRIVE=C:
set HOMEPATH=\Documents and Settings\build

The problem seems to be because the Bullseye needs a home directory to start its operations which for some strange reason was not being set from the hudson job.

Wednesday, February 16, 2011

Increase the Number of open files

In Hudson/Jenkins, we were unable to open a new session through the browser. However what I noticed on looking at the hudson logs was that the sessions were running in the background. However we did find a SEVER error message which said the
"(Too many open files)"

When I ran an lsof | wc -l it was almost at 1247
however as you can see from the below command , the limit for number of open files was set to 1024

# ulimit -a
core file size (blocks, -c) 0
data seg size (kbytes, -d) unlimited
scheduling priority (-e) 0
file size (blocks, -f) unlimited
pending signals (-i) 139264
max locked memory (kbytes, -l) 32
max memory size (kbytes, -m) unlimited
open files (-n) 1024
pipe size (512 bytes, -p) 8
POSIX message queues (bytes, -q) 819200
real-time priority (-r) 0
stack size (kbytes, -s) 10240
cpu time (seconds, -t) unlimited
max user processes (-u) 139264
virtual memory (kbytes, -v) unlimited
file locks (-x) unlimited

To resolve this, and to increase the number of open files that are allowed in the system, I did the below..


edit the /etc/security/limits.conf and add the following.
* soft nofile 4096
* hard nofile 4096

This means that for every user ( indicated by *) , the maximumm number of open files would be 4096. Instead of specifying *, you can specify the user-name .
You will have to restart the service, and exit the session for the new ulimit values to be in place.

# ulimit -a
core file size (blocks, -c) 0
data seg size (kbytes, -d) unlimited
scheduling priority (-e) 0
file size (blocks, -f) unlimited
pending signals (-i) 139264
max locked memory (kbytes, -l) 32
max memory size (kbytes, -m) unlimited
open files (-n) 4096
pipe size (512 bytes, -p) 8
POSIX message queues (bytes, -q) 819200
real-time priority (-r) 0
stack size (kbytes, -s) 10240
cpu time (seconds, -t) unlimited
max user processes (-u) 139264
virtual memory (kbytes, -v) unlimited
file locks (-x) unlimited


A FEW commands that I had run to understand the various system parameters. Putting it down here for future reference

lsof -p

cat /proc/sys/fs/file-max

sysctl -a

/etc/sysctl.conf

sysctl -p

Wednesday, September 15, 2010

rm: 0653-611 Directory not empty in aix

This was happening on aix. I was unable to remove a folder . The error it gave was

rm: 0653-611 Directory "xyz " not empty

The issues seems to be because of Unreferenced directory in the filesystem.

I had to un-mount the partition and run an fsck on the filesystem.

fsck /home

FSCK output
===========================================
** Checking /dev/rhd1 (/home)
** Phase 1 - Check Blocks and Sizes
** Phase 2 - Check Pathnames
** Phase 3 - Check Connectivity
Unreferenced directory I=7743662 owner=bin mode=240750
size=512 mtime=Sep 13 08:00 2010 ; RECONNECT? YES
Directory Inode=7743662 connected, parent was Inode=8990791
Unreferenced directory I=8984658 owner=bin mode=240750
size=512 mtime=Sep 14 03:11 2010 ; RECONNECT? y
Directory Inode=8984658 connected, parent was Inode=8990791
** Phase 4 - Check Reference Counts
link count directory I=7743662 owner=bin mode=240750
size=512 mtime=Sep 13 08:00 2010
count 1 should be 2; ADJUST? y
link count directory I=8984658 owner=bin mode=240750
size=512 mtime=Sep 14 03:11 2010
count 1 should be 2; ADJUST? y
** Phase 5 - Check Inode Map
** Phase 6 - Check Block Map
526042 files 51713965 blocks 78833747 free
================================================

Once the fsck was done.. After remounting the partition , I was able to remove the folder.

Thursday, March 11, 2010

Merge PDfs into a single PDF file - windows

http://www.codejacked.com/combine-multiple-pdfs-into-one-merged-document/