The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
using `` ( standart output redirection ) in cshell khazin UNIX for Dummies Questions & Answers 2 07-05-2008 04:31 PM
who truncates the output? redirection? tty? Bug? fredy UNIX for Advanced & Expert Users 7 12-10-2006 02:21 AM
Redirection of output (for logging) _Spare_Ribs_ Shell Programming and Scripting 3 12-04-2006 02:17 PM
redirection of ladebug output yakari UNIX for Advanced & Expert Users 2 10-06-2006 02:23 AM
Standard output and redirection jerardfjay Shell Programming and Scripting 2 06-27-2005 11:03 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 08-21-2008
JohnCrump JohnCrump is offline
Registered User
  
 

Join Date: Jun 2008
Posts: 8
Redirection of output to a log file

Apologies for the trivial nature of this question but I cannot seem to get a simple re direct to a log file to work

Step 1
touch log.txt
at -f batch.sh now >> log.txt

I am trying to get the batch.sh contents into the log file

Manny Thanks
  #2 (permalink)  
Old 08-21-2008
Franklin52 Franklin52 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,212
The touch command isn't necessary, the file is created if it's not present.
Does your script echo the messages to stdout/stderr? Try to redirect both the output to the file:

Code:
at -f batch.sh now >> log.txt 2>&1
Regards
  #3 (permalink)  
Old 08-21-2008
JohnCrump JohnCrump is offline
Registered User
  
 

Join Date: Jun 2008
Posts: 8
Thanks for the help so far. I now get output in the log but just the
job time and date message. I need the output from the run of batch.sh

Regards
  #4 (permalink)  
Old 08-21-2008
otheus's Avatar
otheus otheus is offline Forum Staff  
Moderator ala Mode
  
 

Join Date: Feb 2007
Location: Innsbruck, Austria
Posts: 1,864
Right... at is a batch program which will queue the process and run it at a future point in time. Redirecting NOW doesn't redirect the output later. (Redirection is a shell function). "at", however, will save the program's output to a file and email it to you. So check in Mail (or make sure email is properly setup for forwarding.) If you don't want email, then do this at the beginning of the script:

Code:
# ... initialization of your script
exec >$HOME/script-output.$$ 2>&1
# rest of your script
If you want to append to the same file everytime, do this instead:

Code:
# ... initialization of your script
exec >>$HOME/script-output.log 2>&1
# rest of your script
  #5 (permalink)  
Old 08-21-2008
Franklin52 Franklin52 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,212
What output? Any output of your script should be in the file now....
Post the contents of batch.sh.

Regards
  #6 (permalink)  
Old 08-21-2008
JohnCrump JohnCrump is offline
Registered User
  
 

Join Date: Jun 2008
Posts: 8
all that batch is doing in this instance is

/dev/vg00/lvol3 2097152 299240 1784336 14% /
/dev/vg00/lvol1 1048576 140264 901320 13% /stand
/dev/vg00/lvol21 2097152 127451 1857821 6% /webservers
/dev/vg00/lvol8 4784128 2101952 2661592 44% /var
/dev/vg00/lvol9 2097152 16982 1950167 1% /var/adm/crash
/dev/vg00/lvol7 6356992 5681080 670680 89% /usr
/dev/vg00/lvol12 1572864 645992 868997 43% /usr/cache
/dev/vg00/lvol4 262144 9960 250264 4% /tmp

this is what i need in the log
  #7 (permalink)  
Old 08-21-2008
otheus's Avatar
otheus otheus is offline Forum Staff  
Moderator ala Mode
  
 

Join Date: Feb 2007
Location: Innsbruck, Austria
Posts: 1,864
So in your script, you just need to do this:

Code:
#!/bin/sh
df 2>&1 | tee -a logfile.log
Now the output will be see both in the logfile and in your email.
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 03:24 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0