[Solved] Writing output to the console


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting [Solved] Writing output to the console
# 1  
Old 06-27-2013
[Solved] Writing output to the console

Hi All,

I have written one script in which am writting the result to the log file.
I want to display the results on the console also

Code:
 
if [ -n "$result" ];
then
echo "$result doesnot match with the host file">>InputHostsFileErrors.txt
else
echo "$result input matches with the host file">>InputHostsFileSuccess.txt
rm -f InputHostsFileSuccess.txt 
fi

can you please let me know how can I write it the results on console also?
# 2  
Old 06-27-2013
HI,

You can add the below code to script file.
Code:
set -x

# 3  
Old 06-27-2013
Thanks for your Input. But it is writing everything to the console. I want to write only the thing which am writing to the log file

Code:
 
echo "$result doesnot match with the host file">>InputHostsFileErrors.txt

To the console also. So user can view on console also and if needed see in the log file.
# 4  
Old 06-27-2013
Hi,

I dont know if this is the best way of doing this, but it works.

Code:
output()
{
        echo $1 >> $2
        echo $1
}

if [ -n "$result" ];
then
output "$result doesnot match with the host file" InputHostsFileErrors.txt
else
output "$result input matches with the host file" InputHostsFileSuccess.txt
rm -f InputHostsFileSuccess.txt 
fi

Declare a method for doing this.
# 5  
Old 06-27-2013
see "man tee" ...
Code:
echo "$result doesnot match with the host file" | tee -a InputHostsFileErrors.txt

This User Gave Thanks to Just Ice For This Post:
# 6  
Old 06-27-2013
Thansk Just Ice

It is working for me.
# 7  
Old 06-28-2013
The command "echo "$result doesnot match with the host file" | tee -a InputHostsFileErrors.txt" only works if you want the information displayed on the terminal you are using. To display it on the console try:
Code:
echo "$result doesnot match with the host file" | tee -a InputHostsFileErrors.txt > /dev/console 2>&1

---------- Post updated at 08:36 AM ---------- Previous update was at 08:11 AM ----------

Sorry previous post was a little incorrect. While it would work it wouldn't capture and log STDERR correctly. Try this:
Code:
echo "$result doesnot match with the host file"  2>&1 | tee -a InputHostsFileErrors.txt > /dev/console

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Web Development

302 Redirects Issues Effected Google Search Console (GSC) Fixed - DBSEO Goto Rewrite Problems Solved

Finally! Yesterday I FINALLY figured out why Google Search Console (GSE) was showing so many pages with 302 redirects in our link budget. For over a year, I thought this issue was relate to either Apache2 or DBSEO (our PHP module which rewrites our links to be SEO friendly). However, when I... (5 Replies)
Discussion started by: Neo
5 Replies

2. Solaris

[SOLVED] Console connection to V240

My apologies if this is posted/answered elsewhere. I have recently been tasked with getting 2 Sun V240's running Solaris 10 up and working. I should mention I come from the programming side of life with a small amount of networking on Windows 2003 servers. They boot, no error lights, hd's... (6 Replies)
Discussion started by: kuriosity_prime
6 Replies

3. UNIX for Dummies Questions & Answers

[Solved] Writing a loop to changing the names of files in a directory

Hi, I would like to write a loop to change the names of files in a directory. The files are called data1.txt through data1000.txt. I'd like to change their names to a1.txt through a1000.txt. How do I go about doing that? Thanks! (2 Replies)
Discussion started by: evelibertine
2 Replies

4. Shell Programming and Scripting

[Shell/Perl(?)] Prepending timestamps to console output & writing results to a file

I do a lot of TSM work and I embarked on what I thought would be an easy task, and I'd be very happy for any input to save the pounding my keyboard is receiving :] By default, the output of TSM's console has no timestamping, making it hard to sort through accurately. This puts my console into... (5 Replies)
Discussion started by: Vryali
5 Replies

5. Shell Programming and Scripting

Grep on console output

Hellos! I want to have a unix script that will run grep on the console output. Here is what my script does: 1. Telnet into a remote server (I have done this part successfully) 2. On successful login, the remote server displays outputs information on the console. I need to run grep on that... (6 Replies)
Discussion started by: puneet1984
6 Replies

6. Solaris

No Console Output

Hey everyone I have a sparc enterprise T2000 I'm trying to install solaris 10 on. The only way I can connect to it is the SER MGT console, but I'm not getting anything to display (in Hyper terminal, or PUTTY) when I boot it. Upon googleing, all I get back is "No output may have been generated.... (4 Replies)
Discussion started by: goodvikings
4 Replies

7. Shell Programming and Scripting

[solved] merging two files and writing to another file- solved

i have two files as file1: 1 2 3 file2: a b c and the output should be: file3: 1~a 2~b 3~c (1 Reply)
Discussion started by: mlpathir
1 Replies

8. UNIX for Dummies Questions & Answers

Command display output on console and simultaneously save the command and its output

Hi folks, Please advise which command/command line shall I run; 1) to display the command and its output on console 2) simultaneous to save the command and its output on a file I tried tee command as follows; $ ps aux | grep mysql | tee /path/to/output.txt It displayed the... (7 Replies)
Discussion started by: satimis
7 Replies

9. UNIX for Dummies Questions & Answers

Writing to a file without echo it to the console !!!!

hi all, I am trying to write some message to a file using the following command. echo "${MESSAGE}" >&1 | tee -a ${File_name} can the same be done without using echo . I don't want the result to be displayed to the console. Can anyone guide me. Thanks in advance (6 Replies)
Discussion started by: amit_kv1983
6 Replies

10. UNIX for Dummies Questions & Answers

Eleminating output to console

I am running Shorewall firewall config program to utilize iptables on a Debian 3.3.5 system. This system is setup for a getway/router. I am getting a message: Shorewall:bogons:Drop:IN=eth0 OUT= MAC+ mac address of eth0 SRC:someinternetIP DST=MYIPADD LEN=61 TOS+0x00 PREC=0x00 TTL=114 ID=6673... (3 Replies)
Discussion started by: pflink
3 Replies
Login or Register to Ask a Question