October 2025
M T W T F S S
 12345
6789101112
13141516171819
20212223242526
2728293031  

Categories

October 2025
M T W T F S S
 12345
6789101112
13141516171819
20212223242526
2728293031  

Logoff remote desktop sessions via CMD

To List the session in remote server we use quser.exe

Display information about users logged on to the system.

QUSER [username sessionname sessionid] [/SERVER:servername]

username Identifies the username.
sessionname Identifies the session named sessionname.
sessionid Identifies the session with ID sessionid.
/SERVER:servername The server to be queried (default is current).

Example:

C:>quser /server:testserver

USERNAME SESSIONNAME ID STATE IDLE TIME LOGON TIME
A-BalaK ica-tcp#966 10 Active 7 12/25/2010 3:04 PM
GBala ica-tcp#969 1 Active 9 12/25/2010 3:30 PM
Admin ica-tcp#984 5 Active 1:06 12/25/2010 4:33 PM
Finance ica-tcp#987 2 Active 4 12/25/2010 6:20 PM

Logoff the Remote Sessions

To Log off the terminal session of the remote server, Before you log off the remote session, you should know the “Session ID” which you get it from “QUSER” commands as above stated.

1. Logoff
Logoff command kicks off (logging off) the specified remote session. Log off help shows,

C:>logoff /?
Terminates a session.

LOGOFF [sessionname sessionid] [/SERVER:servername] [/V]

sessionname The name of the session.
sessionid The ID of the session.
/SERVER:servername Specifies the Terminal server containing the user
session to log off (default is current).
/V Displays information about the actions performed.

E.g.,

C:>logoff 2 /server:testserver /v
Logging off session ID 2

How To Enable NTFS Support in CentOS 6.3

In this how to I will describe how to enable NTFS support in CentOS 6.3. By default CentOS 6.x doesnt comes with NTFS support to mount NTFS partition either on hard disk or usb drives. Fedora provies EPEL repository for Red Hat Enterprise Linux. EPEL (Extra Packages for Enterprise Linux) is a volunteer-based community effort from the Fedora project to create a repository of high-quality add-on packages that complement the Fedora-based Red Hat Enterprise Linux (RHEL) and its compatible spinoffs, such as CentOS and Scientific Linux. NTFS drivers ntfs-3g is available through EPEL repository.
1) Preparation

Enable EPEL repository using following command.
rpm -Uvh http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm
1

rpm -Uvh http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm

2) Install NTFS Drivers.

yum -y install ntfs-3g
1

yum -y install ntfs-3g

The above command will install ntfs-3g package which bring NTFS support to your CentOS 6.3 installation. Just plug in your ntfs usb drives or use mount command to enable ntfs hard drive partitions.

Shell script for apache dos protection

#!/bin/bash
cur=`date +%H%M%S`
becur=`date -d “1 minute ago” +%H%M%S`
badip=`tail -n 10000 /var/log/httpd/access_log | egrep -v “\.(gif|jpg|jpeg|png|css|js)” | awk -v a=”$becu
r” -v b=”$cur” -F [‘ ‘:] ‘{t=$5$6$7;if (t>=a && t<=b) print $1}' | sort | uniq -c | awk '{if ($1>=20) print $2}
‘`
if [ ! -z $badip ];then
for ip in $badip;
do
if test -z “`/sbin/iptables -nL | grep $ip`”;then
/sbin/iptables -I INPUT -s $ip -j DROP
fi
done
fi

Shell script to get the user list

#!/bin/bash
awk -F: ‘{ print $1 }’ /etc/passwd
awk -F: ‘{ print $1,$5 }’ /etc/passwd
awk -F: ‘{ print $1,$NF }’ /etc/passwd
awk ‘NF >0’
awk -F: -v ‘OFS=—‘ ‘{ print $1,$5 }’ /etc/passwd
exit 0

How to install Oracle DB Client

Installing Oracle database Client to access DB
Either you can use sqldeveloper as oracle client or you can execute it from the command line using # sqlplus
 We can access oracle server graphically by using a package called sqldeveloper.
sqldeveloper-2.1.1.64.45-1.noarch.rpm

# rpm -ivh sqldeveloper-2.1.1.64.45-1.noarch.rpm

if the front end not getting install the jdk package and try…
# or install jdk on root and put the package in user account and run the ./sqldeveloper.sh from user account. if it shows any permission problem give 777 permission for .sh file and install and tell the jdk installed path while asking. Also included path in /etc/profile and if needed add it in .bashrc file

From the console we can use a Client called sqlplus

$ sqlplus /nolog  —– It starts sqlplus without logging in to a database.

$ connect / as sysdba   —— Connecting as an administrative user,No password is required. This is equivalent to the desupported “connect internal” method.

$ sqlplus -s /nolog ———– Sets silent mode which suppresses the display of the SQL*Plus banner, prompts, and echoing of commands.

 $ SQLPLUS [ { username[/passward][@connect_identifier] | / } [ AS { SYSDBA | SYSOPER } ] | /NOLOG ]

/home/oracle/app/oracle/product/11.2.0/dbhome_1/network/admin/tnsnames.ora ( In this path we are defining the connect_identifier, Using connect

 

using identifier we can access the db and tables of another system. To do so define the hostname,port,connect_identifier etc in tnsnames.ora file(copy the contents and edit the files)
$ sqlplus system/oracle@pfdb (connect_identifier)
we can connect to remote machine using this OR We can give the remote machine details in
tnsnames.ora, else connect using ipaddress and port/ We can give any connect_identifier name.
$ sqlplus system/oracle@orcl —— Give the connection details in tnsnames.ora

Oracle DB startup Scripts

Starting oracle listener

$ lsnrctl start

Start the database

$ dbstart

Starting oracle Enterprise manager
$ emctl start dbconsole

Shutting down the database
$ dbshut

Stopping the listener
$ lsnrctl stop

Stopping oracle Enterprise manager
$ emctl stop dbconsole

Starts sqlplus without logging in to a database
# su ­ oracle
$ sqlplus /nolog

Logging into default oracle db
$ sqlplus system/oracle11@pfdb

The automatic startup and shutdown of the Oracle database can be achieved with the files dbstart and dbshut both provided by Oracle. These files rely on the existance of the file /etc/oratab to work

$ cat /etc/oratab
orcl:/u01/app/oracle/product/10.2.0/db_1:Y

The first field is the name of my database (orcl), the second one is my home directory
(/u01/app/oracle/product/10.2.0/db_1), and the third indicates to the dbstart utility whether the database should, or should not be brough up at the system boot time with “Y” or “N” parameters respectively. As root user, we’ll change last field of this line from “N” to “Y” to let dbstart utility start this database when it runs.

Oracle Schema Creation

A schema is a collection of database objects. A schema is owned by a database user and has the same name as that user. Schema objects are logical structures created by users to contain, or reference, their data. Schema objects include structures like tables, views, and indexes.

$ sqlplus /nolog

SQL> connect / as sysdba
Connected

Creating a New Schema
SQL> create user ctechz identified by ctehz11;
User created

Grant Permissions to user
SQL> grant create session, create table, create trigger, create sequence, create procedure, create view to ctechz;
Grant succeeded

Connecting to Schema

SQL> connect ctechz/ctechz11;

Connected

Granting table space to the schema
SQL> grant unlimited tablespace to ctechz;
Grant succeeded

Mysql DataBase in linux

We  can check how to install mysql db in a linux machine
All files of mysql including DB are stored in /var/lib/mysql/

 

All configuration files are in /etc/my.cnf

 

Install the package using yum
# yum install mysql mysql-server

 

And then start the mysql server
# service mysqld start

 

Here no root password set for the DB so any one can access the DB command
# mysql

 

For securing it set a root password for mysql
# mysqladmin -u root password ‘password’

 

this will set a root password for mysql. If you want to update the mysql root password the do the following
# mysqladmin -u root -p’oldpassword’ password ‘newpassword’

 

Then to enter into mysql database run
# mysql -u root -p
enter password:
or we can specify password after -p option but it will be visible to all
Now your  mysql data base is ready for operation with a default port of 3306.

 

Some basic mysql queries are
To list all databases on the mysql sql server
mysql> show databases;

 

Create a database on the sql server
mysql> create database [databasename];

 

To use a database
mysql> use dbname;

 

To create a table in the database
mysql> create table tablename(name varchar(20),dob int(20));

 

To see all the tables in the db
mysql> show tables;

 

To drop a particular table
mysql> drop table tablename;

 

To see the structure of a particular table
mysql> describe employee;
mysql> show columns from table-name;

 

Show all data in a table
mysql> SELECT * FROM [table name];

Granting  Database permission to a user, * will give all default permissions

mysql> grant usage on *.* to ‘ctechz’@’localhost’ identified by ‘ctechz123’;

 

Granting  particular permission to users,
mysql> grant select,insert,update,delete,create,drop on TestDb.* to ‘ctechz’@’localhost’ identified by  ‘ctechz123’;

 

Creating a user to access db
mysql> create user ctechz identified by ‘ctechz123’;

 

To change the password for a user
mysql> set password for ‘ctechz’@’localhost’=password(‘ctechz123’);
 mysql> flush privileges;

 

Granting permission from any host
mysql> GRANT ALL PRIVILEGES ON *.* TO ‘monty’@’%’ WITH GRANT OPTION;

% means for all host

We can get the mysql history file from
  # vim .mysql_history
from the above file we can get the commands that we run the mysql bd.

If you want to connect to a remote mysql server from your machine

#  mysql -uroot -p -h 192.168.1.245

Granting permission to access the database from a particular Ip

# grant all privileges on *.* to ‘root’@’192.168.1.67’ identified by ‘mysql1’;

# flush privileges;

Mysql source

Executing number of sql queries at a time using “source” command

Make all the queries in a single file, here i opened a file called “ctechz.sql” and saved all sql queries in this file.

# mysql -uroot -pmysql

mysql> use dbname;  —– be in that database
and then run the “source”  command to update the queries into the tables.

mysql> source ctechz.sql

it will execute all sql queries in the file ctechz.sql at the same time. When you are using the #mysql command to log into the db make sure that you are doing this from the direcory where you placed the ctechz.sql file.

You will see quite a bit of output as mysql reads queries from the ctechz.sql file and executes them.

How to take Mysql Dump

We can just check how to back up and restore mysql database and tables

 

if we want the backup of entire mysql db
# mysqldump -u root -p -A > /bkp/mysql_full.sql
-A —— take all(full)db from /var/lib/mysql
-p —— password
-u —— user

 

# vim mysql_full.sql shows the complete file db entries in it.
If we want the backup of a single db
# mysqldump -u root  -p dbname > /bkp/bkp_dbname.sql
After taking this when we restore the db to another system first create the db with same name there and then restore the backup file to the new db

 

Restoring mysql db
# mysql -u root -p dbname < /bkp/bkp_dbname.sql

 

To take full db bkp with date,
# mysqldump -uroot -p -A > /bkp/fulldb-$(date %d.%m.%y).sql

 

Restoring a particular db from full db backup to another system or same system, If we want to create the db in another system first copy the full backup in that system

mysql> create database dbname;   —– which we want to restore from other system (also from full db backup) and come out from the db, and put the restoration command

# mysql -u root -p dbname < full-02.Jun.10.sql
it will restore the db to the new system. Then login to the db and check the tables in the db
mysql> use dbname;
mysql> show tables;

 

Mysql dump full db with triggers and routines
# mysqldump -u root -p -A –triggers=TRUE –routines=TRUE –add-drop-table –databases | bzip2 > ALL_DB_`date %Y%m%d`.sql.bz2–add-drop-table may remove the existing table when you dump the file to another machine which has the same db.

above command dump all the databases. If we give “--all-databases –databases ” parameters we don’t want to make any db name while restoring the dump or else we have to create the same db before restoring the dump.

 

Dump single db with  triggers and routines. It will take stored procedures and functions as well
#  mysqldump -u root -p –triggers=TRUE –routines=TRUE –add-drop-table –databases dbname > dbname.sql

 If you do not name any tables following db_name or if you use the --databasesor --all-databases option, entire databases are dumped.

 

Taking a mysql table backup and restoring
# mysqldump -uroot -p dbname tablename > tablename.sql

 

For restoring a data base table
# mysql -uroot -p bdname < tablename.sql

 

Backup table with triggers and routines
# mysqldump -uroot -p -R –triggers dbname tablename > tablename.sql

 

To take only trigger and routines from the db
# mysqldump -R -t -n -d  –databases dbname > dbname.sql

 

To take db dump without any date
# myqldump -u root -p -R -t -n -d –skip-opt dbname > dbname.sql

 

To backup db,either cp files or db from /var/lib/mysql to another bd or other system and give mysql permission and if we run ‘show’ we can see all tables in the new db or in the system. Or use mysqldump

–add-drop-database  — Add a DROP DATABASE statement before each CREATE DATABASE statement
–add-drop-table     — Add a DROP TABLE statement before each CREATE TABLE statement
–add-locks          — Surround each table dump with LOCK TABLES and UNLOCK TABLES statements
–all-databases      — Dump all tables in all databases
–all-tablespaces    — Adds to a table dump all SQL statements needed to create any tablespaces used by an NDB Cluster table
–bind-address=ip_address —- Use the specified network interface to connect to the MySQL Server
–comments           — Add comments to the dump file
–databases          — Dump several databases
–debug-info         — Print debugging information, memory and CPU statistics when the program exits
–delete-master-logs — On a master replication server, delete the binary logs after performing the dump operation
–dump-date          —  Include dump date as “Dump completed on” comment if –comments is given
–flush-logs         — Flush the MySQL server log files before starting the dump
–flush-privileges   — Emit a FLUSH PRIVILEGES statement after dumping the mysql database
–host               — Host to connect to (IP address or hostname)
–lock-all-tables    — Lock all tables across all databases
–no-data            — Do not dump table contents
–routines           — Dump stored routines (procedures and functions) from the dumped databases
–skip-add-drop-table — Do not add a DROP TABLE statement before each CREATE TABLE statement
–skip-triggers      — Do not dump triggers
–triggers           — Dump triggers for each dumped table