Sponsored Content
Top Forums Shell Programming and Scripting Can I pipe stderr to another process Post 302414999 by alister on Wednesday 21st of April 2010 01:24:58 PM
Old 04-21-2010
I would just use sh syntax and source it.

Config file:
Code:
$ cat config
PATHS_TO_WATCH='/home/ /var/www/'
LIMITED_TRANSFER_RATE=800

Read config:
Code:
$ . ./config
$ echo "$PATHS_TO_WATCH"
/home/ /var/www/
$ echo "$LIMITED_TRANSFER_RATE"
800


If you want the script to abort if there are any invalid variable names in the config (if you try the following, with an invalid variable name in config, in your current shell, it will *poof* disappear Smilie, so make sure to do it in a subshell):
Code:
set -e
. config_file
set +e

Or, you could leave "set -e" on, if you like (it causes the shell to terminate when a command fails, with certain exceptions regarding and-or lists and conditionals ... read your shell's 'set' documentation for more info).

As to spaces in a pathname, I don't see how you can detect them since you are using spaces to delimit each path. How is the code to know if the space is embedded in a path or meant to separate one path from another? To be absolutely certain of whether a character is in a path or a delimiter, you would need to select a delimiter that cannot occur in a UNIX path. There is only one such character, the null byte, and it's notoriously difficult to work with in most shells. Perhaps simply checking the validity of each path is sufficient.

Assuming that the config file was sourced as in my example above (using the dot command):
Code:
for p in $PATHS_TO_WATCH; do
    if [ ! -d $p ]; then
        echo $0: $p: bad path 1>&2
        exit 1
    fi
done

If an invalid path is encountered, a message (including the script's name and the offending path) is printed to standard error and an exit status of 1 is returned.

Cheers,
Alister
 

10 More Discussions You Might Find Interesting

1. Programming

stderr in background process

Herez the question, In a process which writes into file FILE1 with descriptor fHandler1 and it is run as a background process where would statements be directed when stderr descriptor is used. fprintf(stderr,"some message\n"); assume that session from which it is run is terminated and... (3 Replies)
Discussion started by: matrixmadhan
3 Replies

2. Programming

sychronize process using pipe?

can pipe sychronize thread or process? because I'm trying to create 5 thread or process that can take an integer value and display it. each time a thread display the value, it has to be decrement it by 1 until the value has reach 0. The problem that I'm having is how can that integer value be... (1 Reply)
Discussion started by: saipkjai
1 Replies

3. UNIX for Advanced & Expert Users

AIX 5.3 - There is no process to read data written to a pipe

I have the following code which works on AIX 4.3 but fails at times on AIX 5.3 with: cat: 0652-054 cannot write to output. There is no process to read data written to a pipe. validator="${validator_exe} ${validator_parms}" cmd_line="${CAT} ${data_file} | ${validator}... (6 Replies)
Discussion started by: vigsgb
6 Replies

4. Linux

Can background process access to stdout,stderr

Hi folks :) Can deamonized process access to stderr, stdout? I 'm trying to display error_num/return value of a function run() in stderr using fprintf(stderr, "function run() returns = %d", ret_val); run() is called after deamonizing the process. (1 Reply)
Discussion started by: katty
1 Replies

5. Programming

Two way Pipe Process

Hi.. I am hoping someone could assist me with the pipe program I wrote below. I want to have communication from parent to child and then child to parent.. Is my logic right? int p,p1; pipe(p); pipe(p1); pid_t pid = fork(); if(pid == 0) { close(p); close(p1); dup2(p,0);... (1 Reply)
Discussion started by: therome
1 Replies

6. AIX

Tape drive problem - no process to read data written to a pipe

Hi Everyone, The machine I'm working on is an AIX 5.3 LPAR running on a P650. oslevel -r shows 5300-08. I'm trying to take a backup to a SCSI tape drive, which has been working up until this point. I know of nothing that has changed recently to cause this problem. But when I try to take a... (0 Replies)
Discussion started by: need2bageek
0 Replies

7. UNIX for Dummies Questions & Answers

No process to read data written to a pipe on AIX

We use SAP application cluster on AIX. Communication between 2 of its instances is failing randomly with the following error: java.net.SocketException: There is no process to read data written to a pipe. The above error causes a cluster restart if an important communication fails. Can... (0 Replies)
Discussion started by: RoshniMehta
0 Replies

8. Programming

Communicate with multiple process using named pipe

how to read and write on pipes to communicate with each other? (5 Replies)
Discussion started by: nimesh
5 Replies

9. 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

10. Shell Programming and Scripting

Using pipe command between process and concatenate

Dear all, I use a pipe command to assign a variable: $ v_LstStdCdhId=$(cat Bteq_Xport_GetLstStdViewToBuild__1274.txt | grep 'CD/39/AT/CDH_BV_ODS'|cut -d"/" -f1) $ echo "${v_LstStdCdhId}" 43 49 My aim is to concatenate for each line of the variable v_LstStdCdhId the character "/" in... (3 Replies)
Discussion started by: dae
3 Replies
unbound-checkconf(8)						  unbound 1.4.17					      unbound-checkconf(8)

NAME
unbound-checkconf - Check unbound configuration file for errors. SYNOPSIS
unbound-checkconf [-h] [-o option] [cfgfile] DESCRIPTION
Unbound-checkconf checks the configuration file for the unbound(8) DNS resolver for syntax and other errors. The config file syntax is described in unbound.conf(5). The available options are: -h Show the version and commandline option help. -o option If given, after checking the config file the value of this option is printed to stdout. For "" (disabled) options an empty line is printed. cfgfile The config file to read with settings for unbound. It is checked. If omitted, the config file at the default location is checked. EXIT CODE
The unbound-checkconf program exits with status code 1 on error, 0 for a correct config file. FILES
/etc/unbound/unbound.conf unbound configuration file. SEE ALSO
unbound.conf(5), unbound(8). NLnet Labs May 24, 2012 unbound-checkconf(8)
All times are GMT -4. The time now is 03:48 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy