Tuesday, April 30, 2024
4
rated 0 times [  4] [ 0]  / answers: 1 / hits: 6284  / 1 Year ago, sun, december 4, 2022, 8:35:47

I am trying to run a test case via automation testing (sahi) , so I am running it repeatedly after 1 hour (via crontab).

What I want is that whenever my test case fails i should receive the email otherwise not. Right now I am receiving mail whether it passes or fails.

In short, can I send mail to a person depending upon the output I get in terminal.



I am using Ubuntu 10.10.


More From » command-line

 Answers
1

Pipelineing works in cron just as well as in bash. You could pipe the output to a script, that examines it and sends the mail. Or even easier use grep:



# in /etc/crontab

[email protected]
SHELL=/bin/bash

# m h dom mon dow user command
30 * * * * confus /home/confus/bin/someCommand.sh | grep -A 11 -B 10 "Error:"


This will send an e-mail to [email protected] when the stirng "Error: " occures in the output of someCommand.sh. In this case the text of the e-mail will be the output from 10 lines before and 11 lines after the occurrence of "Error: " (hence the -A for after and -B for before).



The mail is only send if the computer running cron has a working mail-server installed. A script to process the output is of course more flexible and considerably more work.


[#43668] Sunday, December 4, 2022, 1 Year  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
imberst

Total Points: 370
Total Questions: 107
Total Answers: 123

Location: French Polynesia
Member since Tue, Jul 7, 2020
4 Years ago
imberst questions
;