1

I try to get a listing from an directory with mod time and send this per pipe to mail command

so I fiddled this construct together:

find /etc/myfolder -type f -exec sh -c 'printf "%-40s %s\n" $(echo {}|sed "s:/etc/myfolder::g") "$(stat -c %y {})" ' \; | mail -a "FROM: Server <root@server.com>" -a "Content-type: text/plain; charset=UTF-8" -s "test" my@domain.com

Now I want that I have a title line on top - but don’t know how.

printf "%-40s %s\n" File Mod | find ....

This cant work, because find don't forward it to the next pipe.

Any Idea how to do it? I know it is possible that I write the content first to a file and pipe later this file content to mail, but that's not what I want to do.

I prefer a oneliner :)

OK, this is now the working example I use in crontab:

(printf "\%-40s \%s\n" File Mod; find /etc/folder -type f -exec sh -c 'printf "\%-40s \%s\n" $(echo {}|sed "s:/etc/folder/::g") "$(stat -c \%y {})" ' \; ) | mail -a "FROM: Server <root@server.com>" -a "Content-type: text/plain; charset=UTF-8" -s "Test" my@domain.com
4

1 回答 1

1

在将输出传送mail.

说:

{ echo "My title"; find ... \; ; } | mail ...

(请注意,\;在上面的命令中表示终止提供给的命令-exec。另一个分号是终止列表所必需的。)

于 2013-09-24T11:02:57.920 回答