Domestic animals have largely lost their ability to empty these sacs voluntarily. Walking around and normal defecation serves to empty the glands but some animals become unable to empty their glands on their own at all. The sacs become impacted and uncomfortable. Dogs with impacted anal sacs usually scoot their rear on the ground in an attempt to empty the glands. Some dogs will lick their anal area and other dogs will chase their tails.
Cats often lick the fur off just under their tails.
An abscess can form and rupture out through the skin. This is a painful, messy and pretty smelly condition often mistaken for rectal bleeding. If an anal sac abscess forms, it must be properly treated by your veterinarian. Antibiotics will be needed. This is a highly individual situation.