LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-17-2006, 05:09 PM   #1
pachakutek
LQ Newbie
 
Registered: Jul 2006
Posts: 3

Rep: Reputation: 0
help writting an automated mail script?


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.
 
Old 07-18-2006, 02:12 AM   #2
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
I've got some Perl code that does that sort of stuff, but need more specific details of what sort of sys info you want to gather.
 
Old 07-18-2006, 07:34 AM   #3
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,515

Rep: Reputation: 239Reputation: 239Reputation: 239
just use batch, at or cron

e.g:
echo script_name | at 10pm
 
Old 07-19-2006, 02:14 PM   #4
pachakutek
LQ Newbie
 
Registered: Jul 2006
Posts: 3

Original Poster
Rep: Reputation: 0
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.
 
Old 07-19-2006, 02:47 PM   #5
gilead
Senior Member
 
Registered: Dec 2005
Location: Brisbane, Australia
Distribution: Slackware64 14.0
Posts: 4,141

Rep: Reputation: 168Reputation: 168
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 "&lt;" & "&gt;". You can use sed for this, e.g.:
Code:
/usr/bin/ps auxfww | /bin/sed -e s/</\&lt;/g -e s/>/\&gt;/g
As I said, just a starting point - hope it helps...
 
Old 07-19-2006, 05:28 PM   #6
pachakutek
LQ Newbie
 
Registered: Jul 2006
Posts: 3

Original Poster
Rep: Reputation: 0
Thank you. It definitely somewhere to start. I'll post progress later on. Thanks again.
 
Old 07-20-2006, 03:48 AM   #7
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,515

Rep: Reputation: 239Reputation: 239Reputation: 239
It's quite easy,

basically:
Code:
cat file | mailx -s subject user@box
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
automated mail a given file overlord73 Linux - General 2 02-10-2006 04:15 AM
Automated mail ioanv Linux - Software 4 03-29-2005 02:47 AM
writting a backup shell script yenonn Slackware 2 03-18-2004 07:49 PM
Automated E-Mail cleansing. Thrifty Linux - Software 0 02-20-2004 12:17 PM
Automated su script? elmetald00d Linux - General 5 04-08-2002 11:17 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:00 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration