Steps to create and execute a bash script
Step 1: Open a terminal window.
nano myscript.sh
Step 3: Type the bash commands that you want to include in the script.
Step 4: Save the file by pressing CTRL + X, then Y, and then Enter.
Step 5: Make the script executable by running the chmod command:
chmod +x myscript.sh
Step 6: Run the script by typing its name at the command prompt, followed by any arguments that the script expects:
./myscript.sh
Script:
Output:
You can see in the above image the script is being executed successfully and the output is printed in the terminal.
Shell Script to Perform Database Operations
In this article, we will be creating a shell script to perform various database operations. We will be using the MySQL database management system and the MySQL command-line client for our examples. However, the concepts and techniques discussed in this article can be applied to other database management systems as well.
Before we begin, make sure that you have the following prerequisites:
- A MySQL server set up and running
- The MySQL command-line client installed on your machine
- A MySQL user account with the necessary privileges to perform the operations you want to include in your script
Make sure that your MySQL server is running you can start your server by command:
$ service mysql start
You can see below the status is running and my server is active:
Contact Us