To run multiple commands in Linux SSH, all we need a to write a Bash shell script. The shell script execute the commands based on the order in which commands have been written.
You can have loops, if else statements etc like any other programming. For this post I am restricting myself to getting started with a shell script and run few commands.
Here are steps to create a simple Bash shell script.
Create an empty file using vim.
0
1
2
|
vim test.sh
|
Enter Bash shell script identifier
0
1
2
|
#!/bin/bash
|
Enter list of commands you want to run per line
I want to run some simple commands. here it is.
0
1
2
3
4
|
echo “Hello World! Its first shell script”
ls –l
mkdir test
|
Escape from vim with saving shell script file
Press Esc Key on your PC and write down this. It will save the file and exit from vim editor.
0
1
2
|
:wq
|
Make this file executable
0
1
2
|
chmod +x test.sh
|
Finally execute your first shell Script
0
1
2
|
./test.sh
|
If all goes well then you will see and commands are executing in the order you have written in shell script. There are many tutorial sites on web from you can learn more about Bash shell scripting.