Re: redirect for stdout in ${command_line}
- From: "steven_nospam at Yahoo! Canada" <steven_nospam@xxxxxxxx>
- Date: 9 Aug 2006 07:45:53 -0700
Robin wrote:
Here is a piece of what I am trying to execute...
#
cmd_1='nohup /fnsw/local/bin/NLS_Archive -f
/tmp/ssar_conv_cmds/surface'
cmd_2='.txt '
cmd_3=' /tmp/ssar_conv_cmds/surface'
cmd_4='.out &'
command_line=$cmd_1$surf_in$cmd_2\ > \$cmd_3$surf_in$cmd_4
${command_line}
#
Hi Robin,
I did a similar test and I see what you are probably running into. Here
is what I tried:
# START OF SCRIPT #
#!/bin/ksh
#
echo "Enter surf_in value: \c"
read surf_in
command_line="nohup /bin/ls /dev/$surf_in* 1>/tmp/devices.$surf_in 2>&1
&"
echo "Command line is shown below:"
echo "${command_line}"
${command_line}
sleep 3
echo "Results:"
ls -l /tmp/devices.$surf_in
cat /tmp/devices.$surf_in
# END OF SCRIPT#
This script was supposed to simulate what you are doing with the
NLS_Archive. I would accept a variable and build a command line while
inserting the variable at certain points. My script was simply going to
list device names in the /dev directory.
For surf_in, I entered "tty" as what I wanted to search for. When I ran
it I got the following:
Enter surf_in value: tty
Command line is shown below:
nohup /bin/ls /dev/tty* 1>/tmp/devices.tty 2>&1 &
Sending nohup output to nohup.out.
Results:
ls: 0653-341 The file /tmp/devices.tty does not exist.
cat: 0652-050 Cannot open /tmp/devices.tty.
When I checked the nohup.out that gets created, here are the contents:
ls: 0653-341 The file > does not exist.
ls: 0653-341 The file /tmp/devices.tty does not exist.
ls: 0653-341 The file 2>&1 does not exist.
ls: 0653-341 The file & does not exist.
/dev/tty
/dev/tty0
/dev/tty1
/dev/tty2
/dev/tty3
What it appears to be doing is treating the redirection and even & at
the end as a parameter passed to the ls command instead of as the
redirection it was supposed to be.
I believe that you can prevent that from happening by writing the
command line you are trying to execute to a temporary file and then
nohup'ing that file. Of course, that means that you will have temp
files to clean up afterward. Here is how I got it to work:
# START OF SCRIPT #
#!/bin/ksh
#
echo "Enter surf_in value: \c"
read surf_in
echo "/bin/ls /dev/$surf_in* 1>/tmp/devices.$surf_in 2>&1" >
/tmp/robin.$$
echo "/bin/rm /tmp/robin.$$" >> /tmp/robin.$$
echo "Temp file contents are shown below:"
cat /tmp/robin.$$
chmod a+x /tmp/robin.$$
nohup /tmp/robin.$$ &
sleep 3
echo "Results:"
ls -l /tmp/devices.$surf_in /tmp/robin.$$
cat /tmp/devices.$surf_in
# END OF SCRIPT#
And the results were:
Enter surf_in value: tty
Temp file contents are shown below:
/bin/ls /dev/tty* 1>/tmp/devices.tty 2>&1
/bin/rm /tmp/robin.85604
Sending nohup output to nohup.out.
Results:
ls: 0653-341 The file /tmp/robin.85604 does not exist.
-rw-rw-r-- 1 root system 236 Aug 09 10:49
/tmp/devices.tty
/dev/tty
/dev/tty0
/dev/tty1
/dev/tty2
/dev/tty3
/dev/tty3p
/dev/ttyp0
/dev/ttyp1
/dev/ttyp2
/dev/ttyp3
/dev/ttyp4
/dev/ttyp5
/dev/ttyp6
/dev/ttyp7
/dev/ttyp8
/dev/ttyp9
/dev/ttypa
/dev/ttypb
/dev/ttypc
/dev/ttypd
/dev/ttype
/dev/ttypf
The error from the final ls command shows me that my temp file in fact
did get deleted by the rm command within that temp script. So it cleans
up after itself.
HTH
Steve
.
- Follow-Ups:
- Re: redirect for stdout in ${command_line}
- From: Robin
- Re: redirect for stdout in ${command_line}
- References:
- redirect for stdout in ${command_line}
- From: Robin
- Re: redirect for stdout in ${command_line}
- From: steven_nospam at Yahoo! Canada
- Re: redirect for stdout in ${command_line}
- From: Robin
- redirect for stdout in ${command_line}
- Prev by Date: Re: Newbie Scripting Variable Question
- Next by Date: Re: Howto hot-add a new PV into an existing concurrent mounted VG
- Previous by thread: Re: redirect for stdout in ${command_line}
- Next by thread: Re: redirect for stdout in ${command_line}
- Index(es):
Relevant Pages
|