Hello,
I am running a shell script on AIX 6.1. The script calls ksh to run. ksh is also the login shell for the account under which I am running this script, but for convenience I always change to the bash shell via "exec bash" after I "su" to the account.
The script redirects stdout and stderr to a file via exec, then builds a report via a bunch of "echo" and "awk" commands, and then finally reconnects to stdout and stderr and emails the report:
I run into difficulties when I try to run this script (archcmp.sh) in the background via "./archcmp.sh &" . I can do so, and the script does run, but as soon as I type anything at the terminal (like an 'ls -l' on the report file in /tmp) the script stops and I cannot resume it. I see the same behavior whether or not I switch from the ksh login shell to bash before running the report:
It will never write anything more to the report file.
I find that I can get my program to behave the way that it should (or, at least, the way that I would like it to) if I change I redirecting 'exec' command to redirect all three of the standard file handles, as follows:
But this should be unnecessary, shouldn't it? When I place a command into the background via '<commandname> &' , it should be unconditionally dissociated from the terminal. Is this a bug in ksh? Is there some other way to get the background process to actually resume?
& doesn't mean "unconditionally dissociated from the terminal" -- anything but, really. Once it's in the background, attempting to do I/O on the std channels will suspend it. This is expected behavior.
Please be aware that
does NOT capture std output and stderr. It duplicates stderr from (the old) stdout , and then redirects stdout to $RPTF. So stderr still points to (presumably) /dev/tty (or so) and eventually prints to it.
and that
does NOT restore stdout/stderr. Actually, it doesn't do anything.
Please be aware that
does NOT capture std output and stderr. It duplicates stderr from (the old) stdout , and then redirects stdout to $RPTF. So stderr still points to (presumably) /dev/tty (or so) and eventually prints to it.
1st make redirect for stdout and 2nd redirect stderr (handler 2) to same as stdout (handler 1)
This works also but result is little surprise. Not planned.
1st set stderr same as stdout is now and 2nd redirect stdout. = stderr is same as stdout was before new setup.
Example script:
find mydir -type f -exec echo {}>aaa \; -exec echo {}>bbb \;The two paths go the the bbb file, while there should be one of them on each file. How should I do it to get it working? (2 Replies)
I have the following bash script lines in a file named test.sh.
#!/bin/bash
#
# Write Date to cron.log
#
echo "Begin SSI Load $(date +%d%b%y_%T)"
#
# Get the latest rates file for processing.
#
d=$(ls -tr /rms/data/ssi | grep -v "processed" | tail -n 1)
filename=$d
export filename... (3 Replies)
Hello All,
I am using the below script to gather various tools running by the user, we have more than 100 tools running on the server so my challenge is to redirect memory & cpu load to the file with the name of the tool.so am using the below script i am stucking how to redirect to the file... (2 Replies)
Hello everyone,I'm reading a book and there's code fragment:
exec 3>&1
ls -l 2>&1 >&3 3>&- | grep bad 3>&-
exec 3>&-
It says that the red part of that code does not close fd 3 but the green does close the fd 3.I can't understand that.....Why?Any predicate will be appreciated.:) (18 Replies)
Hi to all.
It's possible with a single line redirect to stdout and to a file a echoed string?
I need something like this:
echo "Pizza" >/tmp/file (and same time print to stout "Pizza")...
What can i do? (2 Replies)
Hello Experts,
I am on Solaris 10
Due to some limitations in one of the vendor software, I am forced to output the command to exec and then run it from there.
For example..
$(echo "/usr/bin/cp a.dat b.dat") # This works
However,
$(echo "/usr/bin/cat a.dat > c.dat") # This does not... (8 Replies)
Hi Guys,
I m new to UNIX and new to this forum. Was wondering if someone can help me understand redirection (standard input output pipeline etc)
for starters, not too sure what this would mean
who | sort > sortedfile | pr | lp
im starting to understand common commands but when throwing... (2 Replies)
Hi,
The code below works, it's a part of a bash shell script that serve to search a pattern $pattern_da_cercare in the files contained in a directory $directory_iniziale.
Now the proble is:
How can I redirect stderr to a file?
PS: so I want to redirect ALL the errors to a file.
I tryed... (9 Replies)
Here is my problem. I don't know make this redirection thing work. The output file (called output.c) looks like this
#include<stdio.h>
int main()
{
int k;
int m;
print f("%d\n", k);
printf("%d\n", m);
return 0;
}
the input file(called input.c) is this
#include<stdio.h>
int... (2 Replies)