I have this command to see the space of my hard disk of my server: fdisk -l
and I do a grep to filter more the information that interests me (my main HD):
The command looks like this: fdisk -l | grep vda
, and to this I put the header of what each number is (the title) : df -h | grep -m1 "" && df -h | grep "/dev/vda1 "
, being as follows ->
Ok, once I have the information I need, I have a script to send emails, which works like this:
enviar_email.sh "(destinatario)" "Titutlo" "Cuerpo Mensaje"
So, the recipient and the Title are covered, but the body of the message I want to send the output of the previous command.
What I have tried without success is:
./enviar_email [email protected] "Un Asunto" $(df -h | grep -m1 "" && df -h | grep "/dev/vda1 ")
But the empty mail is sent to others because the command that creates the body fails. What I am trying to do is redirect the output to the style : echo "hola" > hola.txt
but as a parameter to my script.
I don't know if it's because that command doesn't give usable output and if so I don't understand how I could capture it and send it in one step.
And I want to avoid at all costs having to, prior to the script, create a file with the content of the script's output and read it when sending email, I think it's unnecessary.
You can try saving the output to a variable, as suggested on this page :