Click here

Friday, April 20, 2018

ldconfig , to set library path in linux

LDCONFIG
( Where are the Libs ? )


Sometimes when you install a program from source it can complain that a certain library is missing . . . and still you know that the lib it is complaining about is actually installed on your system. But most likely it is not on the default place ( /usr/lib ) where the program looks for the lib.

There is a file on your system where all the paths to the libraries are mentioned: the /etc/ld.so.conf file. Here is an example of the /etc/ld.so.conf file on Slackware:
 
QUOTE
/usr/local/lib
/usr/X11R6/lib
/usr/i486-slackware-linux/lib
/usr/lib
/opt/kde/lib


So, what's the solution ?

1). First locate the lib the program is complaining about, maybe it is in /usr/lib/qt/lib or in /usr/include or any other odd location.

2). Next add the path to that lib in the /etc/ld.so.conf file. So, for our example the /etc/ld.so.conf file would look like:
 
QUOTE
/usr/local/lib
/usr/X11R6/lib
/usr/i486-slackware-linux/lib
/usr/lib
/opt/kde/lib
/usr/lib/qt/lib
/usr/include

3). Finally to let the system know that you updated the /etc/ld.so.conf file and make it use the new values give the command:
CODE
# ldconfig

Friday, March 23, 2018

Squid stats - Beginner's guide

Squidclient is a tool that can access the squid service, and retrieve statistics on the service. For example, to get some general performance statistic, run the following command on the squid server

Friday, March 9, 2018

Docker - Beginner's guide

1) What is docker?

A client program named Docker.

A server program that manages a Linux system[ listen for messages from the command line and manages the running system].

A program that builds container's from code

A service that distributes the containers across the internet

A company that makes containers


2) What is docker container?

Self contained sealed unit of software. Contains elements required to run the code. Includes batteries and operating system

Includes - Code, configs , processes, Networking[to allow the containers to talk to other containers],dependencies and operation system.

A container image is a lightweight, stand-alone, executable package of a piece of software that includes everything needed to run it: code, runtime, system tools, system libraries, settings. Available for both Linux and Windows based apps, containerized software will always run the same, regardless of the environment. Containers isolate software from its surroundings, for example differences between development and staging environments and help reduce conflicts between teams running different software on the same infrastructure.


3) What is docker engine?

"Docker engine" is the part of Docker which creates and runs Docker containers.

Because the Docker Engine daemon uses Linux-specific kernel features, you can’t run Docker Engine natively on Windows. Instead, you must use the Docker Machine command, docker-machine, to create and attach to a small Linux VM on your machine. This VM hosts Docker Engine for you on your Windows system

Basics
A Docker container is a live running instance of a Docker image.
A Docker image is a file you have created to run a specific service or program in a particular OS.So, for example, say I want a web proxy; I can create a Docker image which is a standard install of Ubuntu 14.04 with just the squid3 package installed, and some specific configuration that I want to enforce authentication to be used with that squid proxy. I've created the docker image, but it's just a file.To use it, I need to create a Docker container which uses that file to become a live running squid VM with the config of my choice.

"Docker engine" (or just "Docker") is the program which creates and runs the Docker container from the Docker image file

Basic docker commands


  1. docker run -ti debian bash[  start an debian image with bash prompt]
-i, --interactive Keep STDIN open even if not attached

-t allocate a Pseudo TTY
-ti - terminal interactive which causes it have a full  terminal within the image so that you can run the shell and get things like tab completion and formatting to work completely

  1. docker images [ shows images]

docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
debian              latest              1b3ec9d977fb        3 weeks ago         100MB
hello-world         latest              f2a91732366c        3 months ago        1.85kB

REPOSIROY - Where it came from
TAG - Version number
IMAGE ID - internal docker representation of the image


  1. docker ps - to find running containers
root@debian:/home/saravanan# docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
0e512fe50c7b        debian              "bash"              14 seconds ago      Up 13 seconds                           gifted_mcclintock
  1. docker kill container-id  [ to kill the running container]
  2. Docker container ID and Image ID's are different
  3. docker ps -l = to display last stopped container

droot@debian:/home/saravanan# docker ps -l
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                       PORTS               NAMES
910bce8bfc26        debian              "bash"              9 minutes ago       Exited (127) 2 seconds ago                       elastic_curran

Status shows the exit status of the container

7. docker  ps -a ,  to display all the container's including stopped containers.  Suppose if you create a file and exited that container, it is called stopped container. The file created in that container will never get deleted . It's there in   a stopped container. If we execute a docker run command from an image , it will spawn a new instance of an image and it does not contain the file which was created in  another instance of an image.

8. Docker image ====>[ docker run] =====> Running container ==[exit]==> Stopped container=== [docker commit] =======> New image

9. docker commit container-id

To modify and save a container as an image

root@debian:/home/saravanan# docker  run -ti debian bash

root@70f0efed3d3f:/# ls 
bin  boot  dev        etc  home  lib        lib64  media  mnt  opt        proc  root  run  sbin  srv  sys  tmp  usr  var
root@70f0efed3d3f:/# touch HELLO-WORLD
root@70f0efed3d3f:/# exit
Exit

root@debian:/home/saravanan# docker ps -l , to list last exited container
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                     PORTS               NAMES
70f0efed3d3f        debian              "bash"              15 seconds ago      Exited (0) 2 seconds ago                       competent_boyd

Method 1
root@debian:/home/saravanan# docker commit 70f0efed3d3f [ to commit a container, input -container ID]
sha256:56eaac55c9225df65d3907f56d2d0f807470bd06b4c67f6564ef7a555e339961

root@debian:/home/saravanan#

root@debian:/home/saravanan# docker tag  56eaac55c9225df65d3907f56d2d0f807470bd06b4c67f6564ef7a555e339961 my-image [ to tag an image]

Method 2
root@debian:/home/saravanan# docker ps -l
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                     PORTS               NAMES
70f0efed3d3f        debian              "bash"              15 seconds ago      Exited (0) 2 seconds ago                       competent_boyd


root@debian:/home/saravanan# docker ps -l
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                        PORTS               NAMES
0355fd7bcf33        my-image            "bash"              4 minutes ago       Exited (127) 10 seconds ago                       heuristic_ptolemy

root@debian:/home/saravanan# docker commit competent_boyd my-image2  [ commit and tag an image, Input - container name and tag name]
sha256:496ecb935c3c72ec79381f5c89d7a4b48a9b409ddeab4ad6e1059e8862eaf444

root@debian:/home/saravanan# docker images

REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
my-image2           latest              496ecb935c3c        7 seconds ago       100MB
my-image            latest              56eaac55c922        7 minutes ago       100MB
debian              latest              1b3ec9d977fb        3 weeks ago         100MB
hello-world         latest              f2a91732366c        3 months ago        1.85kB
root@debian:/home/saravanan#


root@debian:/home/saravanan#
root@debian:/home/saravanan#
root@debian:/home/saravanan#
root@debian:/home/saravanan# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
my-image            latest              56eaac55c922        2 minutes ago       100MB
debian              latest              1b3ec9d977fb        3 weeks ago         100MB
hello-world         latest              f2a91732366c        3 months ago        1.85kB

root@debian:/home/saravanan#
root@debian:/home/saravanan#
root@debian:/home/saravanan# docker run -ti my-image
root@0355fd7bcf33:/# ls
HELLO-WORLD  bin  boot        dev  etc  home        lib  lib64  media  mnt        opt  proc  root  run  sbin  srv  sys  tmp  usr        var

root@0355fd7bcf33:/# 

Tuesday, March 6, 2018

Virtual box Full screen mode for debian

  1. Login as root;
  2. Update your APT database with apt-get update;
  3. Install the latest security updates with apt-get upgrade;
  4. Install required packages with apt-get install build-essential module-assistant;
  5. Configure your system for building kernel modules by running m-a prepare;
  6. Click on Install Guest Additions… from the Devices menu, then run mount /media/cdrom.
  7. Run sh /media/cdrom/VBoxLinuxAdditions.run, and follow the instructions on screen

Wednesday, May 31, 2017

Mercap/editcap: Files from that network type can't be saved in that format [solved]

Sometimes we do face problem in spilt/merge  packet captures taken in a different media. For example, if we capture packets in MAC operating system, we can't merge the capture files using mergecap utility. Because the files are not in libpcap format. When you try to merge/edit the files, you get the below error


Issue
mergecap  -w out.pcap VA123_00016_20170530202904 VA123_00016_20170530202905

mergecap: Can't open or create out.pcap: Files from that network type can't be saved in that format

file VA123_00016_20170530202904
VA989_00016_20170530202904: pcap-ng capture file - version 1.0


you can solve this issue with the help of tcpdump utility. With the help of tcpdump, you can convert the pcap-ng files to libpcap format 

tcpdump -r  VA123_00016_20170530202904  output.pcap

You can use the below script to merge the list of pcapng files into a single libpcap file

#!/bin/bash
for i in `ls`
do
    echo $i
    file=`echo $i | cut -d "." -f1`
    tcpdump -r $i -w $file.pcap
done
mergecap -w outputfile.pcap *.pcap

Tuesday, March 28, 2017

Install nodejs , npm and websocket in Debain wheezy

Installing npm and websocket is not so easy in Debian wheezy. You can make use of the below steps to install websocket and npm in Debian wheezy.

1) Install nodejs using the Debian package manager 

apt-get install nodejs

2) npm does not come with Debian package management system. Still there is a way 

curl https://www.npmjs.com/install.sh | sh

3) To install websocket, you need to upgrade to the latest version of nodejs and node-gyp package. You can install latest version of nodejs using nmp

npm cache clean -f
npm install -g n
n stable
n 4.7.2

4) Install node-gyp package using npm

npm install -g node-gyp

5) Finally install websocket using npm

npm install webscoket

P.S.
npm makes it easy for JavaScript developers to share and reuse code, and it makes it easy to update the code that you're sharing.

Tuesday, March 14, 2017

Debugging Signals- Log the PID of the sender

Suppose if your program randomly crashes  and you find that some process is sending SIGTERM to your program , you can find the process ID of the sender using "sigaction"


 You need to use sigaction call to set up your signal handler instead of signal. Doing so will let you set up a signal handler that takes three parameters:

  • An int, for the signal number (just like signal)
  • A siginfo_t *, which is a structure containing all sorts of information about the source of the signal, including the pid of the sender if applicable. (It also includes some information about the cause of the signal for automatic signals like SIGSEGV.)
  • A ucontext_t *, which has to do with which thread got the signal. Mostly ignorable


Example code and steps:

1) catchsignal.c

"/* Example of using sigaction() to setup a signal handler with 3 arguments
 * including siginfo_t.
 */
#include <stdio.h>
#include <unistd.h>
#include <signal.h>
#include <string.h>
 
static void hdl (int sig, siginfo_t *siginfo, void *context)
{
 printf ("Sending PID: %ld, UID: %ld\n",
   (long)siginfo->si_pid, (long)siginfo->si_uid);
}
 
int main (int argc, char *argv[])
{
 struct sigaction act;
 
 memset (&act, '\0', sizeof(act));
 
 /* Use the sa_sigaction field because the handles has two additional parameters */
 act.sa_sigaction = &hdl;
 
 /* The SA_SIGINFO flag tells sigaction() to use the sa_sigaction field, not sa_handler. */
 act.sa_flags = SA_SIGINFO;
 
 if (sigaction(SIGTERM, &act, NULL) < 0) {
  perror ("sigaction");
  return 1;
 }
 
 while (1)
  sleep (10);
 
 return 0;
}

2) Compile the program 
    gcc -o catchsignal catchsignal.c


3) Shell script to trigger a signal 

sendsig.sh
#!/bin/sh
while [ 1 ]
do
    pidof=`ps -ef | grep catchsignal | grep -v "grep" | awk  '{print $2}'`
    if [ ! -z $pidof ]
    then
        kill $pidof
    fi
sleep 10
done

4) Execute the script
   sh sendsig.sh

5) Run the program 
    ./catchsignal


6) Output of the program


Sending PID: 18532, UID: 0 
Sending PID: 18532, UID: 0
Sending PID: 18532, UID: 0



Omicron - people gathers in crowd

Amidst omicron thread, people are gathered in crowd at markets and public places to buy their daily needs. Because of full lockdown at Sunda...