Showing posts with label Server. Show all posts
Showing posts with label Server. Show all posts

How to get 'Nth' line of a text file in linux

How to get 'nth' line of a text file in linux
How to get 'nth' line of a text file in linux

 Below are the two better ways to print nth line of text files in linux.

1. Use the combination of head and tail command

one of the easiest way of printing nth line of a text file is by using the combination of head and tail command.Below is an exapmle of how to use it for displaying the 9th line of a file named sample.txt

Moving all the txt files from all the subfolders to another single folder in Linux

            


 Some times we need to move all the files with same extension to a single desired folder. It can be easy if there is only two or three folders...Just think there is hundreds of folders and its sub folders are there and need to move the files from all these folder.

Searching all the folder manually and move these files to the outside folder is a big task.In such case we can use the below command in order to move all the files to our desired external folder. 

Syntax

find <Parent_folder> -type f -iname "*.txt" -exec mv --backup=numbered -t <destination folder> {} +

LAMP Quickstart for Red Hat Enterprise Linux 4



Introduction
A very common way to build web applications with a database backend is called
a “LAMP Stack”, where “LAMP” stands for the Linux® operating system, the Apache web server, the MySQL database, and the PHP (or Perl or Python) web
application language. This Quickstart will take you through configuring and starting up the LAMP components, and then downloading, installing and testing a
complete LAMP application, an online DVD Store. The DVD Store application, including four PHP pages and the code needed to build and load the MySQL database, can be used as a model for your own LAMP web application.

This Quickstart assumes you have successfully installed Red Hat® Enterprise
Linux 4 on your server (RHEL4 ES edition was used for the test but the
instructions should be similar for the other RHEL4 editions) and are moderately
familiar with Linux commands (you will need to be able to edit files). Total time to
work through the Quickstart should be 30 – 60 minutes.

Getting Started
For ease of use, log into the system as root.

Verify that the required packages have been installed. To do this, click on Applications => Systems Settings => Add/Remove Packages. This will bring up
a window showing all of the packages available, and what has already been installed, sorted by groups. Scroll down to the Servers section and verify the Web Server and MySQL Database have been checked. Under details of MySQL Database, verify that both php-mysql and mysql-server have also been checked. If any of these items have not been previously checked, simply click the update button at the bottom of the window and provide the appropriate installation media as requested.

For purposes of this document, the hostname is “rhel4es” and the root password
is “password” (you should use something more creative, of course!). You will need to ensure that all of the appropriate host name information has been
set in your network environment (updating DNS, or /etc/hosts, etc.) You will
need to create a non-root user to own the PHP and MySQL code. We used user
“web” with password “web”.

To create the web user, open a terminal shell (right click anywhere on the
desktop, select “Open Terminal”). Type the following (ideally you can cut and
paste right from this Quickstart to your Linux command shell). In this document
commands that you type or that are printed by the computer are indicated in
monospace font.

useradd web
passwd web

At this point, it will prompt you for the new password. Use “web” as the password
(ignore the warnings for BAD PASSWORD – you can always change this later).

For the rest of this document you will enter some commands as root and some
as web. [Hint: use two Linux command shells, one for root, one for web. If you
are logged in as root you can use the command su – web to login as web in that
command shell].

Start and Test Apache
To run the Apache web server you first need to make a small modification to the
Apache configuration file, then start the Apache service (known as “httpd”), and
finally configure it so it will always start when the machine is booted:

cd /etc/httpd/conf
cp httpd.conf httpd.conf.orig
gedit httpd.conf

Find the line with #ServerName new.host.name:80 and add below it:
ServerName rhel4es

Save your changes; close the window. Next, you will start the web server, and
configure it so that it will automatically start on the next reboot. Type the
following into the shell window:

service httpd start
chkconfig httpd on

To test Apache, bring up a web browser with URL http://localhost. You should
see the Red Hat Enterprise Linux Test Page:
LAMP Quickstart for Red Hat Enterprise Linux 4
Start and Test Apache



Start and Test MySQL
Before starting MySQL, you’ll need to create a MySQL configuration file from one
of the standard ones offered. As root, copy the standard small configuration file
to /etc/my.cnf and add 4 lines to the end of it. Type the following into the terminal
window:

cd /etc
cp /usr/share/doc/mysql-server-4.1.7/my-small.cnf my.cnf
cat >> my.cnf <hit Enter, then paste in next 4 lines>
# For DVD Store full text search
ft_min_word_len = 3
ft_stopword_file =
log=/var/lib/mysql/mysql_query.log
<Enter Ctrl-C>

Next you need to start the MySQL service (called “mysqld”), and set it to always
start when the machine starts. Type the following into the terminal shell:

service mysqld start
chkconfig mysqld on

Now configure user access to the MySQL database. To change root’s password
(replace the final “password” with your root password), give privileges to the webuser, and remove the default anonymous user, type the following into the
terminal shell:

mysqladmin -u root password password
mysql –p

This will prompt you for the password you just entered above, and start the
MySQL monitor. You will need to ensure that you also add access based on
your specific host name as well (i.e. web@localhost.localdomain). Type the
following at the mysql> prompt:

grant all privileges on *.* to web@localhost identified by 'web';
grant all privileges on *.* to web@rhel4es identified by 'web';
delete from mysql.user where User='';
exit

Login as web and test out MySQL:

su – web
mysql –u web –-password=web

This will start the MySQL monitor as the user “web”. Type the following at the mysql> prompt to test it:

show databases;

You should get output that looks something like:

+----------+
| Database |
+----------+
| mysql    |
| test     |
+----------+
2 rows in set (0.00 sec)

Type “exit” to leave the MySQL monitor. Type “exit” again to log out as “web”.
This shows that MySQL has been installed with the initial two databases.

 Start and Test PHP

As root, edit the PHP configuration file to point to the correct host and allow
access to the web user, then restart Apache to read changes. In the terminal
window, type the following:

cd /etc
cp php.ini php.ini.orig
gedit php.ini

Change three lines to read as follows:

mysql.default_host = rhel4es   
mysql.default_user = web
mysql.default_pw = web

Save the document, close the window, then continue typing the following into the
terminal shell window to restart the web server and put the changes you just
made into effect:

service httpd restart

To test PHP, create a test PHP page. Type the following into the terminal
window:

cd /var/www/html
gedit default.php

Add the following to the file:
<html>
 <head>
   <title>PHP Test Page</title>
 </head>
 <body>
   <?php
     echo “<hr />”;
     echo “<p align=center>This is a test of PHP!</p>”;
     echo “<hr />”;
     echo “<p align=center>Copyright &copy; 2005 Dell</p>”;
   ?>
 </body>
</html>

To test, use your browser to access http://localhost/default.php. It should look like
LAMP Quickstart for Red Hat Enterprise Linux 4
Start and Test PHP

Install and Test the DVD Store LAMP Application

Now you are ready to install a full LAMP application, the Dell DVD Store
application. This application has been released by Dell to the open source
community under the GPL license and is available for all to use.
First, download in binary the DVD Store files ds2.tar.gz and ds2_mysql.tar.gz
from http://linux.dell.com/dvdstore to web’s home directory, /home/web. To
accomplish this, type the following from the terminal window:

su – web
wget http://linux.dell.com/dvdstore/ds2.tar.gz

Then expand these “tarballs” with:

tar –xvzf ds2.tar.gz
tar –xvzf ds2_mysql.tar.gz

This will create several directories under /home/web/ds2 with the DVD Store data
files and driver programs, as well as the MySQL build and load scripts. Now, as
root, you will need to create a directory to put the PHP pages:

cd /var/www/html
mkdir ds2
Now, the PHP files need to be copied to the new directory:

cd ds2
cp ~/ds2/mysqlds2/web/php4/* .

Now you are ready to create and test the MySQL DVD Store database. As web:

cd ~/ds2/mysqlds2
sh mysqlds2_create_all_nosp.sh
mysql –u web --password=web

mysql> use DS2;
mysql> show tables;
+---------------+
| Tables_in_DS2 |
+---------------+
| CATEGORIES    |
| CUSTOMERS     |
| CUST_HIST     |
| INVENTORY     |
| ORDERLINES    |
| ORDERS        |
| PRODUCTS      |
| REORDER       |
+---------------+
8 rows in set (0.00 sec)

mysql> select count(*) from CUSTOMERS;
+----------+
| count(*) |
+----------+
| 20000    |
+----------+
1 row in set (0.01 sec)

mysql> exit

This shows that the DVD Store has been installed correctly with 8 tables and
20,000 initial customers.

The DVD Store LAMP stack is ready for testing. With your browser, access
http://rhel4es/ds2. You should see the DVD Store Login page:
LAMP Quickstart for Red Hat Enterprise Linux 4


Login with Username “user2” and password “password”. You should see the
following Welcome screen:
LAMP Quickstart for Red Hat Enterprise Linux 4



Click on “Start Shopping”, search for some DVDs by Title, Actor or Category, add
DVDs to your shopping cart, and finally purchase them using your stored credit
card number.

You now have a working LAMP stack. By basing your application on the MySQL
and PHP code included here, you can jumpstart your own LAMP stack!

Remote Server Administration Tools for Windows 7 with Service Pack 1 (SP1)


Remote Server Administration Tools for Windows 7 with Service Pack 1 (SP1)

Remote Server Administration Tools for Windows® 7 with SP1 enables IT administrators to manage roles and features that are installed on computers that are running Windows Server® 2008 R2, Windows Server® 2008, or Windows Server® 2003, from a remote computer that is running Windows 7 or Windows 7 with SP1.


Setting up a LAMP Server Remotely


LAMP time!It’s been said a million times over — Linux is awesome on servers! With over 60 per cent of the Web’s servers gunning away on the mighty penguin, the robust, resilient, scalable and stable Linux plays a major role in keeping the Internet running like a well-oiled machine. In this article, I will describe how to set up a LAMP (Linux, Apache, MySQL and PHP) server from scratch, remotely. The only step requiring physical access is installing Ubuntu Server. The rest can be done the geeky way, via SSH! Read on if getting your hands dirty gives you a kick!

Setup SSH Key Authentication (Password-Less Authentication)


Setup ssh key authentication for password-less login between servers.  For use by ssh/sftp users or scripts.
Source Server (or local system)
Generate RSA key for user on this system, you can also use DSA.  This asks for key pass-phrase but you can leave it blank.
ssh-keygen -t rsa
This asks for location to place the generated key, by default it will be your home directory (ex: /home/your_username/.ssh/).  This generates two files:  id_rsaand id_rsa.pub.  Content of id_rsa.pub is what we need to copy to destination server.

Restrict network access by time or IP address with Squid


There are a number of reasons why you would want to restrict network access. You run a cafe with web access or you have young or teenage children and you want them to only be able to use the network at certain times. Their are certainly tools out there to do this on a PC-by-PC basis, but why not employ a proxy server instead? One of the best (and most robust) proxy servers available for the Linux operating system is theSquid Proxy server. But don’t let the name fool you, you do not have to install Squid on a server. You can just as easily install squid on a Linux desktop machine and control network access from your LAN.
Of course when you open up your /etc/squid/squid.conf file you might be a bit overwhelmed. So in this article I am going to show you two ways to limit access with Squid (instead of tossing the whole configuration file at you at once). I will also show you the quick and dirty method of installing Squid on a Fedora 13 machine. Once done with this article, you will at least be able to control network access by time or by IP address. In later articles we will discuss other ways to control network access with Squid.

See what images are being viewed on your network with driftnet


I want to preface this article by saying I am not, in any way advocating spying on your users. With that said, there are times (and reasons) why you might need to see what images are being viewed on your network. Whether it be an end user who is viewing content that goes against specific company policies or, worse, against the law. When this happens, you might have need or cause to see just what is being viewed from your LAN. When this is the case there is a handy tool for that called Driftnet.
Driftnet was inspired by the old Apple program EtherPEG and works by watching TCP streams for images and MPEG audio streams. As it listens I dumps the images into a user configured directory and/or it can display the images within a window as they are captured. In this article I will show you how to install and use Driftnet.
Installation

Connect remotely from Linux with Terminal Server Client


I do a lot of remote work throughout the day and to make those connections I use different tools. Between LogMeIn andTeamViewer I have remote support covered. But when I need to connect to a machine such as a Terminal Server, where do I turn? Generally speaking I turn to the Linux tool Terminal Server Client (tsclient.) This tool makes connecting to unattended remote servers a snap — and it workswith different protocols.
Features
Just what does tsclient offer? Take a look at this short list of features:

Set up a Linux media server


Do you have multiple machines around your house that would like to share a centralized server for multi-media? Having such a server for music allows for consolidation, ease of use, and space saving on client PCs. Of course to many users, the idea of setting up a multi-media server sounds like it would be a nightmare…especially on the Linux platform. That couldn’t be further from the truth.
The Firefly Media Server (formerly mt-daap) is a fast DAAP server that is simple to install and even easier to configure. Firefly resides on a single Linux machine that doesn’t have to be a powerhouse. In fact, you can install this lightweight server on Ubuntu Server and you’re almost ready to go. In this article you will see how to do just that – install and configure Firefly Media Server on Ubuntu Server.
Features
The Firefly server has all of the features you will want in a DAAP server:

Migrate users from one Linux machine to another


Have you ever had a need to migrate current running Linux users from installation to another? That would be a simple task if the user count was low. But  what happens when the user count is in the hundreds? What do you do then? If you’re not using LDAP, you know you will have to migrate the users’ data, passwords, etc from the old machine to the new. Believe it or not, this is just a matter of a few commands – not necessarily simple commands, but it’s not as complex as you would think.
In this article I am going to show you how to make this migration so your Linux users do not loose their data and their passwords are all retained.
What we migrating
The list is fairly simple:
  • /etc/passwd - Contains information about the user.
  • /etc/shadow - Contains the encrypted passwords.
  • /etc/group - Contains group information.
  • /etc/gshadow - Contains group encrypted passwords.
  • /var/spool/mail - Contains users email (the location will depend upon the mail server you use).
  • /home/ - Contains users data.
Unfortunately these files can not simply be copied from one machine to another – that would be too easy.  Just make sure you enter the following commands correctly.