LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (http://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   remove output Connection to $server closed. (http://www.linuxquestions.org/questions/linux-newbie-8/remove-output-connection-to-%24server-closed-4175442961/)

figure20012 12-26-2012 03:06 AM

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?

sharadchhetri 12-26-2012 03:11 AM

Quote:

Originally Posted by figure20012 (Post 4856881)
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

figure20012 12-26-2012 03:16 AM

Quote:

Originally Posted by sharadchhetri (Post 4856883)
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

sharadchhetri 12-26-2012 03:18 AM

Quote:

Originally Posted by figure20012 (Post 4856885)
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

figure20012 12-26-2012 03:21 AM

Quote:

Originally Posted by sharadchhetri (Post 4856887)
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

sharadchhetri 12-26-2012 03:32 AM

Quote:

Originally Posted by figure20012 (Post 4856888)
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

figure20012 12-26-2012 03:35 AM

Quote:

Originally Posted by sharadchhetri (Post 4856892)
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

figure20012 12-26-2012 03:36 AM

Quote:

Originally Posted by figure20012 (Post 4856893)
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

sharadchhetri 12-26-2012 03:56 AM

Quote:

Originally Posted by figure20012 (Post 4856894)
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}'

figure20012 12-26-2012 04:34 AM

Quote:

Originally Posted by sharadchhetri (Post 4856899)
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

sharadchhetri 12-26-2012 04:56 AM

Quote:

Originally Posted by figure20012 (Post 4856917)
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 .

sharadchhetri 12-26-2012 05:00 AM

Quote:

Originally Posted by sharadchhetri (Post 4856925)
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:~$


All times are GMT -5. The time now is 07:41 AM.