Skip to main content
formatting; tags
Source Link
chaos
  • 49.3k
  • 11
  • 127
  • 147

I am aware that iI can log using tee

But I want to log from inside my script, at the same time display the content on the stdout also.

Example, my code looks something like this:

    names=$(print("name1 name2 name3 name4"))

    for name in names
    do
       echo "Current Name: " $name 
       related_job= ps -ef | grep $name | awk '{print $9}' >> File.dat
       echo "related job: " $related_job
    done 

Now, this block will certainly echoecho at stdout, but iI even want to log this to a log file, say script_name.logscript_name.log.

Also, iI am calling the script through a scheduler and sue to come constraint iI can't use script_name | tee log_file . I can just call the script by the script name.

What could be the solution to itthis?

I am aware that i can log using tee

But I want to log from inside my script, at the same time display the content on the stdout also.

Example, my code looks something like this:

    names=$(print("name1 name2 name3 name4"))

    for name in names
    do
       echo "Current Name: " $name 
       related_job= ps -ef | grep $name | awk '{print $9}' >> File.dat
       echo "related job: " $related_job
    done 

Now, this block will certainly echo at stdout but i even want to log this to a log file, say script_name.log.

Also, i am calling script through a scheduler and sue to come constraint i can't use script_name | tee log_file . I can just call the script by script name.

What could be the solution to it?

I am aware that I can log using tee

But I want to log from inside my script, at the same time display the content on the stdout.

Example, my code looks something like this:

    names=$(print("name1 name2 name3 name4"))

    for name in names
    do
       echo "Current Name: " $name 
       related_job= ps -ef | grep $name | awk '{print $9}' >> File.dat
       echo "related job: " $related_job
    done 

Now, this block will certainly echo at stdout, but I even want to log this to a log file, say script_name.log.

Also, I am calling the script through a scheduler and sue to come constraint I can't use script_name | tee log_file . I can just call the script by the script name.

What could be the solution to this?

Source Link
NishantM
  • 13
  • 2
  • 8

How to log from inside the script along with stdout

I am aware that i can log using tee

But I want to log from inside my script, at the same time display the content on the stdout also.

Example, my code looks something like this:

    names=$(print("name1 name2 name3 name4"))

    for name in names
    do
       echo "Current Name: " $name 
       related_job= ps -ef | grep $name | awk '{print $9}' >> File.dat
       echo "related job: " $related_job
    done 

Now, this block will certainly echo at stdout but i even want to log this to a log file, say script_name.log.

Also, i am calling script through a scheduler and sue to come constraint i can't use script_name | tee log_file . I can just call the script by script name.

What could be the solution to it?