Anonymous Named Pipes

When I worked with Oracle Service Bus installed on Solaris, I created the one-liner command for creating report of today’s max average times per message type from reading log files in OSB cluster consisting of two servers.

I used awk with two process substitution (anonymous named pipes) inputs. You interface with these as if they were files, but they behave like pipes. In other words, and from a practical point of view, you can use an expression like the following <(commands) as a file name for other commands requiring a file as a parameter.

The main advantages of process substitution over its alternatives are:

  • Simplicity: The commands can be given in-line; there is no need to save temporary files or create named pipes first.
  • Performance: Reading directly from another process is often faster than having to write a temporary file to disk, then read it back in. This also saves disk space.
  • Parallelism: The substituted process can be running concurrently with the command reading its output or writing its input, taking advantage of multiprocessing to reduce the total time for the computation.

Running a command in parenthesis in a shell invokes a seperate subprocess, so multiple uses of <() are run in parallel automatically.

The command:

/usr/xpg4/bin/awk ‘{a[$1″ “$2]+=$3;b[$1” “$2]+=$4;c[$1” “$2]+=1}END{for (i in a) print i,” “,a[i],” “,b[i]/c[i];}’ <(/usr/gnu/bin/find /u01/app/oracle/admin/soa_domain/mserver/soa_domain/servers/wls1_osb1/logs/access* -daystart -mtime 0 -exec grep $(date +”%Y-%m-%d”) /dev/null {} \;| /usr/xpg4/bin/awk ‘{a[$5″ “$6]++;b[$5” “$6]+=$8}END{for (i in a) print i,” “,a[i],” “,b[i]/a[i];}’) <(ssh oracle@soa02 “/usr/gnu/bin/find /u01/app/oracle/admin/soa_domain/mserver/soa_domain/servers/wls2_osb1/logs/access* -daystart -mtime 0 -exec grep $(date +\”%Y-%m-%d\”) /dev/null {} \;| /usr/xpg4/bin/awk ‘{a[\$5\” \”\$6]++;b[\$5\” \”\$6]+=\$8}END{for (i in a) print i,\” \”,a[i],\” \”,b[i]/a[i];}'”) | grep -i -v wsdl | sort -k 1,2

Ovaj unos je objavljen u Nekategorizirano. Bookmarkirajte stalnu vezu.

Jedan odgovor na Anonymous Named Pipes

  1. Povratni ping: Partitioning (Clustering) Around Medoids | Tmilinovic's Blog


Popunite niže tražene podatke ili kliknite na neku od ikona za prijavu: Logo

Ovaj komentar pišete koristeći vaš račun. Odjava /  Izmijeni )

Google photo

Ovaj komentar pišete koristeći vaš Google račun. Odjava /  Izmijeni )

Twitter picture

Ovaj komentar pišete koristeći vaš Twitter račun. Odjava /  Izmijeni )

Facebook slika

Ovaj komentar pišete koristeći vaš Facebook račun. Odjava /  Izmijeni )

Spajanje na %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.