Ex.no.1:
Kernel configuration, compilation and installation
Description:
The Linux kernel in the distributions are
configured to work correctly in a wide variety of hardware and there is usually
no need to use any other kernel.In this exercise, a custom kernel has to be
compiled using the new kernel source and the system has to be booted using the
newly compiled kernel.
Pre-Requisite
·
Latest kernel source(2.6.39.1.tar.bz2)
Steps:
1.All
actions are performed as root.
>
su
#
2. To ensure that all
tools required for compiling the kernel are installed.
[root@localhost
student]#rpm –qa kernel-devel
If not installed
[root@localhost
student]#yum install kernel-devel
This
command will ensure that all packages required to compile the current running
kernel will
be installed.
3. Remove traces of old
kernel source if they exist.
#
rm -rf /usr/src/linux/
# rm -rf /usr/src/linux-2.6/
4.
The kernel source is usually kept under /usr/src. Copy the downloaded kernel
source to /usr/src.
#
cp linux-2.6.39.1.tar.bz2 /usr/src
#
cd /usr/src/
#
tar -xjvf linux-2.6.39.1.tar.bz2
# cd linux-2.6.39.1
5. Create two symlinks
to the kernel tree.
#
ln -s /usr/src/linux-2.6.39.1 /usr/src/linux
# ln -s /usr/src/linux-2.6.39.1
/usr/src/linux-2.6
6. Clean out all previous
configurations and reset the source directory to a pristine state.
The main reason for doing this is that some files do not
automatically get rebuilt, which can lead
to failed
builds, or at worst, a buggy kernel
#
make mrproper
7.
Configure the kernel.
#
make menuconfig
8. Save
and exit the prompt.
9. Build
the kernel.
# make clean
# make all
10. Once the compilation is completed we can install the kernel
and its modules.
# make modules_install
# make install
11. The newly created kernel will be in /boot.To check that the
install process has configured the boot loader to point to the new kernel.
# vi /boot/grub/menu.lst
12. The new kernel will have an entry at the top of the kernel
list. It can be identified by the kernel version number.
Change the lines containing default, timeout to the values shown
and comment out the
hiddenmenu entry.
default=0
timeout=5
#hiddenmenu
13. Now reboot the computer and the computer will boot into the
new kernel.
14. To check the version of the running kernel, use the uname
command.
# uname -r
2.6.39.1
Ex.no.2: Virtualization environment
Description:
Installing and running a guest OS within Qemu.
QEMU
QEMU is a generic and open
source machine emulator and virtualizer. When used as a machine emulator, QEMU
can run OSes and programs made for one machine (e.g. an ARM board) on a
different machine (e.g. your own PC). By using dynamic translation, it achieves
very good performance. When used as a virtualizer, QEMU achieves near native
performances by executing the guest code directly on the host CPU.
Fdbasecd.iso
Pre-requisites:
·
Fedora
installed with root access (root access for configuration purposes)
·
Internet Connectivity for downloading/installing
Packages
·
QEMU
·
fdbasecd.iso
Steps:
Steps for Virtualization
using QEMU and FreeDOS
1. Check whether qemu has
been installed using the command
#rpm -qa |grep qemu
2. Download the
fdbasecd.iso from www.freedos.org .
The following steps should
be followed from the directory where fdbasecd.iso is stored
3. Create a virtual disk
using the command. A 100MB disk image is sufficient for the FREE DOS installation.
#qemu-img create virtualdisk.img 100M
4. Boot from isoimg using
the command
#qemu -hda virtualdisk.img -cdrom fdbasecd.iso -boot
d
5. After booting through
QEMU, select 1 to boot from CDROM
6. In the installation cd
boot prompt, choose Install to hard disk using FreeDos.
7. Select the language
and keyboard layout as English (US).
8. Select option to Run
FreeDOS from CDROM
9. The created hard disk image is like a blank hard disk,
and does not
contain partitions. Atleast
one partition has to be created to install the OS.In the prompt type X:>fdisk
to partition the hard disk.
10. Enable Large disk
support (Y)
11. Create DOS
partition -> Primary DOS partition
12. Make the whole DOS
Primary partition as Active (Y)
13. Escape and come
back to prompt
14. In the terminal give
the same command
#qemu -hda virtualdisk.img -cdrom fdbasecd.iso -boot
d
15. Through qemu Choose
boot from CDROM
16. Select Language
- English US
17. Continue with Free Dos
installation.
18. Start installation
19. Choose Yes to reboot.
19. Close qemu.
20. The OS has been
installed.
20. To boot from the saved
state
#qemu -hda virtualdisk.img -boot c
21. Through qemu Choose
the option 3
22. Virtualisation
environment has been created.
Ex.no.3: Installing
various software packages
Description
SAMBA
Samba can be used
with Linux to provide transparent access between machines running Linux and
machines running Windows. Samba itself runs on a Linux machine and makes shared
files and printers available to Windows machines, as if they are available on a
Window machine or server.
Common
Unix Printing System (CUPS)
All printing systems on Linux make use of the
excellent PostScript system called GhostScript
(www.ghostscript.org).Ghostscript is a PostScript interpreter that is most
commonly used on Linux.Implements an excellent PostScript engine that can take
as inputs formats like JPEG,TIFF, PS & Text and output data in formats like
X Windows output, raster formats and PDF.Also handles conversion of PS output
for non-PS printers; can also be used a basic, spooler less printing system.
Most printing systems today use a combination of multiple tools (postscript interpreters,
filters, rasterises etc) to process and print documents.The printing system
converts PostScript into a raster format and then converts that into a printer
specific language to send commands to the printer
Steps
1.SAMBA
i.Installing
samba
1.Check whether samba has been installed
[student@localhost ~]$ rpm -qa |grep samba
system-config-samba-1.2.90-1.fc14.noarch
samba-3.5.5-68.fc14.1.i686
system-config-samba-docs-1.0.9-1.fc14.noarch
samba-common-3.5.5-68.fc14.1.i686
samba-winbind-clients-3.5.5-68.fc14.1.i686
samba-client-3.5.5-68.fc14.1.i686
If samba has not been installed,
Insatall samba
$ su
Enter Password:
(Here enter the
root password)
# yum install samba
2.Check the samba status.
[root@localhost student]# service smb status
smbd (pid 1914) is running...
[root@localhost student]# service nmb status
nmbd is stopped
[root@localhost student]# service nmb start
Starting NMB services: [ OK ]
[root@localhost student]# service nmb status
nmbd (pid 2945) is running...
3.Stop the ip and ip6tables.
[root@localhost student]# iptables -L
Chain INPUT (policy ACCEPT)
target prot opt source destination
ACCEPT udp -- anywhere anywhere udp dpt:domain
ACCEPT tcp -- anywhere anywhere tcp dpt:domain
ACCEPT udp -- anywhere anywhere udp dpt:bootps
ACCEPT tcp -- anywhere anywhere tcp dpt:bootps
ACCEPT all -- anywhere anywhere state RELATED,ESTABLISHED
REJECT icmp -- anywhere anywhere icmp echo-reply reject-with icmp-host-prohibited
REJECT icmp -- anywhere anywhere icmp echo-request reject-with icmp-host-prohibited
ACCEPT icmp -- anywhere anywhere
ACCEPT all -- anywhere anywhere
ACCEPT tcp -- anywhere anywhere state NEW tcp dpt:ftp
ACCEPT tcp -- anywhere anywhere state NEW tcp dpt:smtp
ACCEPT udp -- anywhere anywhere state NEW udp dpt:ipp
ACCEPT udp -- anywhere anywhere state NEW udp dpt:netbios-ns
ACCEPT udp -- anywhere anywhere state NEW udp dpt:netbios-dgm
ACCEPT tcp -- anywhere anywhere state NEW tcp dpt:netbios-ssn
ACCEPT tcp -- anywhere anywhere state NEW tcp dpt:microsoft-ds
ACCEPT udp -- anywhere anywhere state NEW udp dpt:netbios-ns
ACCEPT udp -- anywhere anywhere state NEW udp dpt:netbios-dgm
ACCEPT tcp -- anywhere anywhere state NEW tcp dpt:ssh
ACCEPT tcp -- anywhere anywhere state NEW tcp dpt:http
REJECT all -- anywhere anywhere reject-with icmp-host-prohibited
Chain FORWARD (policy ACCEPT)
target prot opt source destination
ACCEPT all -- anywhere 192.168.122.0/24 state RELATED,ESTABLISHED
^Z
[1]+ Stopped iptables -L
[root@localhost student]# service iptables stop
iptables: Flushing firewall rules: [ OK ]
iptables: Setting chains to policy ACCEPT: nat filter [ OK ]
iptables: Unloading modules: [ OK ]
[root@localhost student]# ip6tables -L
Chain INPUT (policy ACCEPT)
target prot opt source destination
ACCEPT all anywhere anywhere state RELATED,ESTABLISHED
REJECT ipv6-icmp anywhere anywhere ipv6-icmp echo-reply reject-with icmp6-adm-prohibited
REJECT ipv6-icmp anywhere anywhere ipv6-icmp echo-request reject-with icmp6-adm-prohibited
ACCEPT ipv6-icmp anywhere anywhere
ACCEPT all anywhere anywhere
ACCEPT tcp anywhere anywhere state NEW tcp dpt:ftp
ACCEPT tcp anywhere anywhere state NEW tcp dpt:smtp
ACCEPT udp anywhere anywhere state NEW udp dpt:ipp
ACCEPT udp anywhere anywhere state NEW udp dpt:netbios-ns
ACCEPT udp anywhere anywhere state NEW udp dpt:netbios-dgm
ACCEPT tcp anywhere anywhere state NEW tcp dpt:netbios-ssn
ACCEPT tcp anywhere anywhere state NEW tcp dpt:microsoft-ds
ACCEPT udp anywhere anywhere state NEW udp dpt:netbios-ns
ACCEPT udp anywhere anywhere state NEW udp dpt:netbios-dgm
ACCEPT tcp anywhere anywhere state NEW tcp dpt:ssh
ACCEPT tcp anywhere anywhere state NEW tcp dpt:http
REJECT all anywhere anywhere reject-with icmp6-adm-prohibited
Chain FORWARD (policy ACCEPT)
target prot opt source destination
REJECT all anywhere anywhere reject-with icmp6-adm-prohibited
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
[root@localhost student]# service ip6tables stop
ip6tables: Flushing firewall rules: [ OK ]
ip6tables: Setting chains to policy ACCEPT: filter [ OK ]
ip6tables: Unloading modules:
4.Set the enforce as permissive
[root@localhost student]# getenforce
Enforcing
[root@localhost student]# setenforce
usage: setenforce [ Enforcing | Permissive | 1 | 0 ]
[root@localhost student]# setenforce 0
[root@localhost student]# getenforce
Permissive
Configuring samba
5. Create a user
[root@localhost student]# useradd sample1
6. Set the password
[root@localhost student]# smbpasswd -a sample1
New SMB password:
Retype new SMB password:
7. Login into the samba as using the smbclient to add the files and folders to share with windows.
[root@localhost student]# smbclient \\\\localhost\\sample1 -Usample1
Enter sample1's password:
Domain=[CSE1] OS=[Unix] Server=[Samba 3.5.5-68.fc14]
8. In this to see the files shared, enter ‘ls’ command
smb: \> ls
. D 0 Tue Oct 11 14:57:59 2011
.. D 0 Tue Oct 11 14:57:59 2011
.mozilla DH 0 Tue Jun 14 11:25:29 2011
.bash_logout H 18 Tue Jun 22 20:45:21 2010
.bashrc H 124 Tue Jun 22 20:45:21 2010
.bash_profile H 176 Tue Jun 22 20:45:21 2010
.zshrc H 658 Mon Mar 22 19:42:57 2010
.gnome2 DH 0 Wed Sep 29 09:45:31 2010
48758 blocks of size 1048576. 42074 blocks available
9. To see the location of current
directory, enter the ‘pwd‘ command
smb: \> pwd
10. To create a folder in sharing folder enter
following command
smb: \> mkdir sam
11. To check created directory enter the following command
smb: \> ls
. D 0 Tue Oct 11 15:05:09 2011
.. D 0 Tue Oct 11 14:57:59 2011
.mozilla DH 0 Tue Jun 14 11:25:29 2011
.bash_logout H 18 Tue Jun 22 20:45:21 2010
sam D 0 Tue Oct 11 15:05:09 2011
.bashrc H 124 Tue Jun 22 20:45:21 2010
.bash_profile H 176 Tue Jun 22 20:45:21 2010
.zshrc H 658 Mon Mar 22 19:42:57 2010
.gnome2 DH 0 Wed Sep 29 09:45:31 2010
48758 blocks of size 1048576. 42074 blocks available
smb: \>
12. To come out from samba client enter the ‘exit’
smb: \> exit
To access the shared files from windows.
13. Open the samba location as following.
Start-> Run..
14. Enter the ip address of linux machine
as following
eg:
\\172.45.2.135
15. It displays log in window to log into
the samba sever. Here samba username and password should be given.
username: sample1
password:test123
16.Now the shared files can be seen.
2.CUPS
i.
Installing CUPS
Check whether CUPS has been installed
rpm
–qa |grep cups
To Install CUPS Enter the Following command as
root
user
$ su
# yum install cups
Install the printer administration tool
# yum install system-config-printer
ii. Configuring CUPS
Open the cups by typing following
URL
http :/ / localhost :631/
In this click on the Adding
Printers and Classes
Here click on the Add
Printer.
After clicking on the Add Printer It will ask
for permission. Here enter the
system
root username and password
Then
CUPS search for the printers available in the network.
If the printer is connected to the network it
shows in the Discovered Network Printers. Select
the
printer and click on Continue button.
In following window give the name of printer
and also description and location.
Here select the Maker of the Printer and click
on the add printer.
Here select the Model of the Printer and click
on the add printer.
Here set the default options for printer. To
set it click on the set default options. This
is to
manage paper size and also color and Quality
After setting the options the following screen
will appear. In this,with the maintenaince, in
that drop down printer can be deleted and
edited. Below that, the Jobs status can be seen.
To see whether the printer has been configured
correctly, Go to the menu name called System ->
Administration -> Printing .
Ex.no.4(a): Running PHP
Description:
PHP
PHP stands
for Hypertext Preprocessor PHP is a powerful tool for making
dynamic and interactive web pages.PHP is the widely used, free, and efficient
alternative to competitors such as Microsoft’s ASP.PHP is a server-side
scripting language. PHP scripts are executed on the server PHP supports many
databases (MySQL,Oracle,etc.) PHP is an open source software and it is free to
download and use .
MYSQL
MySQL is a
database server and it is ideal for both small and large applications.MySQL
compiles on a number of platforms and is free to download and use .
Apache
The Apache HTTP Server, commonly referred to as Apache, is a web server software
notable for playing a key role in the initial growth of the World Wide Web. Apache is generally recognized as the
world's most popular Web server (HTTP server) .Originally designed for Unix
servers, the Apache Web server has been ported to Windows and other network
operating systems (NOS).
Pre-Requisites:
PHP,MYSQl,Apache
Steps:
1. Check whether apache has been
installed.
rpm -qa |grep apache
2. Check whether MYSQL has been
installed.
rpm -qa |grep mysql
3. Check whether PHP has been installed.
rpm -qa |grep php
Login
as a toot user
4. Start the apache server
[root@localhost
student]# /sbin/service httpd start
Starting
httpd:
5. Start the MYSQL server
[root@localhost
student]# /sbin/service mysqld start
Starting
mysqld: [ OK ]
6. Open MYSQl using the command
[root@localhost
student]# mysql -u root
7. Create a database.
mysql>
create database abc;
8. Use the database using the command
mysql>
use abc;
Database
changed
9. Create a table to store the usernames
and passwords.
mysql>
create table def(username varchar(10),password varchar(10));;
10. Insert the values for username and
password.
mysql>
insert into def values(“abcde”,”ll”);
11.
Create a home page for login and save with .php extension.
<form
method="post" action="aks.php">
NAME:<input
name="uname" type="text">
PASSWORD:<input
name="pswd1" type="password">
<input
type="submit">
</form>
12. Create a page for sql connection.
<?php
$host="localhost";
$username="root";
$db_name="abc";
$tbl_name="def";
mysql_connect("$host",
"$username")or die("cannot connect");
mysql_select_db("$db_name")or
die("cannot select DB");
$uname=$_POST['uname'];
$pswd1=$_POST['pswd1'];
$sql="SELECT
* FROM $tbl_name WHERE
username='$uname'
and password='$pswd1'";
$result=mysql_query($sql);
$count=mysql_num_rows($result);
if($count==1)
echo
"Welcome To Our Web Page";
else
echo
"Wrong Username or Password";
?>
13. Run the php program.
14. Thus the php program for login forms
after setting up a LAMP stack has been created.
Ex.no.4(b): Running PHP
Description:
PHP
PHP stands
for Hypertext Preprocessor PHP is a powerful tool for making
dynamic and interactive web pages.PHP is the widely used, free, and efficient
alternative to competitors such as Microsoft’s ASP.PHP is a server-side
scripting language. PHP scripts are executed on the server PHP supports many
databases (MySQL,Oracle, etc.) PHP is an open source software and it is free to
download and use .
MYSQL
MySQL is a
database server and it is ideal for both small and large applications.MySQL
compiles on a number of platforms and is free to download and use .
Apache
The Apache HTTP Server, commonly referred
to as Apache, is a web server
software notable for playing a key role in the initial growth of the World
Wide Web. Apache is
generally recognized as the world's most popular Web server (HTTP server)
.Originally designed for Unix servers, the Apache Web server has been ported to
Windows and other network
operating systems (NOS).
Pre-Requisites:
PHP,MYSQl,Apache
Steps:
1. Check whether apache has been
installed.
rpm -qa |grep apache
2. Check whether MYSQL has been
installed.
rpm -qa |grep mysql
3. Check whether PHP has been installed.
rpm -qa |grep php
Login
as a toot user
4. Start the apache server
[root@localhost
student]# /sbin/service httpd start
Starting
httpd:
5. Start the MYSQL server
[root@localhost
student]# /sbin/service mysqld start
Starting
mysqld: [ OK ]
6. Open MYSQl using the command
[root@localhost
student]# mysql -u root
7. Create a database.
mysql>
create database store;
8. Use the database using the command
mysql>
use store;
Database
changed
9. Create a table to store the usernames
and passwords.
mysql>create table login(firstname varchar(10),lastname varchar(10),age integer(10));
Query
OK, 0 rows affected (0.08 sec)
11.
Create a home page for registration and save with .php extension.
<form action="insert.php" method="post">
Firstname: <input type="text" name="firstname"
/>
Lastname: <input type="text" name="lastname" />
Age: <input type="text" name="age" />
<input
type="submit" />
</form>
12. Create a page for sql connection.
<?php
$con = mysql_connect("localhost","root");
if (!$con)
{
die('Could not connect: ' .
mysql_error());
}
mysql_select_db("store", $con);
$sql="INSERT INTO login (FirstName, LastName, Age)
VALUES ('$_POST[firstname]','$_POST[lastname]','$_POST[age]')";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
echo "1 record added";
mysql_close($con)
?>
13. Run the php program.
mysql> select * from login;
+-----------+----------+------+
| firstname | lastname | age |
+-----------+----------+------+
| srf | srf |
23 |
+-----------+----------+------+
1 row in set (0.00 sec)
14. Thus the php program for login forms
after setting up a LAMP stack has been created.
Ex.no.5(a):
Running Python
Description:
Python is a high-level
programming language. It is an easy to learn, powerful programming language. It
has efficient, high-level data structures and a simple yet effective approach
to object oriented programming. Python’s elegant syntax and dynamic typing,
together with it's interpreted nature, makes it an ideal language for scripting
and rapid application development in many areas and on most platforms.
Pre-Requisite:
·
Python
Steps:
1.Check
whether python has been installed
[root@localhost
student]# rpm –qa |grep python
login as root user.
[student@localhost
~]$ su
Password:
2.Start
the MySQL server using the command
[root@localhost
student]# /sbin/service mysqld start
Starting
mysqld:
[ OK ]
[root@localhost
student]# mysql -u root
Welcome to the MySQL monitor. Commands end with ; or \g.
3.Create
a database using the command
mysql>
create database aaa;
Query
OK, 1 row affected (0.02 sec)
4.Use
the database using the command
mysql>
use aaa;
Database
changed
5.Create
a table using the command
mysql>
create table display(flowers varchar(20));
Query
OK, 0 rows affected (0.10 sec)
6.Insert
the values into the table using the command
mysql>
insert into display values("jasmine");
Query
OK, 1 row affected (0.00 sec)
mysql> insert into
display values("rose");
Query
OK, 1 row affected (0.00 sec)
mysql> insert into
display values("sunflower");
Query
OK, 1 row affected (0.00 sec)
mysql> insert into
display values("hibiscus");
Query
OK, 1 row affected (0.00 sec)
7.Display
the table using the command
mysql>
select * from display;
+-----------+
|
flowers |
+-----------+
|
jasmine |
|
rose |
|
sunflower |
|
hibiscus |
+-----------+
4
rows in set (0.00 sec)
8.Create
a python program by using the command
#!/usr/bin/python
#
import MySQL module
import
MySQLdb
#
connect
db
= MySQLdb.connect(host="localhost", user="root",
db="aaa")
#
create a cursor
cursor
= db.cursor()
#
execute SQL statement
cursor.execute("SELECT
* FROM display")
#
get the resultset as a tuple
results
= cursor.fetchall()
#
iterate through resultset
for
record in results:
print
record
9.Two
ways for running the Python Program.
Method 1:
[root@localhost student]# chmod +x
Filename.py
[root@localhost student]#
./Filename.py
[root@localhost
student]# vi python2.py
[root@localhost
student]# chmod +x python2.py
[root@localhost
student]# ./python2.py
('jasmine',)
('rose',)
('sunflower',)
('hibiscus',)
Method 2:
[root@localhost
student]# python Filename.py.
[root@localhost
student]# vi python2.py
[root@localhost
student]# python python2.py
('jasmine',)
('rose',)
('sunflower',)
('hibiscus',)
Ex.no.5(b):
Running Python
Description:
Python is
a high-level programming language. It is an easy to learn, powerful programming
language. It has efficient, high-level data structures and a simple yet
effective approach to objectorientedprogramming. Python’s elegant syntax and
dynamic typing, together with it's interpreted nature, makes it an ideal
language for scripting and rapid application development in many areas and on
most platforms.
Pre-Requisite:
- Python
Steps:
1.Check
whether python has been installed
[root@localhost student]#
rpm –qa |grep python
login as root user.
[student@localhost ~]$ su
Password:
2.Start the
MySQL server using the command
[root@localhost student]#
/sbin/service mysqld start
Starting
mysqld:
[ OK ]
[root@localhost
student]# mysql -u root
Welcome to the MySQL monitor. Commands end with ; or \g.
3.Create a
database using the command
mysql> create database aaa;
Query
OK, 1 row affected (0.02 sec)
4.Use the
database using the command
mysql> use abc;
Database changed
5.Create a
table using the command
mysql>create table
bbbb(Sname varchar(20),Rno integer(10),Percentage integer(10));
Query
OK, 0 rows affected (0.10 sec)
7.Create a
python program by using the command
#!/usr/bin/python
#import MySQL module
import MySQLdb
#connect
db=MySQLdb.connect(host="localhost",user="root",db="abc")
#create a cursor
cursor=db.cursor()
sql="""INSERT INTO bbbb (Sname,Rno,Percentage) values
('anu','26','80'),('asha','27','82'),('ammu','28','75')"""
cursor.execute(sql)
#execute SQL statement
cursor.execute("SELECT * FROM bbbb")
#get the result set as a tuple
results=cursor.fetchall()
#iterate through resultset
for record in results:
print record
8.Two ways
for running the Python Program.
Method 1:
[root@localhost student]#
chmod +x ex5.py
[root@localhost
student]# ./ex5.py
mysql>
select * from bbbb;
+-------+------+------------+
| Sname | Rno | Percentage |
+-------+------+------------+
| anu | 26 |
80 |
| asha | 27 |
82 |
| ammu | 28 |
75 |
Method 2:
[root@localhost student]#
python ex5.py.
mysql>
select * from bbbb;
+-------+------+------------+
| Sname | Rno | Percentage |
+-------+------+------------+
| anu | 26 |
80 |
| asha | 27 |
82 |
| ammu | 28 |
75 |
Ex.no.6(a): Text
processing with Perl
Description:
Perl is a high-level,
general-purpose, interpreted, dynamic programming language. Perl is used for a
wide range of tasks including system administration, web development, network
programming, games, bioinformatics, and GUI development. The language is intended to be practical (easy
to use, efficient, complete) rather than beautiful (tiny, elegant, minimal).
Its major features include support for multiple programming paradigms
(procedural, object-oriented, and functional styles), reference counting memory
management , built-in support for text processing, and a large collection of
third-party modules.
Steps:
1.Create a database
mysql> create database aaa;
Query OK, 1 row affected (0.02
sec)
2.Use the database
mysql> use aaa;
Database changed
3.Create a table
mysql> create table display(flowers
varchar(20));
Query OK, 0 rows affected (0.10
sec)
4.Insert the values into the table using
mysql> insert into display
values("jasmine");
Query OK, 1 row affected (0.00
sec)
mysql> insert into display values("rose");
Query OK, 1 row affected (0.00
sec)
mysql> insert into display values("sunflower");
Query OK, 1 row affected (0.00
sec)
mysql> insert into display values("hibiscus");
Query OK, 1 row affected (0.00
sec)
4 rows in set (0.00 sec)
5.Display the table using the command
mysql> select * from display;
+-----------+
| flowers |
+-----------+
| jasmine |
| rose |
| sunflower |
| hibiscus |
+-----------+
8.Create a perl program
#!/usr/bin/perl
use DBI;
$dbh=DBI->connect('dbi:mysql:aaa','root')
or die "connection error:$DBI::errstr\n";
$sql="select * from
display";
$sth=$dbh->prepare($sql);
$sth->execute or die
"SQL Error:$DBI::errstr\n";
while(@row=$sth->fetchrow_array)
{
print "@row\n";
}
Output:
jasmine
rose
sunflower
hibiscus
program2
#!/usr/bin/perl
use DBI;
$dbh=DBI->connect('dbi:mysql:a','root') or die "connection error:$DBI::errstr\n";
$query = "INSERT INTO b (name) VALUES ('abc')";
$query_handle = $dbh->prepare($query);
$query_handle->execute();
$sql="select * from b";
$sth=$dbh->prepare($sql);
$sth->execute();
$sth->bind_columns(\$name);
while(@row=$sth->fetchrow_array) {
print
"@row\n";
}
Output:
| name |
+------+
| abc |
+------+
Ex.no.6(b): Text
processing with Perl
Description:
Perl is a high-level,
general-purpose, interpreted, dynamic programming language. Perl is used for a
wide range of tasks including system administration, web development, network
programming, games, bioinformatics, and GUI development. The language is intended to be practical (easy
to use, efficient, complete) rather than beautiful (tiny, elegant, minimal).
Its major features include support for multiple programming paradigms
(procedural, object-oriented, and functional styles), reference counting memory
management , built-in support for text processing, and a large collection of
third-party modules.
Pre-Requisites:
- Perl
- MYSQL
Steps:
1. Check
whether perl has been installed.
rpm –qa |grep perl
login as root user.
[student@localhost ~]$ su
Password:
2.Start the
MySQL server
[root@localhost student]# /sbin/service mysqld start
Starting mysqld: [ OK ]
[root@localhost student]# mysql -u root
3.Create a
database
mysql> create database a;
Query OK, 1 row affected (0.02
sec)
4.Use the
database
mysql> use a;
Database changed
5.Create a
table to insert the values in the database.
mysql> create table b(name
varchar(10));
Query OK, 0 rows affected (0.06 sec)
6.Create a
perl program
[root@localhost student]# vi
perlpgm.pl
#!/usr/bin/perl
use DBI;
$dbh=DBI->connect('dbi:mysql:a','root') or die "connection
error:$DBI::errstr\n";
$query = "INSERT INTO b (name) VALUES ('abc')";
$query_handle = $dbh->prepare($query);
$query_handle->execute();
$sql="select * from b";
$sth=$dbh->prepare($sql);
$sth->execute();
$sth->bind_columns(\$name);
while(@row=$sth->fetchrow_array) {
print
"@row\n";
}
9.Two ways
for running the Perl Program.
Method 1:
[root@localhost student]#
chmod +x perlpgm.pl
[root@localhost
student]# ./perlpgm.pl
mysql> select * from b;
+------+
| name |
+------+
| abc |
+------+
1 row in set (0.00 sec)
Method 2:
[root@localhost student]#
perl perlpgm..pl.
mysql>
select * from b;
+------+
| name |
+------+
| abc |
+------+
1 row in set (0.00 sec)
Ex.no.7:
Write userspace drivers using fuse
Description:
A file system (filesystem) is
means to organize data expected to be retained after a program terminates by
providing procedures to store, retrieve and update data, as well as manage the available
space on the device(s) which contain it. A file system organizes data in an efficient
manner and is tuned to the specific characteristics of the device. There is
usually a tight coupling between the operating system and the file system. Some
filesystems provide mechanisms to control access to the data and metadata.
Insuring reliability is a major responsibility of a filesystem. File systems
are used on data storage devices such as magnetic storage disks or optical
discs to maintain the physical location of the computer files. A userspace
filesystem is a filesystem in which data and metadata are provided by an
ordinary userspace process.
Filesystem
in Userspace (FUSE)
is a loadable kernel module for Unix-like computer operating systems that lets
non-privileged users create their own file systems without editing kernel code.
FUSE is particularly useful for writing virtual file systems. Unlike
traditional file systems that essentially save data to and retrieve data from
disk, virtual filesystems do not actually store data themselves. They act as a
view or translation of an existing file system or storage device.
FUSE is made up of three main parts:
● A kernel filesystem modules
● A userspace library
● A mount/unmount program
Pre-requisites:
The fuse package and its
development files have to be installed in the system.
> yum install
fuse-devel
Steps:
1.
First create a new directory for this exercise.
> mkdir fuseprog
> cd fuseprog
>vi hello.c
Code
#define FUSE_USE_VERSION 26
#include
<fuse.h>
#include
<stdio.h>
#include
<string.h>
#include <stdlib.h>
#include
<errno.h>
#include
<fcntl.h>
static
const char *hello_str = "Hello World!\n";
static
const char *hello_path = "/hello";
static
int hello_getattr(const char *path,
struct stat *stbuf)
{
int
res = 0;
memset(stbuf, 0, sizeof(struct stat));
if(strcmp(path,
"/") == 0) {
stbuf->st_mode = S_IFDIR
| 0755;
stbuf->st_nlink = 2;
}
else
if(strcmp(path, hello_path) == 0) {
stbuf->st_mode = S_IFREG
| 0444;
stbuf->st_nlink = 1;
stbuf->st_size =
strlen(hello_str);
}
else
res = -ENOENT;
return
res;
}
static
int hello_readdir(const char *path,
void *buf, fuse_fill_dir_t
filler,
off_t offset, struct fuse_file_info *fi)
{
(void) offset;
(void) fi;
if(strcmp(path,
"/") != 0)
return
-ENOENT;
filler(buf, ".",
NULL, 0);
filler(buf, "..",
NULL, 0);
filler(buf, hello_path + 1,
NULL, 0);
return
0;
}
static
int hello_open(const char *path,
struct fuse_file_info *fi)
{
if(strcmp(path,
hello_path) != 0)
return
-ENOENT;
if((fi->flags
& 3) != O_RDONLY)
return
-EACCES;
return
0;
}
static
int hello_read(const char *path,
char *buf, size_t size, off_t
offset,
struct
fuse_file_info *fi)
{
(void) fi;
size_t len;
if(strcmp(path,
hello_path) != 0)
return
-ENOENT;
len = strlen(hello_str);
if
(offset < len) {
if
(offset + size > len)
size = len - offset;
memcpy(buf, hello_str +
offset, size);
}
else
size = 0;
return
size;
}
static
struct fuse_operations hello_oper = {
.getattr = hello_getattr,
.readdir = hello_readdir,
.open = hello_open,
.read = hello_read,
};
int
main(int argc, char *argv[])
{
return
fuse_main(argc, argv, &hello_oper, NULL);
}
2. To run the program, compile it with gcc:
> gcc -Wall
`pkg-config fuse --cflags --libs` hello.c -o hello
3. Run the program as root user with a single parameter - a mount
point:
> su
# mkdir tmp
# ./hello tmp/
4.After running the program there should be a single file in the
tmp/ directory named hello, its
content should be Hello World!:
# ls tmp/
hello
# cat tmp/hello
Hello World!
5. Unmount the file system.
# unmount tmp/
Ex.no.8:
Compiling software from source
Description:
Open source software is distributed in source
code form. In case of popular software Linux distributions will often have the
software packaged in their repositories. If the package is not in the repository the user has
to compile the software from source. To do this the user has to understand
about the build system used in the project.
The GNU build system, also known as the
Autotools, is a suite of programming tools designed to assist in making
source-code packages portable to many Unix-like systems. It can be difficult to
make a software program portable: the C compiler differs from system to system;
certain library functions are missing on some systems; header files may have
different names. The
GNU build system is designed to address this problem more manageably.
Tools
included in the GNU build system
The GNU build system comprises the GNU utility
programs Autoconf, Automake, and Libtool. Other related tools frequently used
with the GNU build system are GNU’s make program, GNU gettext, pkg-config, and
the GNU Compiler Collection, also called GCC.
GNU
Autoconf
Autoconf generates a configure script based on
the contents of a configure.ac file which characterizes a particular body of
source code. The configure script, when run, scans the build environment and
generates a subordinate config.statusscript which, in turn, converts other
input files and most commonly Makefile.in into output files (Makefile) which
are appropriate for that build environment. Finally the make program uses
Makefile to generate executable programs from source code.
GNU
Automake
Automake helps to create portable Makefiles,
which are in turn processed with the make utility. It takes its input as
Makefile.am, and turns it into Makefile.in, which is used by the configure script
to generate the file Makefile output.
GNU
Libtool
Libtool helps manage the creation of static
and dynamic libraries on various Unix-like operating systems. Libtool
accomplishes this by abstracting the library-creation process, hiding differences
between various systems (e.g. GNU/Linuxsystems vs. Solaris).
Gnulib
Gnulib simplifies the process of making
software that uses Autoconf and Automake portable to a wide range of systems
Make
In software development, make
is a utility that automatically builds
executable programs and libraries from source code by reading files called makefiles
which specify how to derive the target program.
CMake
CMake
is a unified, cross-platform, open-source
build system that enables developers to build, test and package software by
specifying build parameters in simple, portable text files.
CMake can:
● Create libraries
● Generate wrappers
● Compile source code
● Build executables in arbitrary combinations
Apache
Ant
Apache
Ant is a software tool for automating software
build processes. It is similar to Make but is implemented using the Java
language, requires the Java platform, and is best suited to building Java
projects. The most immediately noticeable difference between Ant and Make is
that Ant uses XML to describe the build process and its dependencies, whereas
Make uses Makefile format. By default the XML file is named build.xml. Ant is
an Apache project. It is open source software, and is released under the Apache
Software License.
Pre-Requisites:
·
Cmake
·
java-1.6.0-openjdk-devel
·
ant
Steps:
Create a directory for all the programs
in the exercise.
>
mkdir build_systems
>
cd build_systems
1. Make
Write a simple program in C and write a
makefile to compile the program.
> mkdir gnumake
> cd gnumake
>
vi squareroot.c
The Code:
// A simple program that computes the square root of a number
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main
(int argc, char *argv[])
{
if (argc
< 2)
{
fprintf(stdout,"Usage: %s number\n",argv[0]);
return 1;
}
double inputValue
= atof(argv[1]);
double outputValue
= sqrt(inputValue);
fprintf(stdout,"The square root of %g is %g\n",
inputValue, outputValue);
return 0;
}
Test it by compiling it once:
>
gcc squareroot.c -o squareroot -lm
>
./squareroot 49
> The square root of 49 is 7
write a simple makefile to compile the program.
>vi Makefile
The Code:
# Commands start with TAB not spaces
CC = gcc
CFLAGS = -g
LDFLAGS = -lm
all:
squareroot
squareroot:
squareroot.o
squareroot.o:
squareroot.c
clean:
rm
-f squareroot squareroot.o
Test the Makefile:
>
make
make: Nothing to be done for `all'.
>
make clean
rm -f squareroot squareroot.o
>
make
gcc -g -c -o squareroot.o squareroot.c
gcc -lm squareroot.o -o squareroot
>
./squareroot 49
The
square root of 49 is 7
2. CMake
Write a
simple script for CMake to compile the previously written program.
First install CMake
>yum
install cmake
Create a new directory and copy the
source code to it.
> cd ..
> mkdir cmake
> cd cmake
>
cp ../gnumake/squareroot.c .
Create
configuration files for CMake.
>vi
CMakeLists.txt
The Code:
cmake_minimum_required (VERSION 2.6)
project (squareroot)
add_executable(squareroot squareroot.c)
TARGET_LINK_LIBRARIES(squareroot
m)
CMake is
commonly use with out of source builds ie, the program is built in a directory
separate from the source. The generated
makefile is used to compile the program.
> mkdir build
> cd build
> ls
> cmake ..
-- The C
compiler identification is GNU
-- The CXX
compiler identification is GNU
-- Check
for working C compiler: /usr/bin/gcc
-- Check
for working C compiler: /usr/bin/gcc -- works
--
Detecting C compiler ABI info
--
Detecting C compiler ABI info - done
-- Check
for working CXX compiler: /usr/bin/c++
-- Check
for working CXX compiler: /usr/bin/c++ -- works
--
Detecting CXX compiler ABI info
--
Detecting CXX compiler ABI info - done
--
Configuring done
--
Generating done
-- Build
files have been written to:
/home/<user>/projects/buildsystems/cmake/build
> ls
CMakeCache.txt CMakeFiles
cmake_install.cmake Makefile
> make
Scanning
dependencies of target squareroot
[100%]
Building C object CMakeFiles/squareroot.dir/squareroot.c.o
Linking C
executable squareroot
[100%]
Built target squareroot
>ls
CMakeCache.txt
CMakeFiles cmake_install.cmake Makefile squareroot
> ./squareroot 49
The square root of 49 is 7
3. Apache Ant
Apache ant
uses java. So install java.
> yum install
java-1.6.0-openjdk-devel
>
yum install ant
Create a new directory for the ant exercise
> cd ../../
> mkdir ant
> cd ant
> mkdir -p src/hello
>
gedit src/hello/HelloWorld.java
The Code:
package hello;
public class HelloWorld
{
public static void main(String[] args) {
System.out.println("Hello
World");
}
}
Check
whether the code is working properly
> mkdir -p build/classes
>
javac -sourcepath src -d build/classes/ src/hello/HelloWorld.java
> java -cp build/classes
hello.HelloWorld
Hello World
write the
ant build script.
>vi build.xml
The Code:
<project>
<target name="clean">
<delete dir="build"/>
</target>
<target name="compile">
<mkdir dir="build/classes"/>
<javac srcdir="src"
destdir="build/classes"/>
</target>
<target name="jar">
<mkdir dir="build/jar"/>
<jar destfile="build/jar/HelloWorld.jar"
basedir="build/classes">
<manifest>
<attribute name="Main-Class"
value="hello.HelloWorld"/>
</manifest>
</jar>
</target>
<target name="run">
<java jar="build/jar/HelloWorld.jar"
fork="true"/>
</target>
</project>
Now the project can be compile and run
using ant.
> ant clean
Buildfile:
build.xml
clean:
[delete]
Deleting
directory
/home/<user>/projects/buildsystems/ant/build
BUILD
SUCCESSFUL
Total
time: 0 seconds
> ant compile jar run
Buildfile:
build.xml
compile:
[mkdir]
Created
dir:
/home/<user>/projects/buildsystems/ant/build/classes
[javac]
/home/<user>/projects/buildsystems/ant/build.xml:9:
warning:
'includeantruntime' was not set, defaulting to
build.sysclasspath=last;
set to false for repeatable builds
[javac]
Compiling 1 source file
to
/home/<user>/projects/buildsystems/ant/build/classes
jar:
[mkdir]
Created
dir:
/home/<user>/projects/buildsystems/ant/build/jar
[jar]
Building
jar:
/home/<user>/projects/buildsystems/ant/build/jar/HelloWorld.jar
run:
[java]
Hello World
BUILD
SUCCESSFUL
Total time: 1 second
4. GNU Autotools
Copy the
file hello-2.7.tar.gz to the buildsystems project directory and uncompress it.
>
cd ..
> ls
ant cmake
gnumake hello-2.7.tar.gz
> tar -xzf hello-2.7.tar.gz
> cd hello-2.7
> ./configure
> make
> src/hello
Hello,
world!
The
program will now reside in the src directory. To install the program log in as
root.
>
su
>
make install
>
exit
Now the
program can be run from anywhere.
>
hello
Hello, world!
>
hello --help
Usage: hello [OPTION]...
Print a friendly, customizable greeting.
-h, --help display this help and exit
-v, --version display version information and exit
-t, --traditional use traditional greeting format
-n, --next-generation use next-generation greeting format
-g, --greeting=TEXT use TEXT as the greeting message
Report bugs to: bug-hello@gnu.org
GNU Hello home page: <http://www.gnu.org/software/hello/>
General help using GNU software:
<http://www.gnu.org/gethelp/>
To uninstall the program:
>
su
>
make uninstall
>
exit
Ex.no.9:
Button creation using QT program
Procedure:
1. Open
the my computer and Create the folder in the home Location.
“fosslab\saran\Qt button”
2. Open
the terminal and change the floder by using cd command.
[fosslab@fosslab~]$cd
saran
[fosslab@fosslab~]$cd qt button
3.Open the vi
editor by using the following command.
Vi qtbutton.cpp
4. Then show
the content of the file qtbutton.cpp using following command.
Cat qtbutton.cpp
5.In that program we include the
“QUGUT” header file for GUI(Graphical User Interface) Oriented application.
6.Create the object for Qwid get
class,this class is manually used to create the
window.
7. Then set the window size by using
the predefined function.
Window . resize(320,240);
8. Next set the window title by using
the predefined function.
Window . set WindowTitle(“Window with a
button”);
9.Next create the button by using the
class QpushButton.
10.Set the x and y co-ordinate of the
window by using the function.
Button -> move(100,100)
11.Then create the project file by using
the command ,”qmake-qt4 –project”
12.Then create a make file that file.
13.Generate a object file from make file
by the following command,”make”.
14.Execute the program by using the
command.
“./qtbutton”
15.Then show the qt package by using the
command.
$rpm –qa qt
16.Then show the qt
package information by using the command.
$rpm –qi qt
Program:
#include<QTGUI>
int main(int arg c,char * arg v [])
{
QApplication app(argc,argv);
QWidgeb window;
Window . resize(320,240);
Window . set WindowTitle(“Window
with abutton”);
Window . show();
QPushButton * button = new
QPushButton(“Press me”,&window);
Button -> move(100,100);
Button -> show();
Return app.exec();
}
Output:
[fosslab @ fosslab~]$
cd/home/fosslab/saran/testing/qt
[fosslab @ fosslab~]$ cd qtbutton
[fosslab @ fosslab qt
button]$ vi qtbutton.cpp
[fosslab @ fosslab qt
button]$ cat qtbutton.cpp
[fosslab @ fosslab qt button]$
qmake –qt4 –project
[fosslab @ fosslab qt button]$
qmake –qt4
[fosslab @ fosslab qt button]$
make
[fosslab @ fosslab qt
button]$ ./qtbutton
|
Ex.no.10:
Package management system
Procedure:
1. Download
one copy the qmail package into own folder format of that package is zip(or)gz(or).abz.
2.
Extract the package(right click->extract)
3. Open
the terminal
4. Change
the directory by using cd command
5. Rename
the qmail-package by using mv
command
6. Change
the directory into qmail folder using cd
command
7. Use
the || command for show the number of files present in the qmail folder
8. Use
the following command to show the number of directories in rpm
9. Next
come back from the qmail directory using
cd
10. Use
following command for create repo directory repo data directory contains xml
meta data information about qmail packages
Create repo qmail
11. Then enter
into qmail directory
12. Change the
ordinary user($)into root user(#)by using su command.give the password as
“admin123”
13. Check the
status of above apache server using the following command
#service httpd status
14. To run the
apache server using
#service httpd start
15. Open the
browser and type
to display the apache server homepage
16. Change the
mode by using the following command
Chmod 777-R/var/www/html
17. Copy the qmail
folder to fosslab\var\www\html
18. In
terminal,change the directories as \var\www\html by using cd command
Because
\var\www\html is the apache server location
19. Then check
the qmail folder is copied into the apache server(or) not
20. Open the browser
& type the following for show necessary data & steps
21. Setup he
configuration for repository then create
the configuration file.this file is used to
qmail installation.
22. Change the
directory as etc/yum.reposd.this package is used to install(or)uninstall the
software.
23. Using the
|| command show the 4 repo data file
24. Then open
the editor using
“vi qmail.repo”
25. Type the
following on the editor
[qmail]
Name=@-mail
packages
Base
url=http://localhost/qmail
Enabled=1
Gpg
check=0
Then save the file using esc then:wq
26. Then show the content of editor by
using following command
Call qmail.repo
27. Using the following command to clear
the space of the buffer
Yum cleanall
28. Using the following command for
create the buffer space
29. Search the package by using
Yum
search qmail
30. Install the package by using,
Yum install qmail toaster.plus
Yum
install librs2.toaster.i689
Yum
is the install package name
That refer own file “vi
qmail.repo”
OUTPUT:
[fosslab@fosslab~]$cd
saran
[fosslab@fosslab
saran]$mkdir qmailpackages-qmail
[fosslab@fosslab
saran]$ u
[fosslab@fosslab
saran]$ cd qmail
[fosslab@fosslab
qmail]$ /s*.rpm.wc
25 25 1003
[fosslab@fosslab
qmail]$ cd…
[fosslab@fosslab
saran]$ create repo qmail
25/25 –qmail
using /Mrtg-taster-4.2-1.3.6
[fosslab@fosslab
saran]$cd qmail
[fosslab@fosslab
qmail]$ su
Pwd.admin 123
[fosslab@fosslab
qmail]#service httpd status
[fosslab@fosslab
qmail]#chmod 777-R/var/www/html
[root@fosslab
qmail]#cd/etc/yum repos.d
[root@fosslab
yum repos.d]#u
Total 12
[root@fosslab
yum repos.d]# vi qmail.repo
[root@fosslab
yum repos.d]# cat qmail.repo
[qmail]
Name=q.mail
packages
Baseurl=http://localhost
/qmail
Enabled=1
Gpq check=0
[root@fosslab
yum repos.d]# yum clear call
[root@fosslab
yum repos.d]#yum.make check
[root@fosslab
yum repos.d]#yum search qmail
[root@fosslab
yum repos.d]#yum install qmail toastor.plus
[root@fosslab
yum repos.d]#yum install libsrs2 toaster i689
No comments:
Post a Comment