LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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 07-21-2012, 07:07 AM   #1
figure20012
Member
 
Registered: Apr 2012
Posts: 75

Rep: Reputation: Disabled
cannot redirect output to file please help


I cannot redirect output to a file.It appears on the bash output
my command is
/usr/java/j2sdk1.4.2_03/bin/java -version > output.txt
the output is display on the bash shell
i want it to be redirected to the file
please help
 
Old 07-21-2012, 07:32 AM   #2
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
Try this:
exec 2 > filename
<command>
 
Old 07-21-2012, 07:42 AM   #3
figure20012
Member
 
Registered: Apr 2012
Posts: 75

Original Poster
Rep: Reputation: Disabled
thanks a lot pixellany
it worked..
 
Old 07-21-2012, 07:42 AM   #4
silendo
Member
 
Registered: Jun 2012
Location: Italy
Distribution: Slackware 13.37
Posts: 45

Rep: Reputation: Disabled
you must use this command:

Code:
/usr/java/j2sdk1.4.2_03/bin/java -version 2> output.txt
 
Old 07-21-2012, 07:43 AM   #5
figure20012
Member
 
Registered: Apr 2012
Posts: 75

Original Poster
Rep: Reputation: Disabled
thnx silendo
 
Old 07-21-2012, 08:12 AM   #6
figure20012
Member
 
Registered: Apr 2012
Posts: 75

Original Poster
Rep: Reputation: Disabled
i have another problem now
i need to ssh on a remote machine to run the command
result=`ssh "10.0.2.15" /usr/java/j2sdk1.4.2_03/bin/java -version`
$result 2>> result.txt


the result is not copied to the result.txt
Can anyone please help me
 
Old 07-21-2012, 01:36 PM   #7
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
redirection only works when some output is being generated. "$result" does not generate any output.

Try using
Code:
echo $result >> result.txt
 
Old 07-21-2012, 11:07 PM   #8
figure20012
Member
 
Registered: Apr 2012
Posts: 75

Original Poster
Rep: Reputation: Disabled
result=`ssh "10.0.2.15" /usr/java/j2sdk1.4.2_03/bin/java -version`
echo $result 2>> result.txt does not work
the result from /usr/java/j2sdk1.4.2_03/bin/java -version is not copied to $result
the echo $result >> result.txt copied null to result.txt
how can i do that Sir?
 
Old 07-22-2012, 04:19 AM   #9
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
figure*;

You have marked the thread "SOLVED"---this means that most people will not see your new question.

First: What happens if you just do this?:
Code:
ssh "10.0.2.15" /usr/java/j2sdk1.4.2_03/bin/java -version
Side issue:
It seems that "command 2> filename" does not always work. I'm not sure why
 
1 members found this post helpful.
Old 07-22-2012, 07:09 PM   #10
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
This works for me as a test
Code:
r=$(ssh 127.0.0.1 perl -v)
echo $r  # shows perl version info
echo $r>t.t
cat t.t   # shows perl version info
note that in *nix

0 = stdin
1 = stdout
2 = stderr

HTH
 
1 members found this post helpful.
  


Reply

Tags
bash scripting



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
How to redirect to a file the output of a service? rtmex Linux - Newbie 5 04-26-2007 11:09 PM
output redirect back to file mathfeel Linux - Software 1 03-21-2007 12:28 PM
How to redirect output to a file? mus1402 Linux - Newbie 2 02-05-2006 09:42 AM
redirect screen output to file timbuck Linux - Software 5 12-09-2005 06:57 PM
how to redirect the soundcard output to a file? jr0 Linux - General 2 10-31-2005 06:29 AM

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

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