Insert Multiple New Line in a File Using Shell Script?

Posted on

Insert Multiple New Line in a File Using Shell Script?

Do you want to insert multiple lines below of a specific line sed command will help us with different cases,

For example few lines saved in a file name of linuxfaq.txt that contain

colors
scripts
dash
ftpsh

but i would like to add three lines one by one “red, green, blue” next line of colors

Note : -i specified that save the changes in file

1
2
sed -i "/colors/ared\ngreen\nblue" linuxfaq.txt

Read the rest of this entry »

Reference : thelinuxfaq

How to Configure LogRotate in Linux

Posted on

First you have to update in mongoDB configure file /etc/mongod.conf.

1
2
3
4
systemLog:
  logAppend: true
  logRotate: reopen

Then, you can use this logrotate configuration: /etc/logrotate.d/mongodb

1
2
3
4
5
6
7
8
9
10
11
12
13
14
/var/log/mongodb*.log {
    daily
    rotate 30
    size 50M
    compress
    dateext
    missingok
    notifempty
    sharedscripts
    postrotate
        /bin/kill -SIGUSR1 `cat /var/lib/mongodb/mongod.lock 2> /dev/null` 2> /dev/null || true
    endscript
}

Use below command, If you would check immediately whether above config file is working good.

1
# logrotate -f /etc/logrotate.d/mongodb

 

Reference : thelinuxfaq

dpkg Command Usage and Example Ubuntu

Posted on

It is very useful tool for install, build, manage and remove packages. Also can support debian/Ubuntu based operating system, like Mint,kubuntu,etc. We cannot download and install packages automatically. This post describe how to maintain the dpkg on the system.

1. How to Install a Package:

-i is to be install .deb package or we can use –install. For example,

# dpkg -i packagename.deb
1
2
dpkg -i firefox-mozilla-build_31.0-0ubuntu1_amd64.deb

2. List Installed Packages:

List all the installed packages on your system use -l

1
dpkg -l

or

1
dpkg --get-selections

Read the rest of this entry »

Reference : thelinuxfaq

Shell Script TCPDUMP Output Stores in a Log File

Posted on

You can then configure and compile the source via the normal GNU autoconf method.

The simple shell script do take a backup current tcpdump logs  every 10 minutes into a tcpdump.log in your home directory

1
2
3
4
5
#!/bin/bash
/usr/sbin/tcpdump -i eth0 ip >> ~/tcpdump.log &
sleep 5m
pkill -9 tcpdump

If you would like to set the cron job every 10 minutes,

Open a crontab file

1
2
3
4
# vim /etc/cron/crontab
 
0,10,20,30,40,50 * * * *  /bin/sh /root/check_tcpdump.sh

You might restart the cron service.

Reference : thelinuxfaq

How to Get Coredump file in Linux

Posted on

running process and its process status, to find out getting a segmentation fault.

1
ulimit -c unlimited

then that will tell bash that its programs can dump cores of any size.  You can specify a size such as 52M instead of unlimited if you want.

You can set core file size unlimited in your .bashrc file,

1
2
3
4
5
sudo vim ~/.bashrc
ulimit -c unlimited
sudo source ~/.bashrc

Get the coredump file from running process using below command,

gcore 

gcore [file] : The optional argument file specifies the file name where to put the core dump.

You can generate a core dump for a hung process using this command,
Read the rest of this entry »

Reference : thelinuxfaq

Filter Private IP Address

Posted on

there are a number of different ways to install the AWS CLI, depending on your operating system,

The below steps are common to install,

Download the awscli-bundle file with .zip format and extract

step 1:

1

step2:

1
$ unzip awscli-bundle.zip

Read the rest of this entry »

Reference : thelinuxfaq

Install libssl-dev in Ubuntu

Posted on

protocols for secure communication over the Internet. It contains development libraries, header files, and man pages for Libssl and Libcrypto.

It’s very simple command to install libssl-dev package in your machine,

1
2
3
4
$  sudo apt-get update
$  sudo apt-get install libssl-dev

This Package Informations are,

1
2
3
4
5
6
7
8
9
libssl-dev     package information
distro        Ubuntu 14.04 (Trusty Tahr)
section        Main
name        libssl-dev
version        OpenSSL 1.0.1f 6 Jan 2014
description    Secure Sockets Layer toolkit - development files
subsection    libdevel

maintainer    Ubuntu Developers

Reference : thelinuxfaq

libssl-dev from Ubuntu

Posted on

this page shows you To remove  libssl-dev package itself from Ubuntu 14.04 (Trusty Tahr) execute on terminal:

1
sudo apt-get remove libssl-dev

If you would like to remove including and any other dependent package which is no longer needed from ubuntu,

1
sudo apt-get remove --auto-remove libssl-dev

Purginglibssl-dev

If you want to delete configuration permanently from ubuntu, use with purge option

1
sudo apt-get purge libssl-dev

If you want to delete configuration permanently and it’s dependencies from Ubuntu

1

sudo apt-get purge --auto-remove libssl-dev

Reference : thelinuxfaq

Question and Answers for Linux

Posted on

1
echo "- - -" > /sys/class/scsi_host/hosth/  scan

or

1
echo "c t l" /sys/class/scsi_host/hosth/  scan

c   is the channel on the HBA,
t    is the SCSI target ID  ,
l    is the LUN and
h   is  the HBA number

2. What is difference between ping and ping6 Commands?

Both ping and ping6 commands are same. Regular ping command works with IPV4 and ping6 works with ipv6 IP address.

3.  SAN connectivity to a server comes through which port.

SAN storage connected through HBA/FC ports.
Read the rest of this entry »

Reference : thelinuxfaq

PHPMyAdmin on CentOS

Posted on

Use of Tool?

manage databases, tables, relations, users, permission, etc.
Display multiple information set through stored procedure or queries,
Directly create, update, and delete, tables or databases
Get a backup and restore the databases (Import and Export Databases)
create, edit, export and drop events and triggers
administer multiple servers
Database export to different format  like CSV, XML, PDF, ISO/IEC 26300, Microsoft Word, and LATEX.

How to Install:

Need to install Apache and MySQL servers,

# yum -y  install httpd

# yum -y install mysql mysql-server

Read the rest of this entry »

Reference : thelinuxfaq

Views Country of Site Visitor on AWStats

Posted on

installed AWStats on Linux system and when view AWStats report for a domain name unfortunately the Countries wise does not get report properly.
You need to configure GeoIP.dat

4b20-awstats-geoip-unknown
Download the latest GeoIP.dat file from the URL :

# wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz

# gunzip GeoIP.dat.gz

Read the rest of this entry »

Reference : thelinuxfaq