LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Enterprise Linux Forums > Linux - Enterprise
User Name
Password
Linux - Enterprise This forum is for all items relating to using Linux in the Enterprise.

Notices


Reply
  Search this Thread
Old 07-16-2008, 04:05 AM   #1
discover
LQ Newbie
 
Registered: Jul 2008
Posts: 5

Rep: Reputation: 0
vgscan and pvscan outputs are not redirecting to a file in Oracle Enterprise Linux


Output of commands pvscan and vgscan are getting redirected to a file in Oracle Enterprise Linux.

File remains empty after giving following commands:

# pvscan >file.txt
# vgscan >file1.txt

although for other commands outout is getting redirected.

Please suggest some workaround or other mechanism to redirect their output to file.
 
Old 07-16-2008, 09:35 AM   #2
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,517
Blog Entries: 15

Rep: Reputation: 1470Reputation: 1470Reputation: 1470Reputation: 1470Reputation: 1470Reputation: 1470Reputation: 1470Reputation: 1470Reputation: 1470Reputation: 1470
The ">" symbol redirects standard output (file descriptor 1) a/k/a stdout.

It does NOT redirect standard error (file descriptor 2) a/k/a stderr.

Many commands send output to both stdout and stderr. Obviously errors usually go to the latter but sometimes so does non-error output.

To insure you get BOTH stdout and stderr in a file you must first redirect stdout then tell stderr to go to the same place - there is a shortcut for this using the file descriptors:

vgscan >file1.txt 2>&1

The 2>&1 says send file descriptor 2 to the same place as file descriptor 1. You have to do this AFTER using the redirect because the default for stdout (file descriptor 1) is the screen.
 
Old 07-17-2008, 01:13 AM   #3
discover
LQ Newbie
 
Registered: Jul 2008
Posts: 5

Original Poster
Rep: Reputation: 0
Thanx for your valuable reply.

But as you have said I have tried this command also

vgscan >file1.txt 2>&1

and still it is not redirecting the output to file1.txt

For other commands like "ls" redirection to file is working fine and similarly in RHEL, vgscan output is getting redirected to the file.

Only in case of Oracle Enterprise Linux this problem is coming.

Please suggest some workaround...
 
Old 07-17-2008, 09:57 AM   #4
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,517
Blog Entries: 15

Rep: Reputation: 1470Reputation: 1470Reputation: 1470Reputation: 1470Reputation: 1470Reputation: 1470Reputation: 1470Reputation: 1470Reputation: 1470Reputation: 1470
When you run vgscan without the redirect what do you see?

When you run vgscan with the redirect what do you see - does it change?
 
Old 07-18-2008, 01:13 AM   #5
discover
LQ Newbie
 
Registered: Jul 2008
Posts: 5

Original Poster
Rep: Reputation: 0
vgscan as well as pvscan both are giving proper output on the console when i'm not redirecting them. Its only when I'm redirecting them to a file, file remains blank.
 
Old 07-18-2008, 08:35 AM   #6
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,517
Blog Entries: 15

Rep: Reputation: 1470Reputation: 1470Reputation: 1470Reputation: 1470Reputation: 1470Reputation: 1470Reputation: 1470Reputation: 1470Reputation: 1470Reputation: 1470
So you get absolutely no screen output difference?

Instead of saying they run OK please post what happens with no redirect and what happens with redirect. I'm not looking for contents of the file but for differences in the screen output as it may give a clue as to what is going on.
 
Old 07-19-2008, 03:38 AM   #7
discover
LQ Newbie
 
Registered: Jul 2008
Posts: 5

Original Poster
Rep: Reputation: 0
This is the output:

[root /]# vgscan
Reading all physical volumes. This may take a while...
Found volume group "VolGroup00" using metadata type lvm2

[root /]# vgscan 1>output.txt 2>&1

[root /]# cat output.txt



[root /]# pvscan
PV /dev/sda2 VG VolGroup00 lvm2 [19.88 GB / 0 free]
Total: 1 [19.88 GB] / in use: 1 [19.88 GB] / in no VG: 0 [0 ]

[root /]# pvscan 1>output.txt 2>&1

[root /]# cat output.txt


As you can see output.txt is blank .....

Secondly I ran this program too .... which is directly accessing stdout and stderr for output:

#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <fcntl.h>

void execute(char **argv)
{
pid_t pid;
int status;

int fStdOutDesc = open("/tmp/outfile", O_CREAT | O_RDWR, S_IREAD | S_IWRITE);
int fStdErrDesc = open("/tmp/errfile", O_CREAT | O_RDWR, S_IREAD | S_IWRITE);

printf("Out file Desc dup2 is %d\n",fStdOutDesc);
printf("Err file Desc dup2 is %d\n",fStdErrDesc);

if ((pid = fork()) < 0) /* fork a child process */
{
printf("ERROR: forking child process failed...\n");
exit(1);
}

else if (pid == 0) /* for the child process: */
{
dup2(fStdOutDesc, fileno(stdout));
dup2(fStdErrDesc, fileno(stderr));

if (execvp(*argv, argv) < 0) /* execute the command */
{
printf("ERROR: exec failed...\n");
exit(1);
}
}
else /* for the parent process: */
{
while (wait(&status) != pid) ; /* wait for completion */
}
}

int main(void)
{
char cmd[1024];
char *argv[64];

printf("Enter the Command : ");
scanf("%s",&cmd); /* works for ls & doesn’t work for vgscan */
printf("\n");
argv[0]=cmd;
argv[1]='\0';
execute(argv);
return 0;
}

This program redirects output of command given as an argv argument.
 
Old 07-19-2008, 11:22 AM   #8
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,517
Blog Entries: 15

Rep: Reputation: 1470Reputation: 1470Reputation: 1470Reputation: 1470Reputation: 1470Reputation: 1470Reputation: 1470Reputation: 1470Reputation: 1470Reputation: 1470
Delete the "1" before the redirect to output.txt:

e.g.
"vgscan 1>ouput.txt 2>&1" should be:
"vgscan >output.txt 2>&1"

Redirect should work either way but it is unusual to use the former syntax. On testing on FC4, RHEL4 & RHEL5 it works both ways for me.

What does "ls -l output.txt" show you? I'm wondering if perhaps it is a symlink that goes to /dev/null or a non-existent file.

If it is still an issue you may need to open an SR with Oracle as you may have found a bug. It has happened that distro makers have commented out sections of code that they felt weren't important or they didn't understand. (See recent Ubuntu fubar where they accidentally restricted random key generation.)
 
Old 07-20-2008, 04:39 AM   #9
discover
LQ Newbie
 
Registered: Jul 2008
Posts: 5

Original Poster
Rep: Reputation: 0
Thanx for all the analysis.

For command ls -l >output.txt , list of files are getting redirected to output.txt

So, even we are thinking its a bug with Oracle.

Thanx for all.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
vgscan produces no output using file descriptors on Oracle Enterprise Linux. sandiworld Linux - Enterprise 1 03-27-2008 07:04 AM
LXer: Oracle and Symantec Certify Veritas Data Center Solutions on Oracle(R) Enterprise Linux LXer Syndicated Linux News 0 07-18-2007 07:31 AM
LXer: Oracle(R) Database Standard Edition One and Oracle Enterprise Linux on HP Set New World Record for Price Performance with TPC-C Benchmark LXer Syndicated Linux News 0 06-12-2007 06:01 PM
redirecting output to multiple outputs granny Linux - General 6 02-13-2004 08:18 AM

LinuxQuestions.org > Forums > Enterprise Linux Forums > Linux - Enterprise

All times are GMT -5. The time now is 09:39 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration