LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-19-2007, 11:46 AM   #1
Luminoth
LQ Newbie
 
Registered: Aug 2007
Posts: 6

Rep: Reputation: 0
Bash script and chroot with a pipe


Hello all,

I've got a script I'm working on here:

Code:
#! /bin/sh

while read line; do
        echo $line
        chroot /usr/rh8 echo $line | /path/to/ourapp
done
but the pipe there is giving me a bit of trouble. If I run it as is, the pipe is treated as being outside of the chroot. I've tried single and double quotes around the command, but chroot complains about "no such file or directory" when I do that. Is there any way I can get that pipe to be a part of the command that chroot runs?

If it helps, what's going on here is we have an application that takes input on stdin and outputs a result to stdout. This is run from xinetd, which a separate application connects to, so stdin ends up coming through there.

Thanks in advance for any help.
 
Old 09-19-2007, 12:16 PM   #2
gnashley
Amigo developer
 
Registered: Dec 2003
Location: Germany
Distribution: Slackware
Posts: 4,928

Rep: Reputation: 612Reputation: 612Reputation: 612Reputation: 612Reputation: 612Reputation: 612
Try enclosing the whole command line in parentheses:
( chroot /usr/rh8 echo $line | /path/to/ourapp )
 
Old 09-19-2007, 12:20 PM   #3
Luminoth
LQ Newbie
 
Registered: Aug 2007
Posts: 6

Original Poster
Rep: Reputation: 0
Doesn't seem to work either. Getting no such file or directory on the application inside the chroot. I'm assuming that means the pipe is happening outside the chroot because I know the command exists in there.
 
Old 09-19-2007, 12:32 PM   #4
rsashok
Member
 
Registered: Nov 2006
Location: USA, CA
Distribution: RedHat, Debian
Posts: 202

Rep: Reputation: 31
Do you run it as a super user?
Does your "/bin/sh" links to bash (even though it might not be important - any shell should be good)?
Do you really have "/usr/rh8/path/to/ourapp" ?
 
Old 09-19-2007, 12:35 PM   #5
rsashok
Member
 
Registered: Nov 2006
Location: USA, CA
Distribution: RedHat, Debian
Posts: 202

Rep: Reputation: 31
How about trying:
chroot /usr/hr8 echo $line | chroot /usr/rh8 /path/to/ourapp
 
Old 09-19-2007, 12:47 PM   #6
Luminoth
LQ Newbie
 
Registered: Aug 2007
Posts: 6

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by rsashok View Post
Do you run it as a super user?
Does your "/bin/sh" links to bash (even though it might not be important - any shell should be good)?
Do you really have "/usr/rh8/path/to/ourapp" ?
The /bin/sh on the machine is pointing to /bin/bash, in the chroot it's not but it is the same (we did an scp of the filesystem which doesn't maintain the links). Just did an ls and the path to ourapp is correct in the script.
 
Old 09-19-2007, 01:01 PM   #7
Luminoth
LQ Newbie
 
Registered: Aug 2007
Posts: 6

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by rsashok View Post
How about trying:
chroot /usr/hr8 echo $line | chroot /usr/rh8 /path/to/ourapp
Perfect! That did it for me.

Thanks everyone.
 
  


Reply



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
separte pipe for stderr and stout in a bash script ask4info Programming 7 09-07-2012 01:39 AM
Shell script pipe input - bash mostly laikos Programming 4 11-09-2008 05:14 PM
Bash Scripting: Pipe input to script vs. $1 jhwilliams Linux - Software 3 12-21-2007 10:54 PM
Pipe a bash script into less in the script? keysorsoze Linux - Software 4 06-05-2007 10:41 AM
Read the output from a pipe with bash ? fluppi Linux - Software 3 01-13-2004 12:59 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:27 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
Open Source Consulting | Domain Registration