1

I am on UBUNTU 12.04.

I have a shell script that logs the output of a certain processes. The process being logged changes depending on the parent shell script that called the logging script. I would like to write the output of this logging to a file on disk, but am having trouble naming the file.

I would love to name it according to the parent script's own name. Unfortunately I have absolutely no idea how to get that name from script. I imagine that the best way to do that would be to extract the parent PID ($PPID), and then use that to find the script name, but I also don't know how to do that.

1 Answer 1

7

Instead of jumping through hoops to do this, just have the parent open the log on say FD4. Then whenever you need to log, just write to FD4.

# parent script
exec 4>> parent.log

# child script
echo "Log me!" >&4
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks! Much easier than the solution I was devising!
+1 but would be even better with the child call and FD closing.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.