Since a BAM should contain overlapping reads that may or may not agree at any particular base instead of a single sequence then the answer to your question is not straight-forward. First you'll need to generate a consensus sequence via 'samtools', 'bcftools' and 'vcfutils' ... see:
http://samtools.sourceforge.net/mpileup.shtml. Having gotten that then you can pull out the bases.
There may be easier ways but that is how I would do it.