Archive for the ‘Miscellaneous Admin Commands’ Category

Linux: lsof command and its uses

Monday, November 1st, 2010

How to view only TCP Established connections

lsof -iTCP | grep ESTABLISHED

How to view traffic on specific port ( port 22)

Syntax is : lsof -i : port number
lsof -i :22  | grep ESTABLISHED

How to view traffic from specific ip address

lsof -i@ip.of.your.user

how to view open files by a individual users

lsof -u username

How to collect information about a process

lsof -p process_id

Mysql Server processlist shows negative value(-) in connect column for system user

Wednesday, June 9th, 2010

Some times process list out put show negative value like bellow :
Command :

watch /usr/local/mysql/bin/mysqladmin -ppass processlist

8 | system user | | Connect | -1247 | Has read all relay log; waiting for the slave I/O thread to update it |

One of the reason :
make sure both Server has same time zone.
if there is any time difference between 2 server the replicate client show negative values

Linux:How to configure logrotate for ModSecurity(source install)

Monday, April 26th, 2010

Problem: When you install Mod-security from source , by default log-rotate will not rotate those logs file as the path for log files are not defined logrotate configuration file by default. So if you want to allow logo-ratate to rotate your modsecurity log files. here is the steps:

1. Create a file modsecurity under /etc/logrotate.d

 cd /etc/logrotate.d/
touch modsecurity

2. Copy and past bellow lines in their

#Bellow is my modsecurity log file (/opt/modsecurity/var/log/audit.log)
 
/opt/modsecurity/var/log/audit.log {
    missingok
    notifempty
    postrotate
 ##Restart the apache daemon
       /usr/local/apache/bin/apachectl graceful > /dev/null 2>/dev/null || true
    endscript
}

Now you can forcefully rotate log files by executing bellow commands:

 
logrotate -f /etc/logrotate.conf

Linux:How to create multiple OpenVPN instances

Monday, April 26th, 2010

Problem :
How to configure openvpn to create multiple instances and listen more then 2 ports(1194,1195) ??
Solution:
you need more then 2 openvpn configuration file. example : openvpn.conf and openvpn1.conf

Now you need to define different port , Server Ip address,ifconfig-pool-persist, and log files

For openvpn.conf :

port 1194
proto tcp
dev tun
server 10.8.0.0 255.255.255.0
ifconfig-pool-persist ipp.txt
log         openvpn.log
log-append  openvpn.log

For openvpn1.conf :

 
port 1195
proto tcp
dev tun
server 192.168.1.0 255.255.255.0
ifconfig-pool-persist /etc/openvpn/config2/ipp.txt
log         /etc/openvpn/config2/openvpn.log
log-append  /etc/openvpn/config2/openvpn.log

Now start openvpn daemon with these 2 config file separately

shell> openvpn –config /etc/openvpn/openvpn.conf &
shell> openvpn –config /etc/openvpn/openvpn1.conf &

Or add this into /etc/rc.local file so that when computer will reboot , it will start automatically.

so now if you take ifconfig output , it will show like this

tun0      Link encap:UNSPEC  HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00
          inet addr:10.8.0.1  P-t-P:10.8.0.2  Mask:255.255.255.255
          UP POINTOPOINT RUNNING NOARP MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:100
          RX bytes:0 (0.0 b)  TX bytes:0 (0.0 b)
 
tun1      Link encap:UNSPEC  HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00
          inet addr:192.168.1.1  P-t-P:192.168.1.2  Mask:255.255.255.255
          UP POINTOPOINT RUNNING NOARP MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:100
          RX bytes:0 (0.0 b)  TX bytes:0 (0.0 b)

how to configure logrotate for apache log files

Wednesday, March 24th, 2010

Problem : When you install apache from source , by default logrotate will not rotate those logs file as the path for log files are different.

Solution: You can edit httpd file under /etc/logrotate.d/ directory and insert bellow lines

/usr/local/apache/logs/*log {
    missingok
    notifempty
    sharedscripts
    postrotate
        /usr/local/apache/bin/apachectl graceful > /dev/null 2>/dev/null || true
    endscript
}

Now you can forcefully rotate log files by executing bellow commands:

logrotate -f /etc/logrotate.conf

Linux:How to use aide to check file system integrity

Monday, March 15th, 2010

Installing Aide:

Yum install aide

Creating the database:

aide -c /etc/aide.conf –i
Output : AIDE database at /var/lib/aide/aide.db.new.gz initialized.
This process creates a new file, aide.db.new.gz in /var/lib/aide/.You must rename this file to aide.db.gz, which is the correct name for the AIDE database.

Testing Aide:

aide -c /etc/aide.conf –C

Linux/windows-How to add a printer from cups by using .ppd file

Friday, February 12th, 2010

Recently I was trying to add a Canon LBP3460 Printer in my linux Server, I was trying to use .ppd which was available from canon website, but that file would not work.

so I download the file from : http://openprinting.org/printer_list.cgi , and its works perfectly .

here is the procedure::

Download the .ppd file from http://openprinting.org/printer_list.cgi

Upload the file into /usr/share/cups/model/ Directory.

Note : here I added the printer in windows 2003 server and made this printer Shareable by using port number 9100

example : port name : NPI414B70 and port number 9100

as described in the bellow picture

adding printer in windows 2003 server

adding printer in windows 2003 server

Now open your Cups interface by : https://localhost:631

Goto Administration->add new printer and follow as bellow pictues

Adding a new printer in cups (step1)

Adding a new printer in cups (step1)(Click to view Full image)

Selecting how this printer will be connected to linux

Selecting how this printer will be connected to linux

Definning the url for connecting to this printer

Definning the url for connecting to this printer(step3)(Click to view Full image)

cups5

Selecting model/driver for the printer(Step5) (Click to view Full image)

Selecting model(Step4)(Click to view Full image)

Selecting model(Step4)(Click to view Full image)

now you should be able to print from that printer.

Linux print job administration

Friday, January 22nd, 2010

How to find every Printer Status :

lpc status

How to view print job for a particular printer:

lpq -Pprinter-spool-name
[root@Host~]# lpq -PGI_LBP
GI_LBP is ready and printing 
Example:
Rank    Owner   Job     File(s)                         Total Size<br />
active  xxx 231020  s.t-avprnt.0H9                  4096 bytes<br />
1st     xxxx   231023  s.t-avprnt.0HD                  4096 bytes</p>

How to remove a particular print job from a printer :

lprm -PGI_LBP 231020

How to remove all print job from a printer:

lprm -PGI_LBP -


How to sent a print job to a different printer

lpr -P printer-spool-name document
example:
lpr -P GI_LBP wordbook.txt