David Roberts thought he was chatting online to a teenage girl but it was his wife
A suspicious wife posed as a teenager online to catch her husband propositioning girls in a chatroom, Cardiff Crown Court has heard.
Cheryl Roberts, 61, pretended to be a 14-year-old girl and was asked by David Roberts, 68, to meet for sex.
Roberts admitted engaging in sexual activity in the presence of a child and making and possessing illegal images.
He was given a three-year community order and banned from having access in person or online to under 18s.
The couple have now split up and are getting divorced.
The court heard that mother-of-two Mrs Roberts became suspicious about the amount of time her husband was spending in his study and of a message which popped up on their computer while he was out.
While Roberts was chatting online in his study, Mrs Roberts used a different computer in the living room at their home in Pantygog, Bridgend, and pretended to be a schoolgirl.
Cheryl Roberts called the police after catching her husband propositioning schoolgirls for sex
Roberts propositioned the "girl", unaware he was chatting to his wife, the court was told.
Prosecutor Martyn Kelly told the court that Roberts, a former pub landlord who used the nickname 'Corky' online, also used a webcam to film himself carrying out acts of indecency - which his wife could see on her PC just yards away.
Mrs Roberts was so shocked by the behaviour of her husband of almost 20 years she brought in police, who seized his computer and found dozens of illegal child porn images.
Roberts believed he had been caught through downloading the images and did not know until weeks later that it was his wife who had called the police.
The court heard that, when interviewed, Roberts denied having sex with any schoolgirls but admitted he was "prepared to do so".
Byron Broadstock, defending, said: "He's brought shame on himself and his family."
Psychiatrists' reports said Roberts might have a brain disorder which causes him to be an exhibitionist.
Mr Broadstock said Roberts had been going through a dark patch at the time, was anxious to know why he had behaved in that way and would welcome treatment.
Claude Knights, director of children's charity Kidscape, said: "The offences that he has committed are very serious indeed and his wife must be commended for the active part that she played in bringing him to justice."