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
Welcome to
LinuxQuestions.org , a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free.
Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please
contact us . If you need to reset your password,
click here .
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a
virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month.
Click here for more info.
12-26-2012, 02:06 AM
#1
Member
Registered: Apr 2012
Posts: 75
Rep:
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?
12-26-2012, 02:11 AM
#2
Member
Registered: Aug 2008
Location: INDIA
Distribution: Redhat,Debian,Suse,Windows
Posts: 179
Rep:
Quote:
Originally Posted by
figure20012
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.
12-26-2012, 02:16 AM
#3
Member
Registered: Apr 2012
Posts: 75
Original Poster
Rep:
Quote:
Originally Posted by
sharadchhetri
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
12-26-2012, 02:18 AM
#4
Member
Registered: Aug 2008
Location: INDIA
Distribution: Redhat,Debian,Suse,Windows
Posts: 179
Rep:
Quote:
Originally Posted by
figure20012
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.
12-26-2012, 02:21 AM
#5
Member
Registered: Apr 2012
Posts: 75
Original Poster
Rep:
Quote:
Originally Posted by
sharadchhetri
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
12-26-2012, 02:32 AM
#6
Member
Registered: Aug 2008
Location: INDIA
Distribution: Redhat,Debian,Suse,Windows
Posts: 179
Rep:
Quote:
Originally Posted by
figure20012
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.
12-26-2012, 02:35 AM
#7
Member
Registered: Apr 2012
Posts: 75
Original Poster
Rep:
Quote:
Originally Posted by
sharadchhetri
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
12-26-2012, 02:36 AM
#8
Member
Registered: Apr 2012
Posts: 75
Original Poster
Rep:
Quote:
Originally Posted by
figure20012
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
12-26-2012, 02:56 AM
#9
Member
Registered: Aug 2008
Location: INDIA
Distribution: Redhat,Debian,Suse,Windows
Posts: 179
Rep:
Quote:
Originally Posted by
figure20012
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.
12-26-2012, 03:34 AM
#10
Member
Registered: Apr 2012
Posts: 75
Original Poster
Rep:
Quote:
Originally Posted by
sharadchhetri
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
12-26-2012, 03:56 AM
#11
Member
Registered: Aug 2008
Location: INDIA
Distribution: Redhat,Debian,Suse,Windows
Posts: 179
Rep:
Quote:
Originally Posted by
figure20012
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.
12-26-2012, 04:00 AM
#12
Member
Registered: Aug 2008
Location: INDIA
Distribution: Redhat,Debian,Suse,Windows
Posts: 179
Rep:
Quote:
Originally Posted by
sharadchhetri
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.
All times are GMT -5. The time now is 08:22 PM .
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know .
Latest Threads
LQ News