* /dev/stdin .... ?
@ 2003-12-22 19:47 Barth Weishoff
2003-12-22 21:30 ` Peter da Silva
2003-12-22 21:32 ` Spider Boardman
0 siblings, 2 replies; 5+ messages in thread
From: Barth Weishoff @ 2003-12-22 19:47 UTC (permalink / raw)
Hello group,
I've run this by HP, and they can't seem to come up with a clear
answer. Anyway, long story short, I've been using here documents
with OpenSSH's SFTP program to transfer files among hosts. Example
(stolen from http://www.snailbook.com/faq/scripting-sftp.auto.html )
#!/bin/sh
echo "OK, starting now..."
sftp -b /dev/stdin remotehost <<EOF
cd pub
...
That works *great* on Solaris, Linux and FreeBSD. However, it
doesn't work at all on any version of Tru64 unix. /dev/stdin doesn't
exist, and I'm not sure what to substitute on a Tru64 box in order to
make this work. I have tried:
sftp -b `tty` somehost <<HEREDOC
but to no avail.
I've looked at the /dev/stdin on a typical linux box;
[cj037@stotslin1 fd]$ ls -l /dev/stdin
lrwxrwxrwx 1 root root 17 Jul 10 09:51 /dev/stdin ->
../proc/self/fd/0
As you can see, it's just a link to /proc/self/fd/0 which is in turn
linked to the current tty
lrwx------ 1 cj037 cj037 64 Dec 22 13:44 0 ->
/dev/pts/2
Which is why I attempted to use `tty` in tandem with the -b option in
SFTP.
Does anyone have any idea how to accomplish this under Tru64? Thanks!
-BW
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: /dev/stdin .... ?
2003-12-22 19:47 /dev/stdin .... ? Barth Weishoff
@ 2003-12-22 21:30 ` Peter da Silva
2003-12-23 4:23 ` Finnbarr P. Murphy
2003-12-22 21:32 ` Spider Boardman
1 sibling, 1 reply; 5+ messages in thread
From: Peter da Silva @ 2003-12-22 21:30 UTC (permalink / raw)
In article <efbd1d5e.0312221147.57aecc0@posting.google.com>,
Barth Weishoff <barth.e.weishoff@cummins.com> wrote:
> Hello group,
>
> I've run this by HP, and they can't seem to come up with a clear
> answer. Anyway, long story short, I've been using here documents
> with OpenSSH's SFTP program to transfer files among hosts. Example
> (stolen from http://www.snailbook.com/faq/scripting-sftp.auto.html )
>
> #!/bin/sh
> echo "OK, starting now..."
> sftp -b /dev/stdin remotehost <<EOF
> cd pub
> ...
-b batchfile
Batch mode reads a series of commands from an input batchfile instead
of stdin.
Looks like leaving the "-b /dev/stdin" out completely would work. The
problem is that sftp may not be written intelligently and to only act
as if it's interactive if input is from a terminal. Given that this
option even exists, when you should be able to just run
sftp [user@]host < batchfile
I suspect that's the case, but you can try.
> exist, and I'm not sure what to substitute on a Tru64 box in order to
> make this work. I have tried:
>
> sftp -b `tty` somehost <<HEREDOC
>
> but to no avail.
No, that wouldn't work. `tty` (or /dev/tty, which should act the same as
the /dev/... string that comes out of `tty`) is always the terminal, and
never anything you can redirect... that's what it's for, after all.
You can create an equivalent to "/dev/stdin" using a named pipe, but
really the best way around this is something like:
BATCHFILE=/some/secure/directory/batch$$.sftp
trap 'rm $BATCHFILE' 0 # to guarantee it's cleaned up
cat > $BATCHFILE << EOF
commands
EOF
sftp -b $BATCHFILE user@host
> lrwx------ 1 cj037 cj037 64 Dec 22 13:44 0 ->
> /dev/pts/2
/proc/self/0 is not going to always be linked to the tty. In fact, if that's
linked to the tty in *any* case where stdin is redirected I would be utterly
shocked. Try "ls -l /proc/self/0 < /some/file" and see what happens.
> Does anyone have any idea how to accomplish this under Tru64? Thanks!
See above. You have a non-portable example. The way to make it portable is
to fix sftp to do what most portable programs do... use the file named "-"
as a special case for stdin... or to use an explicit batch file.
--
I've seen things you people can't imagine. Chimneysweeps on fire over the roofs
of London. I've watched kite-strings glitter in the sun at Hyde Park Gate. All
these things will be lost in time, like chalk-paintings in the rain. `-_-'
Time for your nap. | Peter da Silva | Har du kramat din varg, idag? 'U`
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: /dev/stdin .... ?
2003-12-22 19:47 /dev/stdin .... ? Barth Weishoff
2003-12-22 21:30 ` Peter da Silva
@ 2003-12-22 21:32 ` Spider Boardman
2003-12-23 2:47 ` Barth Weishoff
1 sibling, 1 reply; 5+ messages in thread
From: Spider Boardman @ 2003-12-22 21:32 UTC (permalink / raw)
Barth Weishoff wrote:
> Hello group,
>
> I've run this by HP, and they can't seem to come up with a clear
> answer. Anyway, long story short, I've been using here documents
> with OpenSSH's SFTP program to transfer files among hosts. Example
> (stolen from http://www.snailbook.com/faq/scripting-sftp.auto.html )
>
> #!/bin/sh
> echo "OK, starting now..."
> sftp -b /dev/stdin remotehost <<EOF
> cd pub
> ...
....
>
> Does anyone have any idea how to accomplish this under Tru64? Thanks!
mount -t fdfs /dev/fd /dev/fd
ln -s fd/0 /dev/stdin
Adjust /etc/fstab appropriately. See also: fd(4).
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: /dev/stdin .... ?
2003-12-22 21:32 ` Spider Boardman
@ 2003-12-23 2:47 ` Barth Weishoff
0 siblings, 0 replies; 5+ messages in thread
From: Barth Weishoff @ 2003-12-23 2:47 UTC (permalink / raw)
That works very well! Just the way it's expected to operate. Thank you very much!
-BW
Spider Boardman <spider@orb.dynalias.net> wrote in message news:<3fe762d5$0$4740
> ....
> >
> > Does anyone have any idea how to accomplish this under Tru64? Thanks!
>
> mount -t fdfs /dev/fd /dev/fd
> ln -s fd/0 /dev/stdin
>
> Adjust /etc/fstab appropriately. See also: fd(4).
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: /dev/stdin .... ?
2003-12-22 21:30 ` Peter da Silva
@ 2003-12-23 4:23 ` Finnbarr P. Murphy
0 siblings, 0 replies; 5+ messages in thread
From: Finnbarr P. Murphy @ 2003-12-23 4:23 UTC (permalink / raw)
In article <efbd1d5e.0312221147.57aecc0@posting.google.com>,
Barth Weishoff <barth.e.weishoff@cummins.com> wrote:
> Hello group,
>
> I've run this by HP, and they can't seem to come up with a clear
> answer. Anyway, long story short, I've been using here documents
> with OpenSSH's SFTP program to transfer files among hosts. Example
> (stolen from http://www.snailbook.com/faq/scripting-sftp.auto.html )
>
> #!/bin/sh
> echo "OK, starting now..."
> sftp -b /dev/stdin remotehost <<EOF
> cd pub
> ...
The following works on Tru64 UNIX 5.1B
sftp remotehost <<EOF
cd pub
....
EOF
Looking at the OpenSSH source code, the relevant code
snippet is in sftp.c:
....
infile = stdin; /* Read from STDIN unless changed by -b */
while ((ch = getopt(argc, argv, "1hvCo:s:S:b:B:F:P:R:")) != -1) {
switch (ch) {
....
case 'b':
if (infile == stdin) {
infile = fopen(optarg, "r");
if (infile == NULL)
fatal("%s (%s).", strerror(errno), optarg);
} else
fatal("Filename already specified.");
showprogress = 0;
break;
....
}
}
- Finnbarr
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2003-12-23 4:23 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-12-22 19:47 /dev/stdin .... ? Barth Weishoff
2003-12-22 21:30 ` Peter da Silva
2003-12-23 4:23 ` Finnbarr P. Murphy
2003-12-22 21:32 ` Spider Boardman
2003-12-23 2:47 ` Barth Weishoff
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox