Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

LINK TO THIS FORUM!

Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Feedback

"...just the few hours I've spent on this site I have learned a lot. I can now implement features that will be very useful to my company, and some of those I never knew existed..."

Geography

Where in the world do Tek-Tips members come from?

Shell script output to console and logfileHelpful Member!(2) 

AlStl (MIS)
13 Feb 12 13:21
Guys,

I have successfully coded the shell script output to a logfile:

LOG_DIR = /xxx/yyy

exec 1>$LOG_DIR/script_name/$(date +%Y%m%d%H%M).log

This script performs several functions. Mainly inserting data into several Oracle tables. This takes time. I want to see these two things happen. A or B or BOTH

a) Beside stdout to LOG_DIR i also want to see the output on the screen. Reason: At least i will  know when this thing ended.

b) Script tells me when it ended something echo on the screen.

Can someone help?

Al
Helpful Member!  Annihilannic (MIS)
13 Feb 12 18:04
For option (b) you could just echo something to standard error (since you are only logging standard output) when the script is done, e.g.:

CODE

print -u2 "job done"      # ksh only

echo "job done" >&2

To use tee as PHV suggested you would need to either redirect the output of your entire script into a tee command rather than using the exec format, or do something like this:

CODE

LOG_DIR = /xxx/yyy

# create a pipe file
mknod /tmp/pipefile.$$ p

# start tee process in background to read it and output contents
# to screen and log file
tee $LOG_DIR/script_name/$(date +%Y%m%d%H%M).log </tmp/pipefile.$$ &

# redirect stdout to the pipe file for remainder of script
exec >/tmp/pipefile.$$

#
# main script here
#

# clean up pipe file
rm -f /tmp/pipefile.$$

Another perhaps neater way is with Ksh Co-processes, and your exact requirements are describe in exercise 9 here:

http://www.dartmouth.edu/~rc/classes/ksh/coprocesses.html

Bash 4.0 also supports them, but I haven't tried it, and it doesn't look as tidy:

http://www.linuxjournal.com/content/bash-co-processes

Annihilannic
tgmlify - code syntax highlighting for your tek-tips posts

Helpful Member!  PHV (MIS)
13 Feb 12 18:11
A very simple way:

CODE

LOG_DIR = /xxx/yyy
log=$LOG_DIR/script_name/$(date +%Y%m%d%H%M).log
(
echo "Start job: $(date)"
your script here
echo "End job: $(date)"
) | tee $log

Hope This Helps, PH.
FAQ219-2884: How Do I Get Great Answers To my Tek-Tips Questions?
FAQ181-2886: How can I maximize my chances of getting an answer?

AlStl (MIS)
14 Feb 12 15:23
Guys,

Thanks a lot of your input. I am going to mull over this and decide the best way forward.

Al

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Back To Forum

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close