LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 05-24-2015, 06:13 PM   #1
Mike_Brown
Member
 
Registered: May 2015
Posts: 37

Rep: Reputation: Disabled
How to redirect the error message?


I have a hostlist and there are several hosts. I want to use ssh to connect to them. I want to see whether the host is available or not by the time length of ssh takes. If it take long than 5s (which means it is not available). Then stop it, and ssh to next host. Once a host is available, then output the name of host. I previously use nmap, but the IT security told it is not allowed to install it on the desktop on campus.
Code:
    HOSTS=`cat $host_list`
    for line in $HOSTS
    do 
    ssh -o ConnectTimeout=5s $line true >> /dev/null
    RESULT=$?
    if [ $RESULT -eq 0 ]
    then
    echo $line > succeed.txt
    else
    echo $line > fail.txt
    fi
    done
The above script is all I can do.
The problem is when it is failed, I want to redirect the error message
Code:
ssh: connect to host c28-0112-05.ad.mtu.edu port 22: No route to host
. But I still get the error message.
 
Old 05-24-2015, 07:03 PM   #2
Keith Hedger
Senior Member
 
Registered: Jun 2010
Location: Wiltshire, UK
Distribution: Void, Linux From Scratch, Slackware64
Posts: 3,150

Rep: Reputation: 856Reputation: 856Reputation: 856Reputation: 856Reputation: 856Reputation: 856Reputation: 856
>> means append to stream you want to use >, also > on its own redirects stdout, most apps send error to stderr which is stream 2 so you need to direct stderr to dev null with '2>/dev/null' to redirect both to /dev/null you can use 2>&1>/dev/null, wich redirects stderr to stdout and the directs stdout to dev/null, if you are using bash you can use &>/dev/null which does the same thing
 
1 members found this post helpful.
Old 05-24-2015, 07:28 PM   #3
Mike_Brown
Member
 
Registered: May 2015
Posts: 37

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by Keith Hedger View Post
>> means append to stream you want to use >, also > on its own redirects stdout, most apps send error to stderr which is stream 2 so you need to direct stderr to dev null with '2>/dev/null' to redirect both to /dev/null you can use 2>&1>/dev/null, wich redirects stderr to stdout and the directs stdout to dev/null, if you are using bash you can use &>/dev/null which does the same thing
I tried
Code:
[zwang10@c15-0331-04 ~/bin]$ ssh -o ConnectTimeout=5s c28-112a-05.ad.mtu.edu true 2 > & 1 > /dev/null
Ambiguous output redirect.
And
Code:
[zwang10@c15-0331-04 ~/bin]$ ssh -o ConnectTimeout=5s c28-112a-05.ad.mtu.edu true & > /dev/null
Invalid null command.
It does not work. I am using tcsh.
 
Old 05-24-2015, 07:35 PM   #4
Ser Olmy
Senior Member
 
Registered: Jan 2012
Distribution: Slackware
Posts: 3,339

Rep: Reputation: Disabled
2 > is not the same as 2>. Same goes for & > vs. &>. Remove the spaces, and things should start working.
 
2 members found this post helpful.
Old 05-25-2015, 05:50 AM   #5
Keith Hedger
Senior Member
 
Registered: Jun 2010
Location: Wiltshire, UK
Distribution: Void, Linux From Scratch, Slackware64
Posts: 3,150

Rep: Reputation: 856Reputation: 856Reputation: 856Reputation: 856Reputation: 856Reputation: 856Reputation: 856
was offline but good catch with the spaces!
 
  


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
Server Hung with error message: ERROR: Message hist queue is filling up iprince Linux - Enterprise 7 02-10-2014 09:40 AM
generate icmp redirect message amar31 Linux - Newbie 1 10-18-2012 09:18 PM
[SOLVED] syslog message redirect Gholi Linux - Server 1 08-25-2011 03:45 PM
postfix+redirect message. stomach Linux - Software 2 02-11-2006 09:56 AM
amavisd-new, redirect message stomach Linux - Software 0 02-07-2006 05:03 PM

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

All times are GMT -5. The time now is 08:40 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