Sponsored Content
Top Forums UNIX for Advanced & Expert Users concurrency issue while Accessing Mail Box from shell script Post 302108253 by Perderabo on Sunday 25th of February 2007 12:49:08 PM
Old 02-25-2007
You don't say what os you're using, what language you're trying to use, or give much info on how the script is used (always for one particular user? for everyone on the system?). I will assume that you're using Solaris 10, trying to program in ksh, and running the script for every user on the box. If these assumptions are wrong, your mileage may vary.

There are several problems with your code. I see the comment where you claim the mailfile is always blank. But the code which is present to handle a non-blank mailfile is guaranteed to fail and should be removed. Leaving broken remnants of old code in a script is asking for trouble down the road. I have never seen syntax like:
while ( [ $mailstat -eq 0 ] )
I think that may be legal. It might even be useful with a much more complex test. The normal syntax is:
while [ $mailstat -eq 0 ]
Your parentheses are demanding that the test be preformed in a subshell. The exit code of the subshell should be the exit code of the [ command in this case. But you are starting an extra process for no good reason. More to the point, the loop is not useful. You should be doing:
1) check for existence of mail, exit if none
2) save any mail present

There is a concurrency issue here... mail may be present during step 1 and absent during step 2. Step 2 needs to accept that...it is not an error. Step 2 should be a one shot deal, not a loop. If new mail arrives immediately after the save, your script will get to it the next time it is launched. You are looping, probably not to handle newly arrived mail, but rather to handle one message at a time. That is not efficient. "save * filename" will grab all of the mail at once. It is more efficient and eliminates most of your problem.

mailx initializes itself by processing a system-wide startup script. Then it processes a user specific startup script. A -n will inhibit the former but not the latter. The mailx man page says the save command "Save the specified messages in the given file. The file is created if it does not exist. The file defaults to mbox. The message is deleted from the mailbox when mailx terminates unless keepsave is set (see also Internal Variables and the exit and quit commands). If a user has a .mailrc that sets keepsave, your script will not empty his mailbox. This is my best guess as to why you have your current problem and I don't know what to suggest. I don't think you should override a user's wishes without consulting with the user in question.
 

10 More Discussions You Might Find Interesting

1. HP-UX

Accessing databases using sql*plus on HP box

When I try to connect to databse from HP box using the following command sqlplus <username>@<databasename> I get this error message: ksh: <database name> : not found I can connect to the database outside the UNIX box using sqlplus though. Looks like the problem is the way HP Unix is... (4 Replies)
Discussion started by: dtonse
4 Replies

2. Shell Programming and Scripting

Box A's perl script calling box B's shell script

Hi all, i have a perl script one server. I am running a cronjob to execute my perl script. #! /usr/bin/perl ... ... ... #call a shell script on another server How can i accomplish #? Do i have to issue a system (" ssh -l username server | shellscript.sh") in my shell script? or is there a... (1 Reply)
Discussion started by: new2ss
1 Replies

3. Shell Programming and Scripting

Accessing the parameters of a shell script

Hi, I have one situation. I am developing a shell script to which parameters will be passed from a Web based User Interface using some Business Process(BP).There are some 6 parameters for which user will enter the values in UI. These values will be passed to script by BP in the form -... (2 Replies)
Discussion started by: The Observer
2 Replies

4. Shell Programming and Scripting

Accessing aliases within a shell script

I am not able to access the aliases in my environment within a Python script. If I pass the alias to os.system(), I get a message saying "sh: x: not found". I've tried sourcing my .bashrc file in the script, but this does not work. I would perfer not to source my or any rc file because this... (9 Replies)
Discussion started by: cooldude
9 Replies

5. UNIX for Dummies Questions & Answers

unix script to check if rsh to box and send status mail

rshstatus=`rsh -n lilo /db/p2/oracle/names9208/restart_names.sh` if $rshstatus <>0 then errstatus=1 mailx -s "xirsol8dr" ordba@xxx.com >> $log_dr else if errstatus=0 echo "status to xirsol8dr successful" can anyone provide if this is t he correct way to do this or is there a better way? (1 Reply)
Discussion started by: bpm12
1 Replies

6. Shell Programming and Scripting

ftp file starting with particular name on Windows box to Unix box using shell script

Hello all ! I'm trying to write a shell script (bash) to ftp a file starting with particular name like "Latest_" that is present on a Windows box to UNIX server. Basically I want to set this script in the cron so that daily the new build that is posted on the Windows box can be downloaded to the... (2 Replies)
Discussion started by: vijayb4u83
2 Replies

7. Web Development

Accessing a Perl CGI script, security issue

Hi Everybody, I was wondering if it was possible for someone to gain access to my Perl CGI scripts before they are interpreted by Perl (mod_perl on apache2) i.e. getting a hold of my raw scripts and not the html output? Let's say I use the DBI module where I have the hostname, user and... (2 Replies)
Discussion started by: z1dane
2 Replies

8. Solaris

Mail system Configuration issue on UNIX box

Hi, I wanted to configure a mail system on my UNIX box. For that I read a document Sun Internet Mail Server 3.5 Advanced Installation Guide: Contents which is actually quite useful document but I am not sure from where can I bring patch? Is this patch will come in any CD form which I need to run... (1 Reply)
Discussion started by: Dhruvak
1 Replies

9. Shell Programming and Scripting

Clean up UNIX mail box using script

Hi, I would like to clean up by unix mail mail box thru some script command.. I do know how to delete from mail box ... e.g. $ mail ? d* ? quit But I need to clean up thru some command which I can use in my script before sending any email.. Thanks in advance! (1 Reply)
Discussion started by: pareshkp
1 Replies

10. Open Source

Shell script file movement to a Mail Box server using ftp commands

Hi All, I have a current Process that runs "windows script " for the file movement that needs to changed to a "DataStage Process (Using shell script )" Source :Text file is getting generated as part of Datastage Jobs processes and resides in a shared drive (Unix server) Target :ftp... (2 Replies)
Discussion started by: developer.dwh9
2 Replies
mail(1) 						      General Commands Manual							   mail(1)

NAME
mail, rmail - send mail to users or read mail SYNOPSIS
file] person ... person ... Remarks: See mailx(1) and elm(1) for an enhanced user mail interface. DESCRIPTION
The command, when used without arguments, prints the user's mail, message-by-message, in last-in, first-out order. For each message, prints a prompt and reads a line from the standard input to determine the disposition of the message. Commands that automatically proceed to the next message exit from if already on the last message. Commands supports the following commands: <new-line> Go on to next message. Exit if already on last message. Same as <new-line>. Same as <new-line>. Delete message and go on to next message. Print message again. Go back to previous message. Save message in the named files (default is mark the message for deletion from the user's mailfile, and proceed to next message. Same as Save message without its header (the ``From ...'' line), in the named files (default is mark the message for deletion, and go on to next message. Mail the message to each named person, mark the message for deletion, and go on to next message. Put undeleted mail back in the and stop. Same as Abort. Leave original unchanged and stop. Escape to the command interpreter and execute command. Print a command summary. Same as Command-Line Options The following command-line options alter printing of the mail: Cause messages to be printed in first-in, first-out order. Suppresses printing of mail and returns the exit value: 0 = Mail present 1 = No mail 2 = Other error Prints all mail without prompting for disposition. Causes to terminate if an interrupt is received. Normally an interrupt only causes the termination of the printing of the current message. Same as Causes to use file (for example, instead of the default mailfile. Causes the outbound message to be preceded by each person the mail is sent to. A person is usually a user name recognized by (see login(1)). If a person being sent mail is not recognized, or if is interrupted during input, the file will be saved to allow editing and resending. Note that is regarded as a temporary file in that it is recreated every time needed, erasing the previous contents of Causes to deliver mail directly. This isolates from making routing decisions, and allows it to be used as a local delivery agent. Typically this option is used by auto-routing facilities when they deliver mail locally. When persons are named, takes the standard input up to an end-of-file (or up to a line consisting of just a and adds it to each person's mailfile. The message is preceded by the sender's name and a postmark. To denote a recipient on a remote system, prefix person by the system name and exclamation mark (see uucp(1)). Everything after the first exclamation mark in person is interpreted by the remote system. In particular, if person contains additional exclamation marks, it can denote a sequence of machines through which the message is to be sent on the way to its ultimate destination. For example, specifying as a recipient's name causes the message to be sent to user on system System then interprets that destination as a request to send the message to user on system This might be useful, for instance, if the sending system can access system but not system does not use if the remote system is the local system name (i.e., localsystem!user). The can be manipulated in two ways to alter the function of The other permissions of the file can be read-write, read-only, or neither read nor write to allow different levels of privacy. If changed to other than the default, the file is preserved, even when empty, to perpetu- ate the desired permissions. The file can also contain the first line: person which causes all mail sent to the owner of the to be forwarded to person. This is especially useful for forwarding all of a person's mail to a given machine in a multiple-machine environment. In order for forwarding to work properly the should have "mail" as group ID, and the group permission should be read-write. only permits the sending of mail. uses as a security precaution. When a user logs in, the command can be used to detect the presence of mail, if any, and so indicate. When terminating, produces a notifi- cation message if new mail arrived while was running. EXTERNAL INFLUENCES
Environment Variables determines the format and contents of the displayed date and time strings. If is not specified in the environment or is set to the empty string, the value of is used as a default for each unspecified or empty vari- able. If is not specified or is set to the empty string, a default of "C" (see lang(5)) is used instead of If any internationalization variable contains an invalid setting, behaves as if all internationalization variables are set to "C". See environ(5). When set, the environment variable specifies a directory to be used for temporary files, overriding the default directory International Code Set Support Between HP-UX systems, single- and multi-byte character code sets are supported within mail text. Headers are restricted to characters from the 7-bit USASCII code set (see ascii(5)). WARNINGS
Conditions sometimes result in a failure to remove a lock file. After an interrupt, the next message may not be printed. To force printing, type a Lines that look like postmarks in the message (that is, ``From ...'') are preceded by treats a line consisting solely of a dot as the end of the message, except when the command is used. The maximum allowable line length in mail messages is 8 times that of bytes as defined in If line length exceeds this limit, truncates the line starting at beginning-of-line, and uses only the trailing 8 * characters. Using two separate mail programs to access the same mail file simultaneously (usually inadvertently from two separate windows) can cause unpredictable results. Some sites that have programs that adhere strictly to RFC-822 will fail to deliver a message if any of the recipient fields below is miss- ing. You can add the RFC-822 commands into the mail program buffer/editor. For instance: FILES
Lock for mail directory Unmailable text Temporary file Variable containing path name of Saved mail To identify sender and locate persons Directory for incoming mail (mode group ID Incoming mail for user; that is, the mailfile (mode group ID SEE ALSO
login(1), mailx(1), uucp(1), write(1). STANDARDS CONFORMANCE
mail(1)
All times are GMT -4. The time now is 06:20 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy