Thread: ]OT] Parsing postgresql.conf archive_command
Hello,
I'd like to get the path configured for archive_command in a shell script
I've used a file with following content as an example (postgresql.conf),
# archive_command = cp %p /backup/%r
# archive_command = cp %p /backup/%r
# archive_command = cp %p /backup/%r
#archive_command = cp %p /backup/%r
archive_command = 'cp %p /backup/wal/%f'
This is what I been trying.
$ awk '!/[ \t]*#/ { sub(/%f$/, "", $NF); print $NF }' postgresql.conf
and I get
/backup/wal/%f'
Any idea how to get rid of "%f'" so that I get only?
/backup/wal/
My regexp skills are sad :-)
Steve
I'd like to get the path configured for archive_command in a shell script
I've used a file with following content as an example (postgresql.conf),
# archive_command = cp %p /backup/%r
# archive_command = cp %p /backup/%r
# archive_command = cp %p /backup/%r
#archive_command = cp %p /backup/%r
archive_command = 'cp %p /backup/wal/%f'
This is what I been trying.
$ awk '!/[ \t]*#/ { sub(/%f$/, "", $NF); print $NF }' postgresql.conf
and I get
/backup/wal/%f'
Any idea how to get rid of "%f'" so that I get only?
/backup/wal/
My regexp skills are sad :-)
Steve
On Oct 3, 2008, at 6:05 AM, Joey K. wrote: > Hello, > > > I'd like to get the path configured for archive_command in a shell > script > > I've used a file with following content as an example > (postgresql.conf), > > # archive_command = cp %p /backup/%r > # archive_command = cp %p /backup/%r > # archive_command = cp %p /backup/%r > #archive_command = cp %p /backup/%r > archive_command = 'cp %p /backup/wal/%f' > > This is what I been trying. > $ awk '!/[ \t]*#/ { sub(/%f$/, "", $NF); print $NF }' postgresql.conf > > and I get > /backup/wal/%f' > > Any idea how to get rid of "%f'" so that I get only? > /backup/wal/ > > My regexp skills are sad :-) I usually prefer to string together more simple command than to compress it into one awkward command: dirname `grep -E '^archive_command' postgresqlc.conf | awk '{print $NF}' | awk -F\' '{print $1}'` dirname will directory component of a path (dirname /backup/wal/%f => / backup/wal) So, that's dirname on the results of grepping for the line that starts with archive_command piped through a basic awk (split on spaces) printing the last filed piped through an awk splitting on a single quote printing the first field. Erik Jones, Database Administrator Engine Yard Support, Scalability, Reliability (415) 963-4410 x 260 Location: US/Pacific IRC: mage2k