Process substitution


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Process substitution
# 1  
Old 03-01-2010
Process substitution

Just playing around with process substitution.
Hoping maybe someone can give me some help on what I'm doing wrong.
When this script is run, "Null message body; hope that's ok" is returned and the script hangs.
I can't seem to work out what I'm doing wrong.

Here is the script:

Code:
#!/bin/bash
#
# test script for piping date stamps onto stderr then to mail
#
#
EMAILLOGS="true"
EMAILTO="email@email.com"
SUBJECT="testing"
ERRORLOG="/tmp/error.log"

##Where are we sending stderr..
if [ $EMAILLOGS == true ]; then
        ##This is the process substitution: Read in sterr lines,
        ##echo back timstamp+line, then pipe that to mail.
      exec 2> >(while read line; do echo -e "$(date):${line}\n"; done | /usr/bin/mail -s "$SUBJECT" "$EMAILTO")
else
      exec 2>>$ERRORLOG
fi

echo -e "Testing Error\n" &>2
echo -e "Testing STDERR" &>2
exit



---------- Post updated at 12:45 PM ---------- Previous update was at 12:34 PM ----------

ah geez. brain fart.


Code:
echo -e "Testing Error\n" &>2
echo -e "Testing STDERR" &>2

Supposed to be >&2.


BLAH.
Sorry.

---------- Post updated at 01:01 PM ---------- Previous update was at 12:45 PM ----------

Well, I guess while I'm here.

Anyone have an idea to say if there are no errors (if message body is null) then do not send?

I've found this with mail:

mail [-EiInv] [-s subject] [-c cc-addr] [-b bcc-addr] [-F] to-addr ...
[-sendmail-option ...]

-E Do not send messages with an empty body. This is useful for pip-
ing errors from cron(8) scripts.

But it seems to fail with "Unknown command: -s".

New code would be like this:

Code:
exec 2> >(while read line; do echo -e "$(date):${line}\n"; done|/usr/bin/mail -E -s "$SUBJECT" "$EMAILTO")

# 2  
Old 03-01-2010
Quote:
Originally Posted by mandelbrot333
But it seems to fail with "Unknown command: -s".

Not all versions of mail have an -s option.
# 3  
Old 03-01-2010
Noted.

However, I can run the command without the -E option and it will parse correctly.

In the man file I quoted, the structure seems to support both -E and -s in the same line.


Thanks for the input.
# 4  
Old 03-01-2010
Further to cfajohnson, what Operating System do you have?

What do you type at the command prompt?

What output did you expect?

What output did you receive?

Last edited by methyl; 03-01-2010 at 09:47 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Command to get exact tomcat process I am running ignoring other java process

Team, I have multiple batchjobs running in VM, if I do ps -ef |grep java or tomcat I am getting multiple process list. How do I get my exact tomcat process running and that is unique? via shell script? (4 Replies)
Discussion started by: Ghanshyam Ratho
4 Replies

2. Shell Programming and Scripting

Monitoring processes in parallel and process log file after process exits

I am writing a script to kick off a process to gather logs on multiple nodes in parallel using "&". These processes create individual log files. Which I would like to filter and convert in CSV format after they are complete. I am facing following issues: 1. Monitor all Processes parallelly.... (5 Replies)
Discussion started by: shunya
5 Replies

3. Shell Programming and Scripting

Problem with process substitution

i have tried process substitution, but run in some problems. this works: samtools view -h $SAMdir/$b.bam | htseq-count -m union -s no -q -t exon -i gene_id - $gtf > $b.count & but this not: htseq-count -m union -s no -q -t exon -i gene_id <(samtools view -h $SAMdir/$b.bam) $gtf >... (7 Replies)
Discussion started by: dietmar13
7 Replies

4. Shell Programming and Scripting

Cannot make pipe for process substitution: Too many open files

Hi, I've came across an issue with a script I've been writing to check DHCP addresses on an Solaris system, the script has been running reasonably well, until it hit the following problem: ./sub_mon_v2: redirection error: cannot duplicate fd: Too many open files ./sub_mon_v2: cannot make... (3 Replies)
Discussion started by: CiCa
3 Replies

5. UNIX for Dummies Questions & Answers

Process Substitution Question?

Hello to all. I'm new to this forum, so please go easy on me. =) I am working on a script to send two e-mail attachments in a single e-mail, and am running into a little bit of an issue when using process substitution. I am using the following: cat <(uuencode $1 <(basename $1)) <(uuencode... (5 Replies)
Discussion started by: rommager
5 Replies

6. Shell Programming and Scripting

script to monitor the process system when a process from user takes longer than 15 min run.

get email notification from from system when a process from XXXX user takes longer than 15 min run.Let me know the time estimation for the same. hi ,any one please tell me , how to write a script to get email notification from system when a process from as mentioned above a xxxx user takes... (1 Reply)
Discussion started by: kirankrishna3
1 Replies

7. Shell Programming and Scripting

Shell Script to Kill Process(number of process) Unix/Solaris

Hi Experts, we do have a shell script for Unix Solaris, which will kill all the process manullay, it used to work in my previous env, but now it is throwing this error.. could some one please help me to resolve it This is how we execute the script (and this is the requirement) ... (2 Replies)
Discussion started by: jonnyvic
2 Replies

8. Shell Programming and Scripting

Can process substitution be used as an input file to another program?

Hey, I was trying to figure out how to launch a program from the command line, and it works if you pass it a config file. I was thinking about writing a script to dynamically create the config file and pass it to the command using something like command substitution (so I don't actually have to... (3 Replies)
Discussion started by: bj0
3 Replies

9. Shell Programming and Scripting

script to monitor process running on server and posting a mail if any process is dead

Hello all, I would be happy if any one could help me with a shell script that would determine all the processes running on a Unix server and post a mail if any of the process is not running or aborted. Thanks in advance Regards, pradeep kulkarni. :mad: (13 Replies)
Discussion started by: pradeepmacha
13 Replies

10. Shell Programming and Scripting

Difference between "Command substitution" and "Process substitution"

Hi, What is the actual difference between these two? Why the following code works for process substitution and fails for command substitution? while IFS= read -r line; do echo $line; done < <(cat file)executes successfully and display the contents of the file But, while IFS='\n' read -r... (3 Replies)
Discussion started by: royalibrahim
3 Replies
Login or Register to Ask a Question