To give you some context, there's a ksh script running in AIX that contained a rm file.txt instruction - the problem is that the file, being owned by a shared group but by other user, made the script's rm command to ask for confirmation...

So, the rm command was waiting for confirmation on deleting a file, expecting a y or n from the command line (from STDIN), and as this was being ran from another script, in a non-interactive way, we had no way to type-in a value in there.

We googled the different options we had, but everything our there was intended for Linux or Solaris - one thing that caught our attention was a workaround for Linux that involved overwriting the value for the PID's STDIN File Descriptor, which makes a lot of sense in the theory, but sadly, in practice this is not working in AIX the same way it works on Linux.

foo@bar - /my/dir $ ps -fT 45023400
     UID      PID     PPID   C    STIME    TTY  TIME CMD
  foo 45023400 16449852   0 11:38:50 pts/17  0:00 /usr/bin/perl script1.pl
  foo  1507590 45023400   0 11:38:50 pts/17  0:00     \--/bin/sh script2.sh
  foo 50987084  1507590   0 11:38:51 pts/17  0:00         \--rm file.txt

We ended up killing PID 45023400, but I'm sure that can't be the only solution when this happens... so my question is: Is there a way to send a string to the STDIN of an existing PID in AIX?

As per the instructions in the Linux forums, you can redirect an echo to the File Descriptor correspondent to the STDIN for the aforementioned PID, but that didn't work in this case:

foo@bar - /my/dir $ ls -l /proc/50987084/fd/
total 0
c---------    1 foo   cm           24, 17 Mar  8 13:43 0
p---------    0 foo   cm                0 Mar  8 11:38 1
p---------    0 foo   cm                0 Mar  8 11:38 2

foo@bar - /my/dir $ echo n > /proc/50987084/fd/0
Permission denied
ksh: /proc/50987084/fd/0: cannot create

We got a Permission denied error, which I think is okay considering that the File Descriptors do not obey to ordinary files' mod rules... or at least not in AIX :(

  • Hmm, is rm reading from stdin or from the tty for the response?
    – thrig
    Mar 8, 2017 at 23:19
  • @thrig good question, and I'm afraid I don't know how to respond to it. I checked and noticed /dev/pts17 was related to this PID, so I tried to echo into it as well, to no avail (same error). Do you know how to figure this out? My guess was STDIN, but as this is running through SSH then TTY makes sense I think.
    – jimm-cl
    Mar 8, 2017 at 23:25
  • Even under Linux, echo n >/proc/…/fd/0 wouldn't have worked. It would write to the terminal file, meaning that it would cause something to be displayed on the terminal, not that it would inject input coming from the terminal. Mar 8, 2017 at 23:49

1 Answer 1


I think rm -f might do the trick for you:

        Does not prompt before removing a write-protected file. Does not display an error message or return error status if
        a specified file does not exist. If both the -f and -i flags are specified, the last one specified takes affect.
  • Yes, that would certainly help. However, that's something that would have to be implemented before running the script - the thing here is that I was looking for a work around for when that's too late and the script have already been ran. Using rm -f is an option for the future, of course :)
    – jimm-cl
    Mar 16, 2017 at 16:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.