Using mailx In A Function


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Using mailx In A Function
# 1  
Old 03-18-2008
Using mailx In A Function

All,

I have a ksh script running on HP-UX (B.11.23 U ia64) that calls mailx and works the way I want. But I am modifying my script so that it uses functions instead of processing in-line. When I moved the mailx stuff into a function, it won't send the mail. It hangs and I have to Ctrl-C to get out. I've moved this portion of the script to a separate file so I can test the mail stuff by itself, but it's not working. Any help is appreciated. Code:

sendtestemail()
{
SUBJECT="TEST .: HP-UX E-Mail Test :. TEST"
TO="me@mycompany.com"
USERS=$(grep @mycompany.com /dir1/dir2/addys | awk '$1 == "#CP" {print $2}')

echo "Sending e-mail request..."

mailx -s "$SUBJECT" "$TO" \<\<-EOT
"Test script; please ignore. Thanks!"

"*** NOTE ***"
"This is not a production script."
"A production script would have been e-mailed to the following users:"

"Users"
"----------------------------------"
"$USERS"

"-------------------------------------------------------------------------------"
"This e-mail was automatically generated by the ${0##*/} script on $(hostname). Please do not reply."
~.
EOT
}
# 2  
Old 03-18-2008
RE: Using mailx In A Function

Smilie

Never mind. I figured it out. When I was testing, I guess I put the back ticks "`" in the wrong place. They should be at the beginning of the mailx line and after the EOF line.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Function - Make your function return an exit status

Hi All, Good Day, seeking for your assistance on how to not perform my 2nd, 3rd,4th etc.. function if my 1st function is in else condition. #Body function1() { if then echo "exist" else echo "not exist" } #if not exist in function1 my all other function will not proceed.... (4 Replies)
Discussion started by: meister29
4 Replies

2. Shell Programming and Scripting

Need help on awk for printing the function name inside each function

Hi, I am having script which contains many functions. Need to print each function name at the starting of the function. Like below, functionname() { echo "functionname" commands.... } I've tried like below, func=`grep "()" scriptname | cut -d "(" -f1` for i in $func do nawk -v... (4 Replies)
Discussion started by: Sumanthsv
4 Replies

3. Shell Programming and Scripting

Will files, creaetd in one function of the same script will be recognized in another function?

Dear All. I have a script, which process files one by one. In the script I have two functions. one sftp files to different server the other from existing file create file with different name. My question is: Will sftp function recognize files names , which are created in another... (1 Reply)
Discussion started by: digioleg54
1 Replies

4. UNIX for Dummies Questions & Answers

Email ids trucated in Mailx function

I wanted to send email to list of people using mailx in unix. I am getting the emailds from a oracle table and getting the ids in a variable. Shell script is shown below: ----------------------------------------------------------------------- filename=testdata921 export filename... (5 Replies)
Discussion started by: sasi02
5 Replies

5. Shell Programming and Scripting

Error related to mailx function

Hi All, I have used the following syntax for sending email. "mailx -s "process not running" userid@domain.com " I am getting below error. " mailx: not found " Can anoy one please give the reason for this error. I am using REDHAT server. (2 Replies)
Discussion started by: suresh.gunti
2 Replies

6. Shell Programming and Scripting

SHELL SCRIPT Function Calling Another Function Please Help...

This is my function which is creating three variables based on counter & writing these variable to database by calling another function writeRecord but only one record is getting wrote in DB.... Please advise ASAP...:confused: function InsertFtg { FTGSTR="" echo "Saurabh is GREAT $#" let... (2 Replies)
Discussion started by: omkar.sonawane
2 Replies

7. Shell Programming and Scripting

Mailx: How to send a attachment using mailx command

Hi All, Can anyone please provide the command for sending an mail with attachment using mailx command. Thanks in Advance :) Regards, Siram. (3 Replies)
Discussion started by: Sriram.Vedula53
3 Replies

8. Shell Programming and Scripting

Return a value from called function to the calling function

I have two scripts. script1.sh looks -------------------------------- #!/bin/bash display() { echo "Welcome to Unix" } display ----------------------------- Script2.sh #!/bin/bash sh script1.sh //simply calling script1.sh ------------------------------ (1 Reply)
Discussion started by: mvictorvijayan
1 Replies

9. Shell Programming and Scripting

Passing global variable to a function which is called by another function

Hi , I have three funcions f1, f2 and f3 . f1 calls f2 and f2 calls f3 . I have a global variable "period" which i want to pass to f3 . Can i pass the variable directly in the definition of f3 ? Pls help . sars (4 Replies)
Discussion started by: sars
4 Replies

10. UNIX for Dummies Questions & Answers

mailx error message : mailx: NUL changed to @

If I use the "Mail" link instead of the "mail" link to ../mailx I get this error. Mail so-n-so @whatever.com mailx: NUL changed to @ Unknown command: "postmaster" The email still goes through but i get the error. If I use "mail" it goes thru without the error. Any ideas?? (2 Replies)
Discussion started by: BG_JrAdmin
2 Replies
Login or Register to Ask a Question