sorting BAM file error using samtools I have few bam files and would like to get read counts using 

samtools idxstats


[Data is aligned to hg19 transcriptome]. To use that command I need a sorted bam file. So to sort them I gave the following command.

samtools sort -T /tmp/input.sorted -o input.sorted.bam input.bam


This ended up showing:

[W::bam_hdr_read] EOF marker is absent. The input is probably truncated.
[E::bgzf_read] bgzf_read_block error -1 after 0 of 4 bytes
[bam_sort_core] truncated file. Aborting.


And the tmp dir has 6 input.sorted.nnnn.bam files.
The cause of the error is that your input file is truncated or /tmp is running out of space. If you can do samtools view -H input.bam without error (reading the header also checks for the magic number at the end of the file) then it's like the that /tmp is filling up.