Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

My cron job is running the following line:

*/40 * * * * cd /home/qa/prod/seo/casino &&  make testv   2> /dev/stdout | /usr/sbin/sendmail -t xxxx@gmail.com

As you can see I am using the sendmail package. The thing I don't manage to find out is how to add a subject to the currently-running cron schedule.

I've came across the following :

echo "Subject: Testing" | cat - /home/file1.out | /usr/sbin/sendmail -t xxxx@gmail.com

However, I have no idea whats the 'cat - /home/file1.out' pipeline does in this case, or how I can integrate it with my own.

Help would be appreciated!

share|improve this question

2 Answers 2

cat - /home/file1.out is for the body of the message.

- means STDIN in this case, STDIN for cat.

[sgeorge@sgeorge-ld ~]$ echo "Subject: Testing" | cat - file 
Subject: Testing
TESTING TESTING
[sgeorge@sgeorge-ld ~]$ echo "Subject: Testing" | cat file 
TESTING TESTING

Actually you don't need it actually:

[sgeorge@sgeorge-ld ~]$ cat test 
Subject: Testing
TESTING TESTING
[sgeorge@sgeorge-ld ~]$ cat test | /usr/sbin/sendmail -t xxxxx@xxxxxx.com

The just above method will also work in the same way as below one works

echo "Subject: Testing" | cat file | /usr/sbin/sendmail -t xxxxx@xxxxxxxx.com 

For more understanding:

[sgeorge@sgeorge-ld ~]$ echo "Subject: Testing" | cat file -
TESTING TESTING
Subject: Testing
[sgeorge@sgeorge-ld ~]$ echo "Subject: Testing" | cat - file 
Subject: Testing
TESTING TESTING

So - is just an STDIN here.

share|improve this answer

The - in cat - tells cat to read the content from pipeline and print it to stdout, so that echo "Subject:Testing " | cat - /home/files1.out means combine "Subject: Testing" with content of files1.out.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.