logging to file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting logging to file
# 1  
Old 09-16-2010
logging to file

I am trying to figure a way to have a log file and still keep the output in the terminal in a script.
The example below logs to a file nicely but i still want the output in the terminal as well

Code:
#!/bin/bash
#Create a log

exec >> /path/to/my/logfile

echo "hello world"

Any help would be much appreciated, ive played with tee am im sure thats the way, but just cant figure it out.

Last edited by Scott; 09-16-2010 at 06:08 PM.. Reason: CODE tags for code, QUOTE tags for quotes
# 2  
Old 09-16-2010
Code:
echo "This go to log (create it) and screen" | tee logfile.log

echo "This go to log (update it) and screen" | tee -a logfile.log

# 3  
Old 09-16-2010
Hi,
I think tee is the way to go. The "-a" option is the key. Here's an example,

tail /var/log/messages | tee -a messy.log

this will give You stdout to console as well as written to a file.

/Lakris
# 4  
Old 09-17-2010
Perhaps try the script utility program?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

BASH logging to file, limit lines

BASH Gurus: Anyone know how to append continuous output command appending to a file, but limit that file to no more than 20 lines? The program I have running is simply monitoring my UDP port 53 for incoming packets endlessly. I just need to keep this file from going over 20 lines. Once the file... (3 Replies)
Discussion started by: scorpius2k1
3 Replies

2. Linux

Syslog not logging successful logging while unlocking server's console

When unlocking a Linux server's console there's no event indicating successful logging Is there a way I can fix this ? I have the following in my rsyslog.conf auth.info /var/log/secure authpriv.info /var/log/secure (1 Reply)
Discussion started by: walterthered
1 Replies

3. Windows & DOS: Issues & Discussions

Xterm logging on Cygwin/X - binary data in log file.

I have Cygwin/X installed on Windows 7. In an xterm, I turned on logging via Main Options > Log to File. When I open my log file with Vim I get a warning that it might be binary. Looking through the file I see what I think are VT datastream escape characters. It makes it hard to use the... (1 Reply)
Discussion started by: gctaylor
1 Replies

4. Programming

Logging in shared file

Hi. The problem is to write logs in a shared file from several processes. The cooperate call of fprintf() leads to messing the content even in one call example: fprintf(f,"a1 \n a2"); fprintf(f,"a3 \n a4"); out: a1 a3 a2 a4 Ofcourse this is possible to implement the file as a... (9 Replies)
Discussion started by: z7ql
9 Replies

5. Shell Programming and Scripting

Logging success event into file

Hi, I've the following code to log the errors any after the command is executed. # Ksh 88 Version log_path=/home/etc/fls/fls_log.log del_path=/home/etc/fls/to_day rm $del_path/* >> $log_path 2>&1 But I even want to log if the rm command is success without any error along with... (1 Reply)
Discussion started by: smile689
1 Replies

6. Shell Programming and Scripting

Tar file with logging and directory via parameter

Hi all, I am fairly new to shell scripting and I am trying the following: My shell script creates a tar file with files with the ending ~. The directory - where the files and sub directories are located - comes as a parameter when I call the script. Files that are archived will be written in... (1 Reply)
Discussion started by: neg42
1 Replies

7. UNIX for Dummies Questions & Answers

SQLPLUS Password Parameter file being used when logging in

Good day to everyone. This is my first time posting and just barely above basic Unix training. I think i have search thoroughly to ensure my question hasn't already been posted. But on the off chance the answer has been posted, please be nice as I am not 100% sure I know what I am looking for. I... (1 Reply)
Discussion started by: Mrjester
1 Replies

8. Shell Programming and Scripting

Logging in and running an update file from command

I am trying to upgrade many installations of a gallery script called coppermine through the commandline. I've copied the latest files of the script to each account. Then, I need to run a file gallery/update.php which requires I log in I can create an admin user for myself for each... (2 Replies)
Discussion started by: vanessafan99
2 Replies

9. UNIX for Dummies Questions & Answers

Logging all console activity to a file - how?

Hi all, Well I've had a bit more experience with Unix-like environments since my last post, now that I have started working on my website in earnest and am doing much of the file manipulation via the command line through SSH. The thing is, I want to be able to log all console activity,... (4 Replies)
Discussion started by: patwa
4 Replies

10. UNIX for Dummies Questions & Answers

logging SFTP details in a log file...

hi all..... i want to know how to log the details when logging into a server using SFTP......in FTP i used something like (ftp -uv<xxx.srp>>log_file.log) where the details will be logged to log_file...is there any options for doing the same in SFTP....i wanted to display the details abt... (4 Replies)
Discussion started by: santy
4 Replies
Login or Register to Ask a Question