Showing posts with label execute multiple commands remotely using SSH. Show all posts
Showing posts with label execute multiple commands remotely using SSH. Show all posts

Friday, September 29, 2023

Linux SSH REMOTE EXECUTION OF COMMANDS

 ssh -t -q oracle@pm "(df -h /u02; hostname -f; date)" 


read -p "enter server name: " server ; ssh -t -q $server "(sudo -iu oracle)"


or looping multiple servers :-

for servers in server1 server2 server3 server4 ;

do 

ssh -t -q $servers "(df -h /u02; hostname -f ; date)" ;

done;


EXPLANATION:- 

  • ssh: This is the SSH command used for secure remote shell access.

  • -t: This option is used to allocate a pseudo-terminal. It's often necessary when you want to run interactive commands remotely because it simulates an interactive terminal session.

  • -q: This option stands for "quiet" and is used to suppress warning and diagnostic messages. It makes the SSH command less verbose.

  • oracle@pm: This part specifies the username (oracle) and the hostname or IP address (pm) of the remote server you want to connect to. The @ symbol separates the username from the hostname.

  • "(...)": The parentheses enclose a series of commands that you want to execute on the remote server. In this case, three commands are enclosed: df -h /u02, hostname -f, and date.

  • -t option is essential when running multiple commands, as it ensures that the commands are executed in an environment that behaves like an interactive shell session.

Enable OpenSSH on Windows 11

Step 1: Install OpenSSH Server You can do this via PowerShell (run as Administrator ): Check if it's already available: Get-WindowsCapab...