- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Script to email based on the user
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-06-2000 07:57 AM
09-06-2000 07:57 AM
The problem is that I want to put a variable in so that the script does basically a "whoami" for the e-mail address. That way who ever fires it off will get the message sent back to their e-mail offsite.
Any ideas?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-06-2000 07:59 AM
09-06-2000 07:59 AM
Re: Script to email based on the user
instead you can simply add an alias to the /etc/mail/aliases file. eg; in this file put an entry;
root :
jim : jim@hp.com
then run newaliases, from now on all email to root or jim it will go to the address specificied.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-06-2000 08:03 AM
09-06-2000 08:03 AM
Re: Script to email based on the user
If you want to use a script you can set a variable which is the result of a whoami command by doing;
USER=`whoami`
This will return a value such as root.
Then in your script you can mail something by going;
echo test | mailx -s"subject" $USER
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-06-2000 08:03 AM
09-06-2000 08:03 AM
Re: Script to email based on the user
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-06-2000 08:11 AM
09-06-2000 08:11 AM
Re: Script to email based on the user
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-06-2000 08:24 AM
09-06-2000 08:24 AM
Re: Script to email based on the user
when you go> USER=`whoami`
you must use backquotes, not forward quotes. The backquotes mean execute the command and put the results into the variable.
eg. after USER=`whoami`;echo $USER I get the answer root
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-06-2000 08:27 AM
09-06-2000 08:27 AM
Re: Script to email based on the user
If you want to use an e-mail address NOT corresponding to your UNIX id then use the .forward file in the home directory. Now grab the UNIX id from whoami and simply tack on your UNIX domainname. If you have a .forward file in the home directory then UNIX will try and use it.
If you want to use the aliases file you will have to take it one step further. If you don't use NIS, you will have to interogate the /etc/mail/aliases file or if your using NIS, interogate the aliases map with ypcat.
Tony
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-06-2000 08:37 AM
09-06-2000 08:37 AM
Re: Script to email based on the user
Set the variable: export WHOISIT=`whoami`
cat file | mailx -s TESTING" root $WHOISIT
You may want to be sure aliases or .forward files are in use as well.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-06-2000 09:12 AM
09-06-2000 09:12 AM
Re: Script to email based on the user
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-06-2000 09:36 AM
09-06-2000 09:36 AM
Re: Script to email based on the user
You may use `whoami` in command line to refer your own user name. e.g
elm -s Testing Mail `whoami' < /tmp/mailfile
Punjabhai V Patel
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-10-2000 04:50 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-10-2000 05:50 PM
09-10-2000 05:50 PM
Re: Script to email based on the user
#!/bin/perl
# This should match the mail program on your system.
$mailprog = '/usr/lib/sendmail';
$recipient = 'youremail@yourdomain.com';
$email = 'bob@hp.com';
# Now send mail to $recipient
open (MAIL, "|$mailprog $recipient") || die "Can't open $mailprog!n";
print MAIL "From: $emailn";
print MAIL "Subject: ITRCnn";
close (MAIL);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-11-2000 12:00 AM
09-11-2000 12:00 AM
Re: Script to email based on the user
if you use posix shell (/sbin/sh) or korn shell (/usr/bin/ksh) you can do:
USER=$(whoami)
this will put the output of the executable whoami into the variable USER.
Regards
Andrew
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-11-2000 04:34 AM
09-11-2000 04:34 AM
Re: Script to email based on the user
on a USASCII you find a backquote ` left of "1", a singlequote ' left of enter.
on a SwissGerman backquote is Shift+ left of backspace, singlequote one more to the left.
RGDS
Thomas
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-13-2000 06:38 AM
09-13-2000 06:38 AM
Re: Script to email based on the user
USER=`whoami`
cp report.wri ~/report.wri
< ~/report.wri
pg $1 > ~/report.wri
if [ ! -d ~/Mail ]; then
mkdir ~/Mail
fi
if [ ! -d ~/.elm ]; then
mkdir ~/.elm
fi
#!usr/bin/sh
echo "[include ~/report.wri application/octet-stream base64]" |
elm -s "report " $USER