Reputation: 1759
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.
Upvotes: 1
Views: 202
Reputation: 798606
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
Upvotes: 7