SSH Shell Script and How to Use It
Bash is a versatile shell program for Linux users.
If you’re working on one server and need to connect to another server over SSH, then you’re reading the right article. This post details how you can successfully run SSH commands on remote machines and exit without issues.
Here you will find out:
- how to use bash script for SSH
- examples for bash script SSH
- when DiskInternals can help you
Are you ready? Let's read!
Bash Script SSH: all you need to know
Bash script SSH is a common tool for Linux users.
It is needed when you want to run a command from a local server or a Linux workstation. SSH is also used to access local Bash scripts from a local or remote server.
If you're looking for information on how to run multiple Linux commands in a Bash script, this article contains an extensive guide on how you can achieve this. Also, this post will be handy for people who wish to host Bash scripts on a machine and have them executed remotely on other hosts via SSH.
1. Example of executing Bash SSH command
To execute a Bash SSH command on a remote host over SSH, follow the example below:
In the command above, replace "HOST" with the host server detail and replace "COMMAND" with the actual command you want to run. Hence, you'll have something like this:
The command above will get the uptime of the specified remote server.
Similarly, to reboot a remote server, use the command below:
2. Example of multiple remote commands
Most of the time, you may want to run various commands on a remote server via SSH. In fact, there are quite different ways to achieve this request. However, we will share just four, which are the most common methods.
Example 1: how to run multiple commands over SSH
Example 2: an alternative way to run multiple commands on a remote host
Example 3: another alternative way
3. Remote server and bash script
If you’re looking to connect a remote Linux server via SSH and run some commands on the remote server, and then return the script to its (original) local server, here is how to do it.
Similarly, you can pipe Bash scripts to a remote server by creating the script on a local server:
What to do if you need to use Linux files from Windows?
There may be a time you'll need to access your Linux files, but you're booted into Windows; how do you access these important Linux files? Well, not to worry: using DiskInternals Linux Reader, you can easily access and view the files saved on any Ext4 partition on your computer. DiskInternals Linux Reader is actually a freeware program designed to have the best and most intuitive user interface.
DiskInternals Linux Reader is a very convenient software tool that also has a paid version: Linux Reader Pro. Linux Reader Pro will give you access not only to Ext2/3/4, ReiserFS, or Reiser4 but also to ZFS, XFS and Hikvision NAS in preview mode.