ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Hi there,
Newbie here...I need to write a script that gathers info from system (run certain commands) and then delivers this info via an automated email. Does anybody know where I can find some kind of template for this? or even better.. can someone give me some detailed advice?.
Thanks.
Thanks for your input. Well the I need to gather info about the daily check-ins to our subversion server, and report them automatically every day. I'm looking for some script (or template) already written and just put in the commands I needed to run. Thanks any input will be greatly appreciated.
The following might be a starting point to do what you want:
Code:
#!/bin/bash
(
/usr/bin/date
/usr/bin/uptime
echo
echo "Current users:"
/usr/bin/who
echo
echo "Scan of localhost:"
/usr/local/bin/nmap -sT -sV -P0 localhost
echo
echo "Current connections:"
/bin/netstat --inet -ape
) 2>&1 > /var/www/html/reports/status.log
(
echo "To: Steve <mail@somewhere.com.au>"
echo "From: System Status <noreply@somewhere.com.au>"
echo "Subject: System status"
echo
echo "Ready for download at <http://www.somesite.com.au/reports/status.log>."
) 2>&1 | /usr/sbin/sendmail -t
It's easy enough to either wrap the output in html and make it a web page, or to redirect the output to mail so that the email contains the command output. If you do wrap the output in html, you should also change the output of the commands so that tag characters like "<" & ">" are converted to "<" & ">". You can use sed for this, e.g.:
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.