1

I wanna write the output of various commands as an email. I tried this:

#!/bin/bash

(echo $(date); echo $(top);sudo apt-get update && sudo apt-get upgrade -y)  | mail -s "Updated!" [email protected] -a "From: UpdateNotify<[email protected]>";

The script is infinite. :/

How can I do that? I need the date,top output and the update logs in one email.

3 Answers 3

3

That's the right way to do it, the issue is with echo $(top). top is an interactive application so never returns.

You should look to use ps instead to list the current processes running.

Sign up to request clarification or add additional context in comments.

1 Comment

It is the right way to do it. It can also be formatted nicer with newline after the initial ( and newline before the closing ) and indentation in between. Then every command can be on its own line.
1

jas_raj answer is correct, however if you like top's output you can run in batch mode: top -bn 1 this will make top exit right after it runs once.

Comments

0

have a look at cron-apt and nullmailer to send mails after system update.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.