How To Create And Run Bash script on Linux mint 20.2
To Create and Bash Script On Linux Mint
Introduction:
It is convention to give files that are Bash scripts an extension of .sh (myscript.sh for example). As you would be aware Linux is an extensionless system so a script doesn't necessarily have to have this characteristic in order to work.
Installation procedure :
Step 1 : To Check the os version
root@linuxhelp:~# lsb_release -a
No LSB modules are available.
Distributor ID: Linuxmint
Description: Linux Mint 20.2
Release: 20.2
Codename: uma
Step 2 : Creating the touch file by uding the following command
root@linuxhelp:~# touch testscript.sh
Step 3 : Changing the permission to the below file
root@linuxhelp:~# chmod 755 testscript.sh
Step 4 : Long list the file by using the following command
root@linuxhelp:~# ls -la
total 49784
drwx------ 5 root root 4096 Jan 6 06:32 .
drwxr-xr-x 19 root root 4096 Jan 4 09:07 ..
-rw------- 1 root root 4467 Jan 6 06:03 .bash_history
-rw-r--r-- 1 root root 3106 Dec 5 2019 .bashrc
drwx------ 3 root root 4096 Jul 3 2021 .cache
drwx------ 3 root root 4096 Jan 4 04:36 .dbus
-rw-r--r-- 1 root root 19666 Jan 6 04:35 index.html
drwxr-xr-x 3 root root 4096 Jan 5 04:28 .local
-rw-r--r-- 1 root root 161 Dec 5 2019 .profile
-rw-r--r-- 1 root root 50916586 Sep 30 02:59 rstudio-server-2021.09.0-351-amd64.deb
-rwxr-xr-x 1 root root 0 Jan 6 06:32 testscript.sh
-rw-r--r-- 1 root root 168 Jan 6 04:35 .wget-hsts
Step 5 : Editing the testscript.sh file
root@linuxhelp:~# nano testscript.sh
#!/bin/bash
echo bash script is started
ping -c 7 192.168.6.180
ls –la
echo bash script completed
Step 6 : Running the testscript.sh by using the following command
root@linuxhelp:~# ./testscript.sh
bash script is started
PING 192.168.7.200 (192.168.7.200) 56(84) bytes of data.
64 bytes from 192.168.7.200: icmp_seq=1 ttl=64 time=3.82 ms
64 bytes from 192.168.7.200: icmp_seq=2 ttl=64 time=0.499 ms
64 bytes from 192.168.7.200: icmp_seq=3 ttl=64 time=1.16 ms
64 bytes from 192.168.7.200: icmp_seq=4 ttl=64 time=1.09 ms
64 bytes from 192.168.7.200: icmp_seq=5 ttl=64 time=0.593 ms
64 bytes from 192.168.7.200: icmp_seq=6 ttl=64 time=1.45 ms
64 bytes from 192.168.7.200: icmp_seq=7 ttl=64 time=1.40 ms
--- 192.168.7.200 ping statistics ---
7 packets transmitted, 7 received, 0% packet loss, time 6018ms
rtt min/avg/max/mdev = 0.499/1.429/3.819/1.032 ms
total 49788
drwx------ 5 root root 4096 Jan 6 06:34 .
drwxr-xr-x 19 root root 4096 Jan 4 09:07 ..
-rw------- 1 root root 4467 Jan 6 06:03 .bash_history
-rw-r--r-- 1 root root 3106 Dec 5 2019 .bashrc
drwx------ 3 root root 4096 Jul 3 2021 .cache
drwx------ 3 root root 4096 Jan 4 04:36 .dbus
-rw-r--r-- 1 root root 19666 Jan 6 04:35 index.html
drwxr-xr-x 3 root root 4096 Jan 5 04:28 .local
-rw-r--r-- 1 root root 161 Dec 5 2019 .profile
-rw-r--r-- 1 root root 50916586 Sep 30 02:59 rstudio-server-2021.09.0-351-amd64.deb
-rwxr-xr-x 1 root root 107 Jan 6 06:34 testscript.sh
-rw-r--r-- 1 root root 168 Jan 6 04:35 .wget-hsts
bash script completed
With this process of creating and Running bash script On Linux mint 20.2 has comes to an end.
Comments ( 0 )
No comments available