LEARN HOW TO CREATE SCRIPT FILE (SHELL SCRIPT ) IN LINUX

In this post we will learn how to create script file and also how to run it in linux .Shell script is a program designed to run in linux . Imagine everyday you have to run many commands . But in script file just type whatever commands you want to run only for one time and save it . Then you just have to run script file and script file will run all the commands written in it . Let’s start how to create and run script file in linux .

shell script in linux

  • First lets create script file through vim  . Adding .sh means we want to create script file .
[root@localhost ~]# vim a.sh
  • And then in the file type commands you want to run .
  • I’m going to install webserver and also run it by running this script file .
yum install httpd* -y
service httpd restart
iptables -F
setenforce 0
service xinetd restart
~
~
~
~
  • Now give permission to this script file (a.sh) .
  • 700 means permission is only for root .
  • 777 means permission is for all .
[root@localhost ~]# chmod 700 a.sh
  • Now to run script file type ./ (dot and slash ) in front of script file .
  • As you can see webserver is installed and even started with single command .
[root@localhost ~]# ./a.sh
Loaded plugins: rhnplugin, security
Repository 'a' is missing name in configuration, using id
This system is not registered with RHN.
RHN support will be disabled.
a                                                                                      | 1.3 kB     00:00
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package httpd.i386 0:2.2.3-31.el5 set to be updated
--> Processing Dependency: libapr-1.so.0 for package: httpd
--> Processing Dependency: libaprutil-1.so.0 for package: httpd
---> Package httpd-devel.i386 0:2.2.3-31.el5 set to be updated
--> Processing Dependency: apr-util-devel for package: httpd-devel
--> Processing Dependency: apr-devel for package: httpd-devel
---> Package httpd-manual.i386 0:2.2.3-31.el5 set to be updated
--> Running transaction check
---> Package apr.i386 0:1.2.7-11.el5_3.1 set to be updated
---> Package apr-devel.i386 0:1.2.7-11.el5_3.1 set to be updated
--> Processing Dependency: gcc = 4.1.2 for package: apr-devel
---> Package apr-util.i386 0:1.2.7-7.el5_3.2 set to be updated
--> Processing Dependency: libpq.so.4 for package: apr-util
---> Package apr-util-devel.i386 0:1.2.7-7.el5_3.2 set to be updated
--> Processing Dependency: openldap-devel for package: apr-util-devel
--> Processing Dependency: db4-devel for package: apr-util-devel
--> Processing Dependency: expat-devel for package: apr-util-devel
--> Running transaction check
---> Package db4-devel.i386 0:4.3.29-10.el5 set to be updated
---> Package expat-devel.i386 0:1.95.8-8.2.1 set to be updated
---> Package gcc.i386 0:4.1.2-46.el5 set to be updated
--> Processing Dependency: libgomp >= 4.1.2-46.el5 for package: gcc
--> Processing Dependency: glibc-devel >= 2.2.90-12 for package: gcc
---> Package openldap-devel.i386 0:2.3.43-3.el5 set to be updated
--> Processing Dependency: cyrus-sasl-devel >= 2.1 for package: openldap-devel
---> Package postgresql-libs.i386 0:8.1.11-1.el5_1.1 set to be updated
--> Running transaction check
---> Package cyrus-sasl-devel.i386 0:2.1.22-5.el5 set to be updated
---> Package glibc-devel.i386 0:2.5-42 set to be updated
--> Processing Dependency: glibc-headers = 2.5-42 for package: glibc-devel
--> Processing Dependency: glibc-headers for package: glibc-devel
---> Package libgomp.i386 0:4.4.0-6.el5 set to be updated
--> Running transaction check
---> Package glibc-headers.i386 0:2.5-42 set to be updated
--> Processing Dependency: kernel-headers >= 2.2.1 for package: glibc-headers
--> Processing Dependency: kernel-headers for package: glibc-headers
--> Running transaction check
---> Package kernel-headers.i386 0:2.6.18-164.el5 set to be updated
--> Finished Dependency Resolution
Dependencies Resolved
==============================================================================================================
 Package                         Arch                Version                           Repository        Size
==============================================================================================================
Installing:
 httpd                           i386                2.2.3-31.el5                      a                1.2 M
 httpd-devel                     i386                2.2.3-31.el5                      a                146 k
 httpd-manual                    i386                2.2.3-31.el5                      a                811 k
Installing for dependencies:
 apr                             i386                1.2.7-11.el5_3.1                  a                123 k
 apr-devel                       i386                1.2.7-11.el5_3.1                  a                232 k
 apr-util                        i386                1.2.7-7.el5_3.2                   a                 76 k
 apr-util-devel                  i386                1.2.7-7.el5_3.2                   a                 53 k
 cyrus-sasl-devel                i386                2.1.22-5.el5                      a                1.4 M
 db4-devel                       i386                4.3.29-10.el5                     a                1.9 M
 expat-devel                     i386                1.95.8-8.2.1                      a                130 k
 gcc                             i386                4.1.2-46.el5                      a                5.2 M
 glibc-devel                     i386                2.5-42                            a                2.0 M
 glibc-headers                   i386                2.5-42                            a                601 k
 kernel-headers                  i386                2.6.18-164.el5                    a                993 k
 libgomp                         i386                4.4.0-6.el5                       a                 70 k
 openldap-devel                  i386                2.3.43-3.el5                      a                1.6 M
 postgresql-libs                 i386                8.1.11-1.el5_1.1                  a                196 k
Transaction Summary
==============================================================================================================
Install     17 Package(s)
Update       0 Package(s)
Remove       0 Package(s)
Total download size: 17 M
Is this ok [y/N]: y
Downloading Packages:
--------------------------------------------------------------------------------------------------------------
Total                                                                          96 MB/s |  17 MB     00:00
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing     : db4-devel                                                                             1/17
  Installing     : expat-devel                                                                           2/17
  Installing     : kernel-headers                                                                        3/17
  Installing     : apr                                                                                   4/17
  Installing     : libgomp                                                                               5/17
  Installing     : postgresql-libs                                                                       6/17
  Installing     : apr-util                                                                              7/17
  Installing     : httpd                                                                                 8/17
  Installing     : cyrus-sasl-devel                                                                      9/17
  Installing     : openldap-devel                                                                       10/17
  Installing     : glibc-headers                                                                        11/17
  Installing     : glibc-devel                                                                          12/17
  Installing     : httpd-manual                                                                         13/17
  Installing     : gcc                                                                                  14/17
  Installing     : apr-devel                                                                            15/17
  Installing     : apr-util-devel                                                                       16/17
  Installing     : httpd-devel                                                                          17/17
Installed:
  httpd.i386 0:2.2.3-31.el5       httpd-devel.i386 0:2.2.3-31.el5       httpd-manual.i386 0:2.2.3-31.el5
Dependency Installed:
  apr.i386 0:1.2.7-11.el5_3.1                          apr-devel.i386 0:1.2.7-11.el5_3.1
  apr-util.i386 0:1.2.7-7.el5_3.2                      apr-util-devel.i386 0:1.2.7-7.el5_3.2
  cyrus-sasl-devel.i386 0:2.1.22-5.el5                 db4-devel.i386 0:4.3.29-10.el5
  expat-devel.i386 0:1.95.8-8.2.1                      gcc.i386 0:4.1.2-46.el5
  glibc-devel.i386 0:2.5-42                            glibc-headers.i386 0:2.5-42
  kernel-headers.i386 0:2.6.18-164.el5                 libgomp.i386 0:4.4.0-6.el5
  openldap-devel.i386 0:2.3.43-3.el5                   postgresql-libs.i386 0:8.1.11-1.el5_1.1
Complete!
Stopping httpd:                                            [FAILED]
Starting httpd:                                            [  OK  ]
Stopping xinetd:                                           [  OK  ]
Starting xinetd:                                           [  OK  ]

 

 

LEARN HOW TO BLOCK ALL USERS TO LOGIN AND HOW TO LOCK USB IN LINUX

VIRUS IN LINUX . LEARN HOW TO INSTALL AND RUN AVG ANTIVIRUS IN LINUX

WHAT IS TELNET AND HOW TO CONFIGURE TELNET IN LINUX AS SERVER AND WINDOWS OR ANDROID AS CLIENT.

HOW TO INSTALL AND USE LYNIS SECURITY AUDITING TOOL IN LINUX OPERATING SYSTEM

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s