Stephane CHAZELAS | 27 Sep 2011 21:40
Picon
Favicon

Re: Network redirection in bash

2011-04-10, 04:26(-07), Todd A. Jacobs:
> I'm trying something a little weird, and am not having much success
> with my shell redirection to a network port. I'm trying to send an MS
> Word file to antiword running out of inetd. Here's what I have on the
> client side:
>
>     exec 4<> /dev/tcp/127.0.0.1/2100
>     cat /tmp/foo.doc >&4
>     cat <&4
>
> This seems like it should work, but I never get any results back from
> antiword. Basically, it just waits until the service times out.
>
> I'm hoping I'm just doing something wrong with my shell redirection
> here. Thoughts?

It won't work for the same reason as

cat foo.doc /dev/tty | antiword -

won't output anything until you press Ctrl-D.

You'd need to shutdown the socket for sending first so that
antiword sees the end of file. Unfortunately, I don't think bash
allows you do close the sending and receiving side separately.
zsh's ztcp can't either as far as I can tell. You'd need to find
a way to tell antiword about the end of input another way.

You could for instance change it to accept uuencoded files and
handle the input with a wrapper script that does:
(Continue reading)

Stephane CHAZELAS | 27 Sep 2011 22:02
Picon
Favicon

Re: bash (or other shell) help with usernames

2011-07-19, 12:35(-07), Roger:
> Trying to do something simple, but it's not working.
> Just trying to pass an argument (in this case a username), and have it
> touch a file in that user's directory.
> calling the script like this:
> SCRIPTNAME  USERNAME
>
> #!/bin/bash
> touch ~$1/FILENAME
[...]

That's zsh syntax, not bash (though there are limits on the
format of username accepted, for instance a "a+b" user won't be
recognised)

You'd be better of using perl or another high level programming
language even if using touch to touch the file/dir.

#! /usr/bin/perl -w
foreach my $user ( <at> ARGV) {
  my $home = (getpwnam($user))[7] or
    die "No such user $user or no home directory";
  system("touch", "--", "$home/FILENAME") == 0 or exit(1);
}

--

-- 
Stephane


Gmane