0

I would like to extend this line that calls /usr/bin/mplayer for recording an audio stream.

The referring script record.sh could get called multiple times in parallel and I need to know in which context an error is logged in the error file.

My question is therefore: how do I have to change this line so that in the beginning of each line also the contents of the variable "$file" is printed?

"$mplayer" $playlist $url $mplayerflags -msglevel all=2 -dumpstream -dumpfile "$file"  >/dev/null 2>>"$errors" <&2 &

Example: Instead of:

some arbitrary error message0
some arbitrary error message1
some arbitrary error message2

some arbitrary error message3
some arbitrary error message4
some arbitrary error message5

I would like to have:

/home/homedir/recordings/filelocation1.mp3 some arbitrary error message0
/home/homedir/recordings/filelocation1.mp3 some arbitrary error message1
/home/homedir/recordings/filelocation1.mp3 some arbitrary error message2

/home/homedir/recordings/filelocation1.mp3 some arbitrary error message3
/home/homedir/recordings/filelocation1.mp3 some arbitrary error message4
/home/homedir/recordings/filelocation1.mp3 some arbitrary error message5

2 Answers 2

0

You can't achieve that by changing the line; just print the file name without a newline before you call mplayer.

0

You can pipe to awk for instance to prefix each line with the file name:

"$mplayer" "${playlist[@]}" "$url" "${mplayerflags[@]}" \
  -msglevel all=2 -dumpstream -dumpfile "$file"  2>&1 > /dev/null |
  F="$file" awk '{print ENVIRON["F"]": "$0}' >> "$errors" &

Note:

  • I've removed the <&2 which didn't make sense.
  • fixed those unquoted parameter expansions. It seems to me $playlist and $mplayerflags are meant to be arrays.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .