Sponsored Content
Top Forums Shell Programming and Scripting Output redirection to exec does not work Post 302424429 by Gokul Kumar G on Tuesday 25th of May 2010 07:56:33 AM
Old 05-25-2010
Thanks for your response. From the truss output, I see the command is passed to the execve function. In both cases I see errors in the truss output.

Code:
"/usr/bin/cat /opt/CMT/partitions/partition1/a.txt > /opt/CMT/partitions/partition1/b.txt"

/opt/CMT/partitions/partition1$ls /usr/bin/cat
/usr/bin/cat

/opt/CMT/partitions/partition1$ls /opt/CMT/partitions/partition1/a.txt
/opt/CMT/partitions/partition1/a.txt

Truss
--------
28573:  getuid()                                        = 930549 [930549]
28573:  execve("/usr/bin/cat /opt/CMT/partitions/partition1/a.txt > /opt/CMT/partitions/partition1/b.txt", 0x100D02090, 0xFFFFFFFF7FFFFB08) Err#2 ENOENT
28573:  _exit(2)
8231/8:         open("/opt/CMT/partitions/partition1/logs/ContactLog.log", O_RDWR|O_APPEND|O_CREAT|O_LARGEFILE, 0666) = 17
8231/8:         fstat(17, 0xFFFFFFFF76DFEFB8)                   = 0
8231/8:         lseek(17, 0, SEEK_CUR)                          = 0


/usr/bin/cat /opt/CMT/partitions/partition1/a.txt > /opt/CMT/partitions/partition1/t.txt

Truss
-----
6320:   execve("/usr/bin/cat", 0x100E29790, 0xFFFFFFFF7FFFFB08)  argc = 4
6320:   resolvepath("/usr/lib/ld.so.1", "/lib/ld.so.1", 1023) = 12
6320:   resolvepath("/usr/bin/cat", "/usr/bin/cat", 1023) = 12
6320:   stat64("/usr/bin/cat", 0xFFBFF8B0)              = 0
6320:   open("/var/ld/ld.config", O_RDONLY)             Err#2 ENOENT
6320:   stat64("/opt/CMT/bin/libc.so.1", 0xFFBFF040) Err#2 ENOENT
6320:   stat64("/opt/oracle/product/10.2.0.3/lib/libc.so.1", 0xFFBFF040) Err#2 ENOENT
6320:   stat64("/opt/teradatav2r6/odbc64/lib/libc.so.1", 0xFFBFF040) Err#2 ENOENT
6320:   stat64("/opt/teradatav2r6/lib64/libc.so.1", 0xFFBFF040) Err#2 ENOENT
6320:   stat64("/lib/libc.so.1", 0xFFBFF040)            = 0
6320:   resolvepath("/lib/libc.so.1", "/lib/libc.so.1", 1023) = 14
6320:   open("/lib/libc.so.1", O_RDONLY)                = 3
6320:   mmap(0x00010000, 32768, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_ALIGN, 3, 0) = 0xFF3A0000
6320:   mmap(0x00010000, 1294336, PROT_NONE, MAP_PRIVATE|MAP_NORESERVE|MAP_ANON|MAP_ALIGN, -1, 0) = 0xFF200000
6320:   mmap(0xFF200000, 1237333, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_FIXED|MAP_TEXT, 3, 0) = 0xFF200000
6320:   mmap(0xFF330000, 35645, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_PRIVATE|MAP_FIXED|MAP_INITDATA, 3, 1245184) =
6320:   mmap(0xFF33A000, 1416, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_PRIVATE|MAP_FIXED|MAP_ANON, -1, 0) = 0xFF33A00
6320:   memcntl(0xFF200000, 145120, MC_ADVISE, MADV_WILLNEED, 0, 0) = 0
6320:   close(3)                                        = 0
6320:   mmap(0x00010000, 24576, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_PRIVATE|MAP_ANON|MAP_ALIGN, -1, 0) = 0xFF3900
6320:   munmap(0xFF3A0000, 32768)                       = 0
6320:   getcontext(0xFFBFF720)
6320:   getrlimit(RLIMIT_STACK, 0xFFBFF700)             = 0
6320:   getpid()                                        = 6320 [867]
6320:   setustack(0xFF392A88)
6320:   mmap(0x00000000, 8192, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_PRIVATE|MAP_ANON, -1, 0) = 0xFF3F0000
6320:   brk(0x0002A600)                                 = 0
6320:   brk(0x0002C600)                                 = 0
6320:   stat64("/platform/SUNW,Sun-Fire-15000/lib/libc_psr.so.1", 0xFFBFE670) = 0
6320:   resolvepath("/platform/SUNW,Sun-Fire-15000/lib/libc_psr.so.1", "/platform/sun4u-us3/lib/libc_psr.so.1", 1
6320:   open("/platform/SUNW,Sun-Fire-15000/lib/libc_psr.so.1", O_RDONLY) = 3
6320:   mmap(0x00010000, 32768, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_ALIGN, 3, 0) = 0xFF3A0000
6320:   munmap(0xFF3A2000, 24576)                       = 0
6320:   close(3)                                        = 0
6320:   stat64("/usr/lib/locale/en_US/en_US.so.3", 0xFFBFE7F8) = 0
6320:   resolvepath("/usr/lib/locale/en_US/en_US.so.3", "/usr/lib/locale/en_US.ISO8859-1/en_US.ISO8859-1.so.3", 1
6320:   open("/usr/lib/locale/en_US/en_US.so.3", O_RDONLY) = 3
6320:   mmap(0x00010000, 32768, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_ALIGN, 3, 0) = 0xFF380000
6320:   mmap(0x00010000, 90112, PROT_NONE, MAP_PRIVATE|MAP_NORESERVE|MAP_ANON|MAP_ALIGN, -1, 0) = 0xFF360000
6320:   mmap(0xFF360000, 16093, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_FIXED|MAP_TEXT, 3, 0) = 0xFF360000
6320:   mmap(0xFF372000, 10158, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_PRIVATE|MAP_FIXED|MAP_INITDATA, 3, 8192) = 0x
6320:   munmap(0xFF364000, 57344)                       = 0
6320:   memcntl(0xFF360000, 6624, MC_ADVISE, MADV_WILLNEED, 0, 0) = 0
6320:   close(3)                                        = 0
6320:   stat64("/opt/CMT/bin/libc.so.1", 0xFFBFE6C8) Err#2 ENOENT
6320:   stat64("/opt/oracle/product/10.2.0.3/lib/libc.so.1", 0xFFBFE6C8) Err#2 ENOENT
6320:   stat64("/opt/teradatav2r6/odbc64/lib/libc.so.1", 0xFFBFE6C8) Err#2 ENOENT
6320:   stat64("/opt/teradatav2r6/lib64/libc.so.1", 0xFFBFE6C8) Err#2 ENOENT
6320:   munmap(0xFF380000, 32768)                       = 0
6320:   fstat64(1, 0xFFBFFAF8)                          = 0
6320:   open64("/opt/CMT/partitions/partition1/a.txt", O_RDONLY) = 3
6320:   fstat64(3, 0xFFBFFA60)                          = 0
6320:   llseek(3, 0, SEEK_CUR)                          = 0
6320:   read(3, " S D K F S D F K D S F K".., 8192)     = 94
6320:   write(1, " S D K F S D F K D S F K".., 94)      Err#5 EIO
6320:   open("/usr/lib/locale/en_US/LC_MESSAGES/SUNW_OST_OSCMD.mo", O_RDONLY) Err#2 ENOENT
6320:   fstat64(2, 0xFFBFEAA0)                          = 0
6320:   write(2, " c a t :   o u t p u t  ".., 19)      Err#5 EIO
6320:   open("/usr/lib/locale/en_US/LC_MESSAGES/SUNW_OST_OSLIB.mo", O_RDONLY) Err#2 ENOENT
6320:   write(2, " I / O   e r r o r", 9)               Err#5 EIO
6320:   write(2, "\n", 1)                               Err#5 EIO
6320:   llseek(3, 0, SEEK_CUR)                          = 94
6320:   close(3)                                        = 0
6320:   open64(">", O_RDONLY)                           Err#2 ENOENT
6320:   write(2, " c a t :   c a n n o t  ".., 17)      Err#5 EIO
6320:   open64("/opt/CMT/partitions/partition1/t.txt", O_RDONLY) = 3
6320:   fstat64(3, 0xFFBFFA60)                          = 0
6320:   llseek(3, 0, SEEK_CUR)                          = 0
6320:   read(3, 0x000222A0, 8192)                       = 0
6320:   llseek(3, 0, SEEK_CUR)                          = 0
6320:   close(3)                                        = 0
6320:   close(1)                                        = 0
6320:   _exit(2)

I cannot use eval as the path for eval does not exist. Is there any other alternative to trick the execve function to execute commands with redirections ?

Rgds,
Gokul

Last edited by Scott; 05-25-2010 at 02:46 PM.. Reason: Code tags, please...
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

find command with exec doesnt work

Hi There, I have a script which finds for log files and removes them if the file has changed in the last day. The script runs fine without errors. The log file is still there. So, I decided to print the find command and run the command outside the script. Getting "Incomplete statement" Can you... (6 Replies)
Discussion started by: funtochat2002
6 Replies

2. Shell Programming and Scripting

redirection and output

I'm redirecting the output of a command to a logfile, however, if the user is on a terminal I would also like the output to be displayed on the screen. tar tvf some_tarfile >Logfile if the user is on a term then have the output to the Logfile and also be displayed on the screen at the same... (2 Replies)
Discussion started by: nck
2 Replies

3. Shell Programming and Scripting

Redirection output

Hi there I have a script that runs but it outputs everything onto the screen instead of a file. I've tried using the > outputfile.txt however all it does is dump the output to the screen and creates an outputfile.txt but doesn't put anything in that file. Any help would be appreciated ... (6 Replies)
Discussion started by: kma07
6 Replies

4. Shell Programming and Scripting

Output redirection

We have an application here that does some table queries and then prints the result on screen. I do not have the code of this application (which i will just call "queryCommand"), but what it does is that you call it with some parameters and it prints some info about the query and then the... (5 Replies)
Discussion started by: jolateh
5 Replies

5. UNIX for Dummies Questions & Answers

Output redirection

Hello i am trying to write a script that will redirect the output to a certain file. Here is the code so far: #!/bin/bash ps -e | sort | more > psfile When I execute the script nothing happens since i assume the output was redirected to the file called psfile. When I try to look at the... (1 Reply)
Discussion started by: mfruiz34
1 Replies

6. UNIX for Advanced & Expert Users

find -exec with 2 commands doesn't work (error incomplete staement)

Hi Gurues, I need to modify an existing script that uses find to search a folder, and then move its contents to a folder. What I need to do is run gzip on each file after it's moved. So, I ran this little test: Put a ls.tar file on my $HOME, mkdir tmp, and then: virtuo@tnpmprd01: find .... (3 Replies)
Discussion started by: llagos
3 Replies

7. Shell Programming and Scripting

output redirection

Hi all I was wondering if there was a slicker way of doing this without the file - awk '{print $2}' FS=":" "${FILE}" > "${TMPFILE}" { read M_GRP_ID || m_fail 1 "Error: Read failed 1 (${FUNCNAME})" read M_GRP_WAIT || m_fail 1 "Error: Read failed 2 (${FUNCNAME})" }... (6 Replies)
Discussion started by: steadyonabix
6 Replies

8. Solaris

Redirection does not work in Solaris

Hi all, i have been trying to direct o/p of one command to file, but i don get any entries in file but ouptput get displayed on command prompt. I have tried many options but still , it does not work. please guide. here is the command -bash-3.00$ /usr/local/bin/sudo lpstat -p | grep... (2 Replies)
Discussion started by: manalisharmabe
2 Replies

9. Shell Programming and Scripting

Several exec on find send all the output to the last redirection

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)
Discussion started by: Tribe
2 Replies

10. Shell Programming and Scripting

Problems with I/O redirection via exec

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... (4 Replies)
Discussion started by: Clovis_Sangrail
4 Replies
All times are GMT -4. The time now is 11:40 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy