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 :(
rm
reading from stdin or from the tty for the response? – thrig Mar 8 '17 at 23:19/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 '17 at 23:25echo 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. – Gilles 'SO- stop being evil' Mar 8 '17 at 23:49