LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 02-07-2016, 05:26 PM   #1
ntbluez
LQ Newbie
 
Registered: Nov 2015
Posts: 21

Rep: Reputation: Disabled
SSH Script - Connection Not Visible


Wrote SSH script.
It seems to be running, connecting to servers in my server list file via SSH. Problem is, I cannot see the session or prompt to see password input...

Something about running ssh in script needs to be >/dev/null 2>%1 ???

Please help
Code:
#!/bin/bash
SERVERS=servers
for SERVERS in 'cat servers'
do
ssh MyUserName@$SERVERS df -h
done
 
Old 02-08-2016, 05:04 AM   #2
fmattheus
Member
 
Registered: Nov 2015
Posts: 104

Rep: Reputation: 38
Nope, you don't need to redirect anything.
It could be that you are using single quotes instead of backticks. Since you're using bash, you should use $(cat servers) instead.

If you're looking for other tips. The line beginning with SERVERS= can be removed as you reset the variable in the following line, and I would not use a pluralized variable for a single item. One last thing, printing out the name of the server you are connecting to can make things much clearer as well. Here's a quick rewrite.

Code:
#!/bin/bash
for SERVER in $(cat servers)
do
    echo $SERVER
    ssh MyUserName@$SERVER df -h
done
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
executing script even when we close connection via ssh sanaz Linux - Newbie 5 02-18-2013 12:44 PM
SSH connection from BASH script stops further BASH script commands tardis1 Linux - Newbie 3 12-06-2010 08:56 AM
How do I reuse one ssh connection in a shell script? jabalsad Linux - Software 8 03-08-2010 11:04 PM
Bash Script to log off of ssh connection Betzie Programming 4 07-07-2009 04:29 PM
ssh - how to close connection from bash script babag Linux - Networking 7 05-30-2008 09:14 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 11:53 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration