How to create and run Bash Script on Oracle Linux 9.2
To Create And Run Bash Script On Oracle Linux 9.2
Introduction:
• A bash script is a collection of commands written in a file.
• The bash program reads and executes these commands.
• It executes these commands line by line.
• Using the command line, you can navigate to a particular path, create a folder, and spawn a process inside that folder
Procedure Steps:
Step 1: Check the OS Version by using the below command
[root@linuxhelp ~]# cat /etc/os-release
NAME="Oracle Linux Server"
VERSION="9.2"
ID="ol"
ID_LIKE="fedora"
VARIANT="Server"
VARIANT_ID="server"
VERSION_ID="9.2"
PLATFORM_ID="platform:el9"
PRETTY_NAME="Oracle Linux Server 9.2"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:oracle:linux:9:2:server"
HOME_URL="https://linux.oracle.com/"
BUG_REPORT_URL="https://github.com/oracle/oracle-linux"
ORACLE_BUGZILLA_PRODUCT="Oracle Linux 9"
ORACLE_BUGZILLA_PRODUCT_VERSION=9.2
ORACLE_SUPPORT_PRODUCT="Oracle Linux"
ORACLE_SUPPORT_PRODUCT_VERSION=9.2
Step 2: Create a file named test.sh
[root@linuxhelp ~]# touch test.sh
Step 3: Grant Permission to test.sh file by using the below command
[root@linuxhelp ~]# chmod 755 test.sh
Step 4: Longlist the files by using the below command
[root@linuxhelp ~]# ls -la
total 40
dr-xr-x---. 14 root root 4096 Oct 16 05:10 .
dr-xr-xr-x. 18 root root 235 Oct 16 03:53 ..
-rw-------. 1 root root 1042 Oct 16 04:12 anaconda-ks.cfg
-rw-------. 1 root root 12 Oct 16 04:24 .bash_history
-rw-r--r--. 1 root root 18 Jan 8 2022 .bash_logout
-rw-r--r--. 1 root root 141 Jan 8 2022 .bash_profile
-rw-r--r--. 1 root root 429 Jan 8 2022 .bashrc
drwx------. 7 root root 103 Oct 16 04:15 .cache
drwx------. 7 root root 4096 Oct 16 04:15 .config
-rw-r--r--. 1 root root 100 Jan 8 2022 .cshrc
drwxr-xr-x. 2 root root 6 Oct 16 04:15 Desktop
drwxr-xr-x. 2 root root 6 Oct 16 04:15 Documents
drwxr-xr-x. 2 root root 6 Oct 16 04:15 Downloads
drwx------. 3 root root 19 Oct 16 04:15 .local
drwxr-xr-x. 2 root root 6 Oct 16 04:15 Music
drwxr-xr-x. 2 root root 6 Oct 16 04:15 Pictures
drwxr-xr-x. 2 root root 6 Oct 16 04:15 Public
drwx------. 2 root root 6 Oct 16 03:54 .ssh
-rw-r--r--. 1 root root 129 Jan 8 2022 .tcshrc
drwxr-xr-x. 2 root root 6 Oct 16 04:15 Templates
-rwxr-xr-x. 1 root root 0 Oct 16 05:10 test.sh
drwxr-xr-x. 2 root root 6 Oct 16 04:15 Videos
-rw-------. 1 root root 55 Oct 16 04:14 .Xauthority
Step 5: Edit the testscript.sh file by using the below command
[root@linuxhelp ~]# vim test.sh
# !/bin/bash
echo Bash Script is Started
ping -c 5 192.168.6.102
date
touch /root/file1
echo Bash Script is Completed
Step 6: Run the test.sh by using the below command
[root@linuxhelp ~]# sh test.sh
Bash Script is Started
PING 192.168.6.102 (192.168.6.102) 56(84) bytes of data.
64 bytes from 192.168.6.102: icmp_seq=1 ttl=128 time=0.598 ms
64 bytes from 192.168.6.102: icmp_seq=2 ttl=128 time=0.699 ms
64 bytes from 192.168.6.102: icmp_seq=3 ttl=128 time=0.464 ms
64 bytes from 192.168.6.102: icmp_seq=4 ttl=128 time=0.354 ms
64 bytes from 192.168.6.102: icmp_seq=5 ttl=128 time=0.510 ms
--- 192.168.6.102 ping statistics ---
5 packets transmitted, 5 received, 0% packet loss, time 4135ms
rtt min/avg/max/mdev = 0.354/0.525/0.699/0.117 ms
Monday 16 October 2023 05:26:02 AM IST
Bash Script is Completed
Step 7: To Run Bash Script with variables and Create another file and grant permission by using the below command
[root@linuxhelp ~]# touch variables.sh
[root@linuxhelp ~]# chmod 775 variables.sh
Step 8: Edit the variable.sh file by using the below command
[root@linuxhelp ~]# touch variables.sh
#! /bin/bash
echo Enter your Name
read Name
echo Enter your Maid ID
read Mail
echo "Details you provided"
echo Your Name is $Name
echo Your Mail ID is $Mail
Step 9: Run the variable.sh file by using the below command
[root@linuxhelp ~]# sh variables.sh
Enter your Name
Linuxhelp
Enter your Maid ID
linuxhelp@gmail.com
Details you provided
Your Name is Linuxhelp
Your Mail ID is linuxhelp@gmail.com
Conclusion:
We have reached the end of this article. In this guide, we have walked you through the steps required to create and run Bash Script on Oracle Linux 9.2. Your feedback is much welcome.
Comments ( 0 )
No comments available