views:

24

answers:

2

Hi, I have a crontab file which executes a shell script as shown below

27 11 * * * /usr/python/bi_python/launcher/launch_script_leds.sh

The shell script does a number of things:

1)executes python script launcher.py which runs tests and outputs to log files

2)sends mail notification when tests have completed with test output as body of the message

This is the command in the .sh file:

mail [email protected] < /usr/python/bi_python/launcher/test_output.txt

This works fine but subject is blank

The subject for the email is out put to a txt file subject.txt from launcher.py. Is there a way to make the contents of this file the subject of my mail message?

I know you can use mail -s to specify subject but since many tests are being run through the launcher the subject will always vary

Thanks in advance

A: 

Try

subject=$(</path/subject.txt)
mailx -s "$subject" [email protected] < /usr/python/bi_python/launcher/test_output.txt
ghostdog74
Worked Great thanks for that ghostdog :) i'm sure the other suggested solutions worked too but this was the first one i tried. Thanks all
Michael Turner
A: 

Well, just pass the parameter -s to the mail command, with a suitable subject.

To use the contents of a file as the subject, just read the file. In Bash,

filecontents=$(cat /my/file)

will read the contents of /my/file into variable filecontents. Then you can truncate/sanitize the text as necessary, and use it as the parameter to -s.

sleske