AIX .ksh script freezes when using the mail -s command

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting AIX .ksh script freezes when using the mail -s command
# 1  
Old 06-15-2011
AIX .ksh script freezes when using the mail -s command


I am trying to send an email when a .KSH script is run on an AIX Machine.

This email will only include a subject line that is made up of variables from within the script, and is as follows:

CURRENT_DATE=`date +%Y%m%d` 
block ()
    print "################################################"
  [ -e "$1" ] && numfiles=$# || numfiles=0
for dir in /transfer/archive/$CURRENT_DATE
  filecount "$dir"/*
  if [ $numfiles -gt 0 ]
    mail -s "%d files found in %s\n" "$numfiles" "$dir" $ADMIN
    printf "%d files found in %s\n" "$numfiles" "$dir"

Whenever I attempt to run this script it freezes at the following point:
    mail -s "%d files found in %s\n" "$numfiles" "$dir" $ADMIN

I have run the printf command by itself, and this works as expected. I know that the mail function is working correctly as I have another script that this works on.

Could anyone offer some advice on the problem?
# 2  
Old 06-15-2011
Your syntax for the mail command would appear to be wrong. man mail for more information.
# 3  
Old 06-16-2011
Thanks fpmurphy

I have looked through the man for mail, and have attempted to modify the command to the following:

 mail -s "%d files found in %s\n" "$numfiles" "$dir" -c $ADMIN

I believe that this is correct now, but it is still failing to send and I have to cancel the command with a Ctrl + c.

Being completely new to (and apparently useless with) UNIX, I can not see what I am doing wrong. Do you have any other suggestions?
# 4  
Old 06-22-2011
I am still having issues with this. Can anyone suggest where I am going wrong?
# 5  
Old 06-24-2011
Please mention what Operating System and version you have and what Shell you are using.

Most versions of "mail" read the contents of the mail body from standard input. Your script is probably waiting for someone to type. Though I can't vouch for your syntax for "mail" (particularly the %d and %s bit), providing "mail" with some input usually cures the "hang" issue:

echo "" | mail -s "%d files found in %s\n" "$numfiles" "$dir" $ADMIN

echo "Message body" | mail -s "%d files found in %s\n" "$numfiles" "$dir" $ADMIN

Just for interest, you'd probably have to type the end-of-file control code (usually ctrl/D) to get out of the original hang.

On many systems the command would be "mailx" not "mail".
I guess that the %d and %s are misplaced "printf" syntax.

Last edited by methyl; 06-24-2011 at 01:25 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

[Solved] AIX ksh script -d <- what does it mean?

I'm looking at a line in a script: && DRROOT="/dir1" || DRROOT="/dir2" I'm trying to understand it. Is there a "-d" command and is it seeing if /dir1 exists and, if so, set an environment variable named DRROOT to "/dir1", else set DRROOT to "/dir2" ? Thanks, -dog ---------- Post... (0 Replies)
Discussion started by: landog
0 Replies

2. Shell Programming and Scripting

AIX-ksh script ends unexpectedly

Hi, I have a ksh script running on AIX 5.3 which has sometimes a bizarre behaviour. The script runs a child script like follow. trap 'rm -f /tmp/res.log;exit 0' 2 15 > /tmp/res.log 2>&1 echo " is terminated" next instructions... rm -f /tmp/res.log ... (12 Replies)
Discussion started by: rivalgro
12 Replies

3. Shell Programming and Scripting

Aix .ksh for loop script.

Hi, I'm trying to write a for loop to run through a list of servers and for each server copy a file to a backup file. But I can't seem to get it to run through my server list. It work for individual servers, please see below. #!/bin/ksh SSH_USERID=khcuser webservers="server1 server2" ... (2 Replies)
Discussion started by: elmesy
2 Replies

4. Shell Programming and Scripting

Help extracting process name from ps command AIX using KSH

Hi All, Newbie script writer and I need some help! I'm grepping ps - eno THREAD >outfile This gives me loads of stuff including the proc names which appear at the end of the line. They're all 10 characters long so what I want to do is cut them (and only them) from the file and put it in... (7 Replies)
Discussion started by: Grueben
7 Replies

5. Shell Programming and Scripting

Calling SQL script from ksh job and send mail on some error.

Hi, I am trying to call sql script from ksh job with parameters.The parameters passed from ksh job will be used in SELECT query in sql file to SPOOL the data in extract file.My questions are: 1) How to call a sql script from ksh job with parameters? 2) How to use the parameter in sql file to... (1 Reply)
Discussion started by: anil029
1 Replies

6. UNIX for Dummies Questions & Answers

AIX: mail command & server

Hi, I have to change the mail server, but I could not find the file where it is written in. I use the following command: </> echo krneki | mail -v -s "New report" receiver@our.comp Server name ("skala") can be seen in a terminal output .... receiver@our.comp ... Connecting to... (0 Replies)
Discussion started by: frajer
0 Replies

7. Shell Programming and Scripting

Mail cleanup from ksh script, keeping 50 most recent msgs

I found some posts describing how to completely clean out a mailbox in Unix/Linux. But I want to keep the 50 most recent messages. Any ideas out there? Thanks! (3 Replies)
Discussion started by: OPTIMUS_prime
3 Replies

8. AIX

How to mail the output of a command in AIX

Hi, I have mastered how to mail to Windows in AIX. Can anyone tell me how I would mail the output command df -g to an email? I want to set a job in cron to mail df -g as the contents of a mail. Any ideas? Thanks John (4 Replies)
Discussion started by: jfd7000
4 Replies

9. UNIX for Dummies Questions & Answers

command completion in .sh or .ksh in AIX environment

How do you user command completion in .sh or .ksh in AIX environment? I know you can do it by hitting <esc><esc> in bash, but how do you do it in bourne or korn shell in AIX 5.3 environment? Thanks in advance. (1 Reply)
Discussion started by: pdtak
1 Replies

10. AIX

AIX server freezes on bootup

Issue: AIX server freezes on bootup. Server AIX ver When the AIX server reboots it negotiates NIS. During startup of NFS, customer gets one or more of the following error messages: 0513-056 Timeout waiting for command response. If you specified a foreign host, see the /etc/inittab file... (1 Reply)
Discussion started by: srzaman1
1 Replies
Login or Register to Ask a Question