Getting the name of the process that sent data to a pipe? (bash)
I am trying to automate some directory naming when we're manually running some scripts and are using tee to direct the output to a file (log).
Right now this is what we do Code:
./some_script.sh 2>&1 | tee /home/user/some_dir/logs/manual/some_script_20110216_1628.log How I envision the command running Code:
./some_script.sh 2>&1 | myfunc Code:
some_script_20110216-1628.log Just in testing I was trying to stream line right on the command line, but I'm having some difficulty in getting the name of the script that is pushing data over the pipe. Here is what I've tried Code:
./some_script.sh 2>&1 | tee $(cd ../logs/manual; pwd)/$0_$(date +%Y%m%d)-$(date +%H%M).log "bash_20110216-1628.log" Can anyone offer any suggestion? Thanks ahead of time! |
Short answer is you can't. The command is just reading from stdin, so it doesn't know where the input is coming from. You may be able to figure out a way to pull it from the history, but its seems like create a script of a function that takes a script name and runs it naming the output log based on the script name would be simpler.
|
Thanks for the reply - before I had even read it I was trying to mess with "!!" and "!$" to get what I needed but that seems to not be working the way I'd liked. I might be able to edit the scripts to export their name or something as well...a wrapper script was my first idea - it was met with opposition from the more senior members of my group...ugh.
|
Hi,
It is possible to create a function, but you need to be a bit creative: Code:
function myfunct() { Hope this helps. |
All times are GMT -5. The time now is 02:33 PM. |