LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 12-26-2012, 02:06 AM   #1
figure20012
Member
 
Registered: Apr 2012
Posts: 75

Rep: Reputation: Disabled
remove output Connection to $server closed.


I am running a script that ssh to a machine and ls a folder

var=`ssh -t $server $command`
echo $var

but the output i am getting contains the line

Connection to $server closed.

how can i remove this line?
Can anyone please help?
 
Old 12-26-2012, 02:11 AM   #2
sharadchhetri
Member
 
Registered: Aug 2008
Location: INDIA
Distribution: Redhat,Debian,Suse,Windows
Posts: 179

Rep: Reputation: 23
Quote:
Originally Posted by figure20012 View Post
I am running a script that ssh to a machine and ls a folder

var=`ssh -t $server $command`
echo $var

but the output i am getting contains the line

Connection to $server closed.

how can i remove this line?
Can anyone please help?
try this

var=`ssh -t "$server" "$command"`
echo $var
 
1 members found this post helpful.
Old 12-26-2012, 02:16 AM   #3
figure20012
Member
 
Registered: Apr 2012
Posts: 75

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by sharadchhetri View Post
try this

var=`ssh -t "$server" "$command"`
echo $var
Thanks for the quick reply

i still get the connection to server closed

i dont want the line beacause i am generating a report afterwards

Can i redirect the line ine some way not to get the Connection to swerver closed?

Please help
 
Old 12-26-2012, 02:18 AM   #4
sharadchhetri
Member
 
Registered: Aug 2008
Location: INDIA
Distribution: Redhat,Debian,Suse,Windows
Posts: 179

Rep: Reputation: 23
Quote:
Originally Posted by figure20012 View Post
Thanks for the quick reply

i still get the connection to server closed

i dont want the line beacause i am generating a report afterwards

Can i redirect the line ine some way not to get the Connection to swerver closed?

Please help
kindly paste the error here.
I am not able to get you clearly
 
1 members found this post helpful.
Old 12-26-2012, 02:21 AM   #5
figure20012
Member
 
Registered: Apr 2012
Posts: 75

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by sharadchhetri View Post
kindly paste the error here.
I am not able to get you clearly
Thanks for helping

Command
var=`ssh -t $server "ls /"`

output on screen

Connection to $server closed.

I want to remove this line Connection to $server closed
 
Old 12-26-2012, 02:32 AM   #6
sharadchhetri
Member
 
Registered: Aug 2008
Location: INDIA
Distribution: Redhat,Debian,Suse,Windows
Posts: 179

Rep: Reputation: 23
Quote:
Originally Posted by figure20012 View Post
Thanks for helping

Command
var=`ssh -t $server "ls /"`

output on screen

Connection to $server closed.

I want to remove this line Connection to $server closed
OK I checked in my laptop too.
use server=ip_address. I am getting same problem when I used $server as domain name.(abc.com)

I will show you my test script.

linux@tuxworld:~$ cat test.sh
#!/bin/bash
server="1.1.1.1"
cmd="ls -la"
var=`ssh root@$server "$cmd"`
echo $var

linux@tuxworld:~$

This script is working for me

Last edited by sharadchhetri; 12-26-2012 at 02:33 AM.
 
1 members found this post helpful.
Old 12-26-2012, 02:35 AM   #7
figure20012
Member
 
Registered: Apr 2012
Posts: 75

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by sharadchhetri View Post
OK I checked in my laptop too.
use server=ip_address. I am getting same problem when I used $server as domain name.(abc.com)

I will show you my test script.

linux@tuxworld:~$ cat test.sh
#!/bin/bash
server="1.1.1.1"
cmd="ls -la"
var=`ssh root@$server "$cmd"`
echo $var

linux@tuxworld:~$

thnks for helping Sharad

but i need to ssh using the dns name
I do not have control on the ip ands the ip keeps changing
Can you suggest a way where i can redirect the <<Connection to server closed>> to /dev/null

or to any other file
 
Old 12-26-2012, 02:36 AM   #8
figure20012
Member
 
Registered: Apr 2012
Posts: 75

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by figure20012 View Post
thnks for helping Sharad

but i need to ssh using the dns name
I do not have control on the ip ands the ip keeps changing
Can you suggest a way where i can redirect the <<Connection to server closed>> to /dev/null

or to any other file
I am using ssh -t

it creates another tty

I am using parameter -t as i do not have root access on the server
 
Old 12-26-2012, 02:56 AM   #9
sharadchhetri
Member
 
Registered: Aug 2008
Location: INDIA
Distribution: Redhat,Debian,Suse,Windows
Posts: 179

Rep: Reputation: 23
Quote:
Originally Posted by figure20012 View Post
I am using ssh -t

it creates another tty

I am using parameter -t as i do not have root access on the server
I tested mine script it is working fine for me.

linux@tuxworld:~$ cat test.sh
#!/bin/bash

server=`nslookup abc.com|grep -A 3 abc.com|grep Address|awk '{print $2}'`
cmd="ls"
ssh -t username@$server $cmd

linux@tuxworld:~$

first of all check this command, are you able to get ip address with below command .if successful then run test.sh script.

nslookup abc.com|grep -A 3 abc.com|grep Address|awk '{print $2}'
 
1 members found this post helpful.
Old 12-26-2012, 03:34 AM   #10
figure20012
Member
 
Registered: Apr 2012
Posts: 75

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by sharadchhetri View Post
I tested mine script it is working fine for me.

linux@tuxworld:~$ cat test.sh
#!/bin/bash

server=`nslookup abc.com|grep -A 3 abc.com|grep Address|awk '{print $2}'`
cmd="ls"
ssh -t username@$server $cmd

linux@tuxworld:~$

first of all check this command, are you able to get ip address with below command .if successful then run test.sh script.

nslookup abc.com|grep -A 3 abc.com|grep Address|awk '{print $2}'

thanks for helping Sharad
but i can only use the dns name
Can you please suggest another way without resolving the dns to its corresponding ip
 
Old 12-26-2012, 03:56 AM   #11
sharadchhetri
Member
 
Registered: Aug 2008
Location: INDIA
Distribution: Redhat,Debian,Suse,Windows
Posts: 179

Rep: Reputation: 23
Quote:
Originally Posted by figure20012 View Post
thanks for helping Sharad
but i can only use the dns name
Can you please suggest another way without resolving the dns to its corresponding ip
I tried to help you with all way ,apologize but system is in your control.

Give the answer of below two questions-

(1)Have you tried the script which I pasted and what was the output.Is it working or not.

(2)Does your server have multiple ip , just like if you do nslookup google.com .
 
1 members found this post helpful.
Old 12-26-2012, 04:00 AM   #12
sharadchhetri
Member
 
Registered: Aug 2008
Location: INDIA
Distribution: Redhat,Debian,Suse,Windows
Posts: 179

Rep: Reputation: 23
Quote:
Originally Posted by sharadchhetri View Post
I tried to help you with all way ,apologize but system is in your control.

Give the answer of below two questions-

(1)Have you tried the script which I pasted and what was the output.Is it working or not.

(2)Does your server have multiple ip , just like if you do nslookup google.com .
OK check this, it is working from my end

linux@tuxworld:~$ cat test.sh
#!/bin/bash

server='your_domain_name.com'
cmd="ls"
ssh -t username@$server $cmd

linux@tuxworld:~$
 
1 members found this post helpful.
  


Reply

Tags
linux, ssh



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
Server was hacked and now I can't remove the attacker's user (off-topic, closed.) dayid Linux - Security 4 05-17-2012 02:11 PM
VSFTP connection closed by remote server newuser455 Linux - Software 8 12-11-2010 09:12 PM
Shared connection to server closed. Why ? exceed1 Linux - Server 1 05-22-2010 09:28 AM
Can't SSH to some remove hosts: Connection Closed by Remote Host kvarkki Linux - Server 5 02-18-2010 06:44 AM
ssh connection closed by server m_yates Linux - Security 3 08-10-2005 03:12 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 11:55 AM.

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