A man who admitted to a “disturbing” social media campaign and other offences against his ex-partner has avoided prison.