LIST
OF EXPERIMENTS
S.NO.
|
TITLE OF THE EXPERIMENT
|
PAGE NO.
|
1.
|
INSTALLATION
OF LINUX IN DIFFERENT MODES
|
3
|
2.
|
MYSQL INSTALLATION
|
27
|
3.
|
APACHE INSTALLATION
|
30
|
4.
|
PHP WITH DATABASE CONNECTIVITY
|
38
|
5.
|
PHYTON PROGRAMMING
|
46
|
6.
|
PERL PROGRAMMING
|
51
|
7.
|
NETWORK SIMULATOR (NS2)
INSTALLATION
|
565
|
Ex.NO
: 1 INSTALLATION OF LINUX IN VARIOUS MODES
AIM:
To write a procedure for PC Boot and Linux
init process.
PROCEDURE:
INTRODUCTION
TO OPEN SOURCE SOFTWARE:
Open-source software (OSS) is computer software that is available in source
code form for which the source code and certain other rights normally reserved for copyright holders are provided under a software license that permits users to study,
change, and improve the software. Open source licenses meet the requirements of
the Open Source Definition. Some open source software is available within the public domain. Open
source
software
is
very
often
developed
in
a
public,
collaborative manner. Open-source software is the most
prominent example
of open-source
development and often
compared
to
(technically defined) user- generated content or (legally
defined) open content
movements. The term open- source software originated
as part of a marketing campaign for free
software.
POPULAR DISTRIBUTIONS:
Well-known
Linux distributions include:
CentOS, a distribution derived from the same sources used by Red Hat,
maintained by a dedicated volunteer
community of developers with both
100% Red Hat-compatible versions and an upgraded version that is not
always 100% upstream compatible
Debian, a non-commercial distribution maintained by a volunteer
developer community with a strong commitment to
free software principles
Linux Mint, a distribution based on and compatible
with Ubuntu.
Mandriva, a Red Hat derivative popular in France
and
Brazil,
today
maintained by the French company of
the same name.
Oracle Enterprise Linux, which is a derivative of Red Hat Enterprise Linux, maintained and commercially supported
by Oracle.
PCLinuxOS, a derivative of Mandriva, grew from a
group of packages into a community-spawned desktop distribution.
Xubuntu, is the
Xfce version of the popular
desktop distro Ubuntu. Commonly used by Linux users that wish to have the function of a bigger
distro such as Ubuntu or
openSuse with the speed of
a smaller distribution.
INTRODUCTION
TO LINUX OPERATING SYSTEM
The name "Linux" comes from the Linux kernel, originally
written in 1991 by
Linus Torvalds.
STANDARD INSTALLATION OF
FEDORA
14
Fedora is an
RPM-based, general purpose collection of software including an operating system based on the Linux kernel, developed by the
community-
supported Fedora Project and sponsored by Red Hat. The Fedora Project's mission is
to lead the advancement of free and open source software and content as a
collaborative community.
One of Fedora's main objectives is not only to contain
software distributed under a free and
open
source
license, but also
to
be
on
the
leading
edge
of
such technologies. Fedora developers prefer to make
upstream changes instead of applying fixes specifically for Fedora—this ensures that their updates are available
to all Linux distributions. In 2008, Linus Torvalds, author of the Linux kernel, started
that he used Fedora because
it had fairly good support for the PowerPC processor architecture which he favored at
the time.
Basic Installation Steps:
1. Boot
from
the DVD.
2. Skip
the media test by pressing the tab and return keys on the
keyboard.
3. Click
the "Next" button on the
welcome screen.
4. Select
the appropriate language, then click the "Next" button.
5. Select
the appropriate keyboard
layout, then click the "Next"
button.
6. When
prompted, click the "Re-initialize drive" button.
7. When
prompted, click the "Re-initialize" button.
8. Enter
a fully qualified hostname,
then click the "Next" button.
9. Select
the appropriate timezone
by clicking on the nearest
city on the
map, then
click the "Next" button.
10. Enter the root password, then click the "Next" button.
11. Select
the "Use All Space" option, uncheck the "Encrypt
system"
option and check the "Review and
modify partitioning layout" option,
then click
the "Next" button.
12. The current partitioning layout is presented.
If the OS is to be used for
an Oracle installation, make sure the swap partition is at least 2G (2048M) in size. Once you
are
happy with the partition
structure, click
the "Next" button
followed by the "Format" and "Write changes
to
disk"button.
13.
Select the appropriate packages to install and check all three
Additional repositories.
.
15. Selecting the repositories will
require you to enter your network configuration. Select the appropriate network interface, highlight
the "System eth0" adapter and click the "Edit" button.
Click on the the "IPv4
Settings" tab, select the appropriate method and enter the required information.
When complete, click the
"Apply" and "Close"
buttons
16.
Once the repositories are selected, select the "Customize
Now" option
and click
the "Next" button.
17.
Select the appropriate package
groups and optional packages for your
installation
and click the "Next"
button.
18. Wait while the installation completes.
19.
When the installation is complete, restart
the machine as instructed.
When the machine has restarted,
click the "Forward" button
on the welcome screen.
20. Accept the license agreement by
clicking the "Forward"
button.
21. Enter login user details, then click the "Forward"
button.
22.
Set the appropriate
date-time information, then click
the "Forward"
button.
23.
Decide if you want to send a
hardware
profile to
the
Fedora project,
then click
the "Finish" button.
24. Click the username you defined previously.
25. Enter the password and click the "Log In" button.
26.
After you've logged in,
you are presented with
the default Fedora
desktop.
RESULT:
Thus the Linux Operating
System is installed successfully.
Ex.NO
: 2
INSTALLATION OF MYSQL
AIM:
To Write a procedure for installing MySQL on
Linux Operating System.
PROCEDURE
MYSQL INSTALLATION
……………………………………………………
4.0.12.tar.gz
if your using FreeBSD use "adduser" instead of "useradd". [root@server root]# groupadd mysql
--datadir=/data/mysql
DataDir is
where your mysql databases will be stored
including the database which
contains all mysql user
accounts,
you can easily backup all databases/users by saving the contents of this folder. /data/mysql
NOTE: If you
see
ERROR: No curses/termcap library
found" find where libncurses.so.5 is installed on your system and
add the following flag to your
configure statement : --with-named-curses-libs=/usr/lib/libncurses.so.5 (or
where ever
it may be)
if you get a "mod_auth_dbm" Error
Copy
the ndbm.h file from
/usr/include
to the /usr/include/db1 directory
(or
install db1-devel)
if
you get a "no acceptable C compiler found in $PATH" Error
Install a
c compiler, example: gcc
if
you get "libmysql.c:1349: warning: passing arg
5 of `gethostbyname_r' from incompatible pointer type"
Error
you need to install a c++ compiler,
install: libstdc++-devel, gcc-c++ (same version
as gcc)
[root@server root]#
ln -s /usr/local/mysql/share/mysql/mysql.server
/sbin/mysqld
Start,
Stop & Restart MySQL
Using MySQL
----------------------------------------
Export Database:
[root@server root]#
/usr/local/mysql/bin/mysqldump -u root -p
database_name > database_name.sql
Import Database:
[root@server root]#
/usr/local/mysql/bin/mysql -u root -p
database_name <
database_name.sql
Set root password:
[root@server root]#
/usr/local/mysql/bin/mysqladmin -u root -p
password
NEW_PASS
NOTE: When it prompts you to enter the password, just
hit Enter if you don't see an error,
the password was successfully changed.
Uninstalling MySQL
---------------------------------------- [root@server root]#
rm -rf /usr/local/mysql [root@server root]#
rm -rf /data/mysql
RESULT:
Thus the MySQL is installed
in Linux Operating System successfully.
EX.No:
3
APACHE INSTALLATION
AIM
:
To
write a procedure to install Apache Server in Linux Operating system.
APACHE INSTALLATION:
Introduction
The Apache Web server is arguably the most popular Web server in use on the Internet
today. Here are some of the reasons why Apache is so popular; you don't have to be running Windows to run Apache. It was developed on various
Unix/Linux/BSD
platforms,
and
then
recently
ported to Win32. Internet Information Server, a Web server
made
by
Microsoft for the Windows NT platform, is made for use in the "Windows-only" world. While IIS has many features, it’s lack
of portability limits it’s market
share.
Another reason for Apache's widespread acceptance is its overall
stability. While you can slow down an Apache
Web server, you can rarely,
if ever, kill one. The Apache
Web server service
is near bulletproof. Lastly, it's relatively
fast. I say "relatively" as it's relative to what you're doing with it. If you're hosting a pretty plain Web site with mostly static content, Apache is
a fireball.
If you throw tons of CGI scripts
at it, while making database
calls at the same time,
you're going to slow it down. Though
much of the slowdown
will come from your scripts themselves, and
not from Apache. Apache evolved out of the NCSA https project to its current status as one of
the fastest, most efficient,
and most functional web servers
in existence today.
Apache has been shown to be substantially faster, more stable, and more
feature-full than many other
web
servers.
Although
certain
commercial
servers have claimed to surpass Apache's speed (it has not been
demonstrated that any of these "benchmarks" are a good way
of
measuring WWW server speed at any rate). The developers of Apache
feel that it is better to have a mostly-fast free server than an extremely fast server that costs thousands of dollars. Apache
is run on sites that get millions
of hits per day, and they have experienced no performance difficulties. Apache is run on
over 10 million Internet servers (as of May 2002). It has been
tested thoroughly by both developers and users.
The Apache Group maintains rigorous standards
before releasing new versions of their server, and their server runs without problems on over one half of all WWW servers
available on the Internet.
When bugs do show up, they release patches
and new versions as soon as they are available.
Installation Options
I’ll cover three methods of installing
Apache under Linux. The three methods are:
·Binary installation
·Using an RPM (Red Hat
Package Manager) – recommended for people running Red Hat Linux
·Building from
source
Apache Installation Guide
We
recommend using the
RPM installation method. This is the
easiest way to install Apache for people that are
new to Linux.
Download the Software
You can download Apache from the Apache Software Foundation web site located at
want to
browse over
the documentation.
What you need
To install Apache, you will need the following things:
1. A computer running Linux
2. Root
access on this computer
3. For
binary and source installations, the
tar and gunzip Unix utilities
Binary Installation
A binary
is pre-configured, which
means someone else has gone to the trouble of
configuring
and building the software for
you.
There are, however, a few things you should keep
in mind:
1. Binaries are compiled for a particular
operating system. In other words, you
must use a binary
built
specifically for FreeBSD on your FreeBSD
machine and a Linux binary on your Linux machine.
You need to be sure to
grab the correct binary; if you don't see a binary for your particular operating system, you
must choose a different
method of installation.
2. Apache
binaries are usually a version or two behind the current source
distribution. This means
you don't reap the benefits of
the latest bug fixes and feature enhancements.
3. Because binaries
are pre-configured, you don't have much opportunity to alter the way the software
works.
If
you're a newcomer, you
may not care about this loss of
flexibility. Fortunately
most Apache binaries
include a full source distribution, providing you with the best of both worlds --
play now, learn later.
Now let's install
a binary. Point your browser
at
and download the binary for your operating system (in
our case, Linux).
You'll most likely be presented with a directory
containing multiple versions of Apache
in various compressed forms. For
the purposes of this guide, I'll
assume you've downloaded the
gzip'd form of the latest 2.0.x
Apache binary (currently that's httpd-2.0.35-i686-pc-linux-rh72.tar.gz). If there is
a README associated
with the file you're downloading, you may want to review it for
any interesting installation
tidbits or possible bugs.
If you can't find a binary for your operating system, choose either the RPM
Installation
(if you are running
Red Hat Linux) or Build
from
Source
method. Now let's
uncompress the archive using the handy
combination of gunzip and tar. You should
replace the "httpd-2.0.35-i686-pc-linux-
rh72.tar.gz" text
below with the name of the gzip'd file you downloaded.
gunzip < httpd-2.0.35-i686-pc-linux-rh72.tar.gz | tar xvf –
Some of you may be lucky enough to have a version of tar that is capable of taking care of both tasks.
tar xvzf
httpd-2.0.35-i686-pc-linux-rh72.tar.gz
Either way, you should
end up with an httpd-2.0.x directory, with x being the particular subversion of Apache you downloaded. Move into the newly
created directory.
cd httpd-2.0.x
As of Apache 1.3.11,
binary distributions
contain an install script called install.bindist.sh. If your binary
does not seem to contain such an install script,
take
a
look
at
the
README.bindist and/or
INSTALL.bindist documents for further information; if these documents
don't outline a simple installation method,
you'll probably want to use one of the other methods
I cover in this guide.
If you've not already done so, you'll need to become root. You can become
root by typing su, then the root password. Then go ahead and run the install
script.
./install.bindist.sh
This command should
install the various bits of the Apache distribution into the appropriate
locations; the default is usually to
install everything under
/usr/local/apache (confirm
this by consulting your README.bindist and/or
INSTALL.bindist
documents). That's all there is to it on installing binaries.
RPM
Installation
Those of you running Red Hat Linux may want to take advantage of Red Hat's RPM ("RedHat Package Manager") system. Almost identical to a
binary, an RPM is further customized
to play nicely
with other RPMs and provide a consistent interface to installing,
updating, and removing binaries.
For
Linux newcomers or when installing a small standard
component, RPMs
are simple and reliable. Bear in mind that an Apache RPM may already be
installed on your system depending on how Linux was originally installed
on your computer. To find
out, at the shell prompt, type:
rpm
-qa | grep apache
If you see something
like apache-1.3.9xxx, an Apache RPM has already
been installed. You can also type
that command typing
httpd instead of apache to see if it’s installed.
If you don't have an Apache
RPM, you must
obtain one. Red Hat 7.3 ships apache-1.3.23- 11.src.rpm in the RedHat/RPMS directory on the installation CD. Or,
point your browser at ftp://ftp.redhat.com/pub/redhat/redhat-7.3-en/os/i386/RedHat/RPMS and download it. If you've not already done so, you'll
need to become
root.
Navigate to the same directory as the .rpm file you obtained,
and then type
the following command,
substituting the name of the .rpm you're using for example: apache-1.3.23-11.src.rpm.
rpm
-ivh apache-1.3.23-11.src.rpm
RPM should
grind away, displaying its progress with
a primitive
#######
progress bar. Barring any errors, you're
done.
Build from Source
Building Apache from source may seem like a daunting task to newcomers,
but the Apache developers have done a wonderful job of making the task about as simple
as
could
be.
Just
three
more
commands
than
a
binary
installation and you skip the arduous task of figuring out which binary is the right
one
for your particular operating system.
Point your browser at http://www.apache.org/dist/httpd/ and download
the
gzip'd
form
of the current version of Apache (2.0.36 at the time of this writing). Now let's uncompress that
archive using
gunzip and tar. You should replace the
httpd-
2.0.36.tar.gz below with the name of the gzip'd file you downloaded.
gunzip < httpd-2.0.36.tar.gz | tar
xvf –
You should
end up with an httpd-2.0.x
directory, x being the particular sub- version
of Apache you downloaded. Move into
the newly created directory.
cd httpd-2.0.x
Now we'll
use
the the configure and
make commands to configure,
make, and install Apache. If
you've not already done so,
now would be the time to become root.
./configure
Your
screen should look something
like:
# ./configure
checking for
chosen layout... Apache checking for working mkdir -p...
yes
checking build
system type...
i686-pc-linux-gnu
checking host system
type... i686-pc-linux-gnu checking
target system type... i686-pc-linux-gnu Configuring Apache Portable Runtime library ......
config.status: executing default commands
Unless errors were
reported (not warnings), your Apache installation is now
configured and we can move on.
This is where
things get a bit ugly. Make'ing Apache produces screenfulls of output.
Make
Your
screen should look something
like:
# make
Making all in srclib
make[1]: Entering directory `/home/ryan/dl/apache_guide/httpd-
2.0.36/srclib' Making all in
apr
make[2]: Entering directory `/home/ryan/dl/apache_guide/httpd-
2.0.36/srclib/apr'...
make[1]: Leaving
directory `/home/ryan/dl/apache_guide/httpd-2.0.36'#
Finally, you're ready
to install your Apache build.
# make install
Now Apache is installed.
Starting Apache
Let's take your new Apache installation
out for a spin.
If you installed Apache using a binary or from scratch,
as root, type:
/usr/local/apache/bin/apachectl
start
If you used an
RPM, as root, type:
/sbin/service
httpd start
Point your browser at your brand new Web server, http://localhost/. If everything worked you should see the
default
home page.
Customize
Apache uses some
rather easy to understand text files
for configuration. On a Red Hat
system,you'll find
them in /etc/httpd/conf. Quite a few Linux
distributions place them in this same place, but if
you can't find such a
directory, do a search for
"httpd.conf". Once you find
these, you've
found
the main config files. If you're
new to Linux, and need help finding this file, here's how
you can find it.
1.Login
as root
2.Type:
cd /
3.Type:
find -name httpd.conf
Now you should
see
where the file is located.
When you move into the directory
containing
httpd.conf, you should see these three files:
·httpd.conf – This has
the settings for the overall
configuration for the server.
·access.conf – This file
contains all the security settings for
Apache.
·srm.conf – This file
contains the MIME
definitions and default document names for files
on the server
RESULT:
Thus the Apache Server is
installed in Linux Operating System successfully.
EX.NO:4 PHP WITH
DATABASE CONNECTIVITY
AIM:
To create a simple web page
using PHP and MySQL database connectivity.
PROCEDURE:
type the following in gedit and save it
as form.html
<html>
<head>
<title>LOGIN</title></head>
<body>
<form action="connect.php" method="post">
<p>
"Enter course no"<input type="text" name="cid"></p>
<p>"enter
the coursename"<input type="text" name="cname"></p>
<p>"click
here to submit"<input type="submit" name="submit"></p>
</form>
</body>
Type the following in gedit and save it
as connect.php
<?php
$cid=$_POST['cid'];
$cname=$_POST['cname'];
echo "connected to
database";
echo "selected
database";
$str="insert into courses values($cid,'$cname')";
if($res>0)
{
echo "Record created";
}
?>
TYPE THE FOLLOWING IN
THE
BROWSER
When press the submit
button
now
go to terminal
>
> Enter password:
Welcome to the MySQL
monitor. Commands end with
; or \g. Your MySQL connection id
is 28
Server version:
5.1.45 Source distributionmysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| student |
| test |
+--------------------+
4 rows in
set (0.11 sec)
mysql>
use
student ;
Reading table information
for completion of table
and column names
You can turn
off
this feature to get a
quicker startup with -A Database changed
mysql>
connect
Connection id: 29
Current
database: student
mysql>
show tables;
+-------------------+
| Tables_in_student |
+-------------------+
| course |
| courses |
| students |
+-------------------+
3 rows in
set (0.00 sec)
mysql>
select * from courses;
+------+-------+
| cid | cname |
+------+-------+
| 1 | java
|
| 1 | java
|
+------+-------+
2 rows in
set (0.02 sec)
2. Create Login Page
Create Login Page (HomePage.php)
<table width="300"
border="0" align="center"
cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<form name="form1" method="post" action="checklogin.php">
<td>
<table width="100%" border="0"
cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
<tr>
<td colspan="3"><strong>Member Login </strong></td>
</tr>
<tr>
<td width="78">Username</td>
<td width="6">:</td>
<td width="294"><input name="myusername" type="text"
id="myusername"></td>
</tr>
<tr>
<td>Password</td>
<td>:</td>
<td><input
name="mypassword" type="text" id="mypassword"></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td><input
type="submit" name="Submit"
value="Login"></td>
</tr>
</table>
</td>
</form>
</tr>
</table>
Create Validation Page (checklogin.php)
<?php
$host="localhost";
// Host name
$username="root"; // Mysql default username
//$password=""; // Mysql No password
$db_name="my_db"; // Database name
$tbl_name="members"; // Table name
// Connect
to server and select databse.
mysql_connect("$host",
"$username")or
die("cannot connect");
mysql_select_db("$db_name")or
die("cannot select DB");
// username
and password sent from
form
$myusername=$_POST['myusername'];
$mypassword=$_POST['mypassword'];
$sql="SELECT * FROM $tbl_name WHERE
username='$myusername'
and password='$mypassword'";
$result=mysql_query($sql);
// Mysql_num_row
is counting table row
$count=mysql_num_rows($result);
// If
result
matched $myusername and $mypassword, table
row must be 1 row
if($count==1)
echo "Welcome To
Our Web Page";
else
?>
echo "Wrong Username or Password";
RESULT:
Thus
the program executed successfully
EX.NO:5 PHYTON PROGRAMMING
AIM:
To write various programs in
PYTHON.
1. Write a Hello World Python
Program
.#!/usr/bin/python
print "Hello World!";
2.
String Concatenation in python programming
#String
concatenation worda='computer';
wordb='science';
print("worda
is ",worda); print("wordb is",wordb); wordc=worda+"
" +wordb; print("wordc is",wordc); wordd=worda*3; print("wordd is ",wordd); str
= 'HelloWorld!' length=len(str);
print ("str
:",str);
print("length:",length);
print ("first
character is",str[0]);
print ("print
character from 2rd to 6th
:", str[2:7] );
print
("Prints string starting
from
3rd
character:",str[2:]); print ("Prints string two times",str * 2);
print ("Prints concatenated
string :",str + "TEST" );
print(str[-1]);
#print
last character
print(str[-6]);#print character from last 6th
position print(str[:-2]);#
Everything except the last two
characters.
3. Write a python program
to perform function in Lists
#Python Lists
#!/usr/bin/python
print("\t \t \t Python Lists");
list
= [ 'abcd', 786 , 2.23, 'john', 70.2 ]
tinylist =
[123, 'john']
print("Prints complete
list:",list);
print("Prints first
element of the list : ",list[0]);
print("Prints elements starting from 2nd to
4th:",list[1:3]); print("Prints elements
starting from 3rd
element:",list[2:]); print("Prints list
two times:",tinylist *
2);
print("Prints concatenated
lists: ", list + tinylist );
#modify the
4th elements in
the list
print("Before modifying the 4th element in list :",list[4]);
list[4]='efgh';
print("4th element in list :",list[4]);
print(" complete list:",list);
#Appending
new elements
list.append('ijkl');
print("After appending list:",list);
#deleting an element in list
del list[2];
print("List :",list);
4. Write a python program
to perform functions in tuples
#Python Tuples
print("\t \t \t Python tuples");
tuple = ( 'abcd', 786
, 2.23, 'john', 70.2 ) tinytuple = (123,
'john') print("\ncomplete
tuple :",tuple);
print("Prints first element of the tuple:", tuple[0]);
print("Prints elements starting from 1nd to 3th:",
tuple[1:4]); print("Prints elements
starting from 3rd
element:", tuple[2:]); print("Prints tuple two times:", tinytuple * 2 );
print ("concatenated
tuple:",tuple + tinytuple );
5.
Write a python program to perform functions in Dictionary.
#Python Dictionary
tinydict =
{'name': 'john','code':6734, 'dept': 'sales'}
print ("Python Dictionary:" );
print ("complete dictionary",tinydict );
print ("Key :",tinydict.keys()); #
Prints all the keys print ("values:",tinydict.values());
# Prints all the values
6. Write a python Program
to select odd number from the
lists
#!/usr/bin/python
a=[11,12,13,14,15,16,17,18,19,20,21,31,44,45,10]; print("List is:",a);
n=len(a);
print("length:",n); i=0;
print("Odd number"); for i in range(len(a)):
if(a[i]%2==1):
print(a[i]);
7. Conditional statement in Python
>>>
x = int(raw_input("Please enter an integer: "))
>>>
if x < 0:
... x
= 0
... print 'Negative changed
to zero'
... elif x
== 0:
... print 'Zero'
... elif x
== 1:
... print 'Single'
... else:
... print 'More'
8.
For Statement in
Python
>>>
# Measure some
strings:
... a
= ['cat', 'window', 'defenestrate']
>>>
for x in a:
... print x,
len(x)
cat 3
window 6
9. The
Range() and Len() in
Python
>>>
a = ['Mary', 'had', 'a',
'little', 'lamb']
>>>
for i in range(len(a)):
... print i,
a[i]
...
10. Prime Number using Python.
>>>
for n in range(2, 10):
... for x
in range(2, n):
... if n
% x == 0:
... print n,
'equals', x, '*', n/x
... break
... else:
... #
loop fell through without finding a factor
... print n,
'is a prime number'
11. Simple Class
Program in python
>>>
class Complex:
... def init (self, realpart,
imagpart):
... self.r = realpart
... self.i
= imagpart
...
>>>
x = Complex(3.0, -4.5)
>>>
x.r, x.i
(3.0, -4.5)
12. Module
Program in Python (Fibonacci Series)
A module is a file containing
Python definitions and statements. The file
name is the module name with the suffix .py
appended. Within a
module, the module’s name (as a string) is available
as the value of the global variable name . For instance, use your favorite
text editor to create a file called fibo.py in the current directory with
the following
contents:
Step 1:
Fibo.py
def fib(n): #
write Fibonacci series up to n a, b = 0, 1
while b < n:
print
b,
a,
b = b, a+b
Step 2:
>>>
import fibo
Step 3:
>>>
fibo.fib(1000)
RESULT:
Thus
the program executed successfully
EX.NO:6 PERL PROGRAMMING
AIM:
Write a procedure to install
Perl and also write a simple program.
PERL PROGRAMS
1.
Sample PERL
#!usr/bin/perl # the above line is shebang directive
$name=<STDIN>; chomp($name); print
"$name\n";
2.
Scalar variables in PERL
#!/usr/bin/perl
my $animal="Camel"; # this variable is lexically scoped ie local my $ans=42_243; #this is similar
to 42243
print
"$animal\n";
print "$ans\n";
print "The square
of &ans",$ans*$ans,"\n";
3. Array
in
PERL
#!usr/bin/perl
my @animal=("cow","Buffalo","Camel"); print "@animal\n"; # list all
elements in array print "$#animal\n"; # list last element position print "$animal[0]\n"; #list 0th position
element
print
"$count"; # count no of elements in array
4.
Hash in PERL
#!usr/bin/perl
%color=('apple'=>"red",'banana'=>"yellow",'orange'=>"orange");
print "$color{'apple'}\n";
5.
To display all values in hash
#!usr/bin/perl
%color=('apple'=>"red",'banana'=>"yellow",'orange'=>"orange");
print "$color{'apple'}\n";
# to
display all the values in hash
{
print "$color{$key}\n";
}
6.If
loop in perl
#!usr/bin/perl
my $a=10;
$condition=1;
if($condition)
{
my
$y=100; print "$a\n"; print
"$y\n";
}
print "$a\n";
print "$y\n";
7. If not loop (unless)in perl
#!usr/bin/perl
$a=5;
unless($a>10) #is equal to if not
{print "a less than 10";}
8. While loop (until) in perl
#!usr/bin/perl
$a=0;
until($a>10) #is equal to while
{
print "$a\n";
$a++;
}
9. for each loop
(upper limit is not fixed )in perl
#!usr/bin/perl
my @animals=("cow","buffalo","camel",123,100,243,300);
foreach $key(@animals)
{
print "$key\n";
}
10. String operation:
#!usr/bin/perl
$a="hello";
$b="world";
print $a.$b,"\n";
$str="-";
print $str
x 80,"/n";
print "@a\n";
11. Magic variable in perl
#!usr/bin/perl
%color=('apple'=>"red",'banana'=>"yellow",'orange'=>"orange");
$h=\%color;
print "$h\n";#print the reference address
print "$h->{'apple'}\n"; # it print the the apple alone foreach (@keys)
{
print "$h->($_}\n"; # to display all
key values we use $_ instead of
keys
}
12 .Function
#!usr/bin/perl sub sayHello()
{print
"Hello\n";
}
&sayHello();
13.Function with parameter
#!usr/bin/perl sub add(){
my ($a,$b)=@_;
#the values will be stored in
@_ array
variable for dynamically
print
$a+$b;
}
&add(10,15);
14.program
to check greater among
3 number
#Greatest among 3 number print "Enter A value : ";
$a=<>;
print "Enter
b value : ";
$b=<>;
print "Enter
c value : ";
$c=<>;
if(($a >
$b)&&($a > $c))
{
print "A is greater";
}
elsif(($b
> $c)&&($b > $a))
{
print "B
is greater";
}
else{
print "C
is greater";
}
RESULT:
Thus Perl is installed and program is
executed successfully.
EX.NO:7 NETWORK SIMULATOR
AIM:
Write a procedure to install
Network Simulator.
PROCEDURE:
NETWORK SIMULATOR-2 is designed to run from on most UNIX based
operating systems.Ns is a discrete
event
simulator targeted at
networking research. Ns provides substantial
support for simulation of TCP,
routing, and multicast protocols over wired and wireless (local and satellite) networks.
tar -xzf
ns-allinone-2.34.tar.gz cd ns-allinone-2.34
./install
After a long wait and a whole lot of text, you
should see the installation finish up with text like the following:
Nam
has been installed successfully.
Ns-allinone package has been installed successfully. Here are the installation places:
tcl8.4.11: /home/pcraven/ns-allinone-2.29/{bin,include,lib} tk8.4.11: /home/pcraven/ns-allinone-2.29/{bin,include,lib} otcl: /home/pcraven/ns-allinone-2.29/otcl-1.11
tclcl: /home/pcraven/ns-allinone-2.29/tclcl-1.17
ns: /home/pcraven/ns-allinone-2.29/ns-2.29/ns nam: /home/pcraven/ns-allinone-2.29/nam-1.11/nam xgraph: /home/pcraven/ns-allinone-2.29/xgraph-12.1
gt-itm: /home/pcraven/ns-allinone-2.29/itm,
edriver, sgb2alt, sgb2ns, sgb2comns, sgb2hierns
---------------------------------------------------------------------------------- Please put /home/myusername/ns-allinone-
2.29/bin:/home/myusername/ns-allinone-
2.29/tcl8.4.11/unix:/home/myusername/ns-allinone-2.29/tk8.4.11/unix into
your PATH environment; so
that
you'll be able to run itm/tclsh/wish/xgraph.
IMPORTANT NOTICES:
(1) You MUST put /home/myusername/ns-allinone-2.29/otcl-1.11,
/home/myusername/ns-allinone-2.29/lib,
If it complains about X libraries, add
path
to your X libraries
into
LD_LIBRARY_PATH.
If
you are using csh, you can set it
like:
setenv
LD_LIBRARY_PATH <paths> If
you are using sh, you can set it like:
export LD_LIBRARY_PATH=<paths>
(2) You MUST put
/home/myusername/ns-allinone-2.29/tcl8.4.11/library
into
your TCL_LIBRARY environmental
variable. Otherwise ns/nam will complain during startup.
(3) [OPTIONAL] To
save disk space, you
can now delete directories tcl8.4.11
and
tk8.4.11. They are now installed under /home/myusername/ns- allinone-2.29/{bin,include,lib}
After these steps, you can now run the ns validation
suite
with
cd ns-2.29; ./validate
At this point, you should follow
the
advice
here
and
update
your environment variables. You should
also add ns-allinone-2.29/bin to you path. This has links to all the executables created by NS-2. Since
the Tcl scripts may call these executables (like nam or xgraph), it is a good idea to
have them in the path.
You can
test the installation by
doing the following:
cd ns-2.29./validate
Note that
this validation takes a really long time. If it starts out ok, you probably have a good installation.
RESULT:
Thus the Network
Simulator has been installed successfully.
now check
the database as
mysql>
select * from students;
+--------+---------------+
| rollno | sname |
+--------+---------------+
| 100 | thamarai |
| 200 | selvi |
| NULL | abcd |
| 71 | thamaraiselvi |
+--------+---------------+
4 rows in
set (0.00 sec)