On Sat, 13 Nov 1999, Tim Howell wrote:
> Thanks for your help, Ramon. I now have a script that emails me only the
> assigned IP address - took a while to get the parsing right! A couple
> more questions, if you don't mind:
>
> 1. Is there a way to pipe the contents of a file into the subject line
> when using the "mail" command? I would like the designated IP address to
> show up as the subject, if possible.
Well, you can do it even more crudely than the first one.
Let us say that you wanted to have a message sent this
way:
cat somefile | mail -s subject [EMAIL PROTECTED]
In the command above, "somefile" will be the text
of the message, "subject" (preceded by -s) is the
subject of the message, and [EMAIL PROTECTED] is the
intended recipient (victim).
Now if the command above is inside a script file,
the scriptfile itself can be concatenated from
several files.
Here is an example
file 1
cat somefile | mail -s
file 2
this is your IP address that you want to report
file 3
[EMAIL PROTECTED]
Then them master script would simply have something
like this
cat file1 file2 file3 > scriptfile2
and when scriptfile2 runs, it contains the command
cat somefile | mail -s 192.168.97.45 [EMAIL PROTECTED]
This trick is used extensively in HTML programming to
put content into the middle of HTML files. You have
basically three files: the HTML headers, the part
you want inserted and the HTML footers. They are
concatenated together by a script and assembled into
a complete HTML file.
I your case, you would use the same technique, but
the final assembled product is actually executed so
the mail message can be sent. Be sure your permissions
are right. The use of the redirector > might give
you problems here, you may want to use something like
this:
cat bumfile > script
if the file "script" has been created with correct
permissions and is blank 0 bytes, then the script keeps
its ownership and permissions. You can then use this to
assemble it:
cat file1 file2 file3 >> script
This will append the 3 files to the (blank) file, so
the permissions and ownerships stays the same. This
trick is often used to erase a file but leaving it
in existence: cat /dev/null > file in which case
the "file" keeps its ownerships & permissions. This
is handy to erase log files because the > replaces
the contents, whereas >> appends contents.
I am sure there are more elegant ways to do this, but
hey, I am getting too old to learn fancy scripting
and sometimes the cheap and dirty works just fine.
> 2. I am using "pump" to retrieve my DHCP info, and am doing so on the
> @HOME network. I have read documentation stating that pump will contact
> the DHCP server every 3 hours to try to renew the lease - any idea where
> this gets called from? I would like the script to run every time the
> lease is renewed.
No idea. But commands can usually be located this way:
prompt# which pump
/usr/sbin/pump
NOTE: the above is ficticious, I have no idea if there
is a /usr/sbin/pump. I do not have that program here.
Anyway, if "pump" shows up, then see if its a binary or
a script and use the method I outlined in my first email
to append or prepend something to it.
--
Ramon Gandia ============= Sysadmin ============== Nook Net
http://www.nook.net [EMAIL PROTECTED]
285 West First Avenue tel. 907-443-7575
P.O. Box 970 fax. 907-443-2487
Nome, Alaska 99762-0970 ==== Alaska Toll Free. 888-443-7525