A variável $ last está sendo ecoada como palavras individuais - cite-a ("$ last") para preservar novas linhas.
Eu estou tentando criar um script de shell que echo é um monte de comandos e consegui enviar e-mails de forma bastante simples.
{
echo $(hostname)
echo ""
echo "Uptime" $(uptime)
echo ""
echo "Who is on the server?" $(who)
echo ""
echo "Recent logs" $(last)
}| mail -s "Homework Report" [email protected]
As saídas nos e-mails são todas em uma única frase, formato bruto:
myhostname.com
Uptime 2:27PM up 15:59, 1 users, load averages: 0.44, 0.55, 0.51
Who is on the server? ec2-user pts/0 Dec 17 14:26 (pool-123-45-678-91.state.fios.verizon.net)
Recent logs ec2-user pts/0 Dec 17 14:26 pool-123-45-678-91.state Sun Dec 17 14:26 still logged in pool-123-45-678-91.state Sun Dec 17 05:12 - 05:13 (00:01) pool-123-45-678-91.state Sun Dec 17 02:45 - 05:12 (02:26) ec2-user pts/0 pool-123-45-678-91.state Sat Dec 16 22:28 - 02:16 (03:47) boot time Sat Dec 16 22:28 shutdown time Sat Dec 16 22:27 ec2-user pts/0 pool-123-45-678-91.state Sat Dec 16 21:48 - shutdown (00:38) ec2-user pool-123-45-678-91.state Fri Dec 15 23:45 - 23:45 (00:00) ec2-user pts/0 pool-123-45-678-91.state Fri Dec 15 23:23 - 23:23 (00:00) ec2-user pts/0 pool-123-45-678-91.state Fri Dec 15 23:23 - 23:23 (00:00) boot time Fri Dec 15 23:23 boot time Fri Dec 15 23:21 utx.log begins Fri Dec 15 23:21:59 UTC 2017
Qual é a melhor maneira de formatar as saídas de modo que pareça com as saídas nas linhas de comando?
Tags email freebsd shell-script