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