It's not clear what exactly you're trying to archive; but timing how long a command takes is fairly easy, for example:
#!/bin/sh
start=$(date +%s)
out=$(sleep 6)
took=$(($(date +%s) - $start))
if [ $took -gt 5 ]; then
echo "$out" | mail -s "Command took too long" test@example.com
fi
Edit
This required the command to finish; if you want to have a timeout, I'd recommend using Python. It is possible with shell scripting, but IMHO this is much easier.
#!/usr/bin/env python
import subprocess, smtplib
from email.mime.text import MIMEText
proc = subprocess.Popen(['sleep', '100'])
try:
proc.wait(5) # 5 is the timeout in seconds
except subprocess.TimeoutExpired:
proc.kill()
# Send email
msg = MIMEText("Command took too long\r\n")
msg['Subject'] = 'Command took too long'
msg['From'] = 'test@example.com'
msg['To'] = 'test@example.com'
s = smtplib.SMTP('localhost')
s.sendmail('test@example.com', ['test@example.com'], msg.as_string())
s.quit()