开发者

How can I make contents of a txt file be used as subject for mail in linux?

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 me@sample.com < /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 u开发者_StackOverflow中文版se mail -s to specify subject but since many tests are being run through the launcher the subject will always vary

Thanks in advance


Try

subject=$(</path/subject.txt)
mailx -s "$subject" me@sample.com < /usr/python/bi_python/launcher/test_output.txt


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜