954,525 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

How to redirect stdin for child process (Linux Shell scripting)

Hi,
I'm trying to write a shell script that do ftp and download file periodically, this script should be called by a daemon running in the background.

the shell script "script.sh" is as follows:
yafc <a href="ftp://test:test@192.168.1.225:21">ftp://test:test@192.168.1.225:21</a> < commands

and the "commands" files is d Root/md5* /
quit

if I run script.sh it will work just fine.
But when the daemon software calls the "script.sh", the script will send ftp login request to the ftp server, but will not even answer the username or anything.

I believe it is something about child process redirection, but I don't know how to deal with it.

This problem is not only with yafc, it is the same with any ftp client or any application like telnet and so.

can you help?
Thanks !

ausrasul
Newbie Poster
10 posts since Oct 2009
Reputation Points: 10
Solved Threads: 0
 

This is just a guess. Try (yafc <a href="ftp://test:test@192.168.1.225:21">ftp://test:test@192.168.1.225:21</a> ) < commands . The parens make the enclosed command(s) run in a sub process together which may work as you wish.

griswolf
Veteran Poster
1,165 posts since Apr 2010
Reputation Points: 344
Solved Threads: 256
 

Interesting, Thanks for the help, I'll try it.
so far I found that the daemon closes all stdin stdout stderr before it makes the call to the shell script.
after openning the std I/O, it worked fine, on drawback is that I can see all the messages no the console screen.
I hope this will not be buffered after I log out from telnet.

Thanks for the help again !

ausrasul
Newbie Poster
10 posts since Oct 2009
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: