Re: Shell script removed but still executing

From: Chris F.A. Johnson (c.f.a.johnson_at_rogers.com)
Date: 07/11/03


Date: 11 Jul 2003 16:10:57 GMT

On Fri, 11 Jul 2003 at 15:36 GMT, Stephane CHAZELAS wrote:
> Franco wrote:
>> Somebody accidentaly removed an important shell script that hasn't backuped.
>> BUT the script is still running!!!
>>
>> That is, if I write "ps -ef" I still see "./name.sh" in execution even if
>> the file has been removed.
>>
>> Is there any way to get the script source back?
>
> On a Linux system, example of restoration:
>
> ~$ bash a &
> [2] 2124
> ~$ rm a
> ~$ ls -l /proc/2124/fd
> total 0
> lrwx------ 1 chazelas users 64 2003-07-11 17:24 0 -> /dev/pts/5
> lrwx------ 1 chazelas users 64 2003-07-11 17:24 1 -> /dev/pts/5
> lrwx------ 1 chazelas users 64 2003-07-11 17:24 2 -> /dev/pts/5
> lr-x------ 1 chazelas users 64 2003-07-11 17:24 255 -> /home/chazelas/a (deleted)
> lrwx------ 1 chazelas users 64 2003-07-11 17:24 3 -> /dev/pts/5
> ~$ ls -Li /proc/2124/fd/255
> 29729 /proc/2124/fd/255
> ~$ sudo debugfs /dev/hda6
> Password:
> debugfs 1.32 (09-Nov-2002)
> debugfs: dump <29729> /tmp/a.restore
> ~$ ls -l /tmp/a.restore
> -rw-r--r-- 1 root root 172 2003-07-11 17:25 /tmp/a.restore

    Or just:

pid=2124 ## adjust to taste
cat /proc/$pid/fd/255 > $pid.sh

    FreeBSD also uses a /proc psuedo filesystem, but it doesn't store
    the script.

-- 
    Chris F.A. Johnson                        http://cfaj.freeshell.org
    ===================================================================
    My code (if any) in this post is copyright 2003, Chris F.A. Johnson
    and may be copied under the terms of the GNU General Public License


Relevant Pages

  • Re: pop-forum Re: poplog-dev A look at Poplog on the Macintosh
    ... with the poplink command. ... When trying to make pglink produce a 'sh' rather than a 'csh' shell ... script for linking and when trying to make it put unexpanded environment ... using the shell script pglibr, ...
    (comp.lang.pop)
  • Files appear to be cross linked
    ... script requires a number of standard environment variables to be set ... so it calls a second shell script to set these at the session level, ... control should return to the first shell script, ... that the script executes to the last line prior to the displaying of ...
    (comp.unix.solaris)
  • Re: [PHP] Catch STDERR
    ... into your PHP script? ... Or do you just need STDOUT in one variable, and STDERR in another, ... Another option is to try to write a .sh shell script to get what you ...
    (php.general)
  • Re: Converting large bash script to TCL
    ... I know that TCL and shell scripting share a lot of similarities. ... The shell script ... Determine what it (the script) is supposed to do ... echo "WOULD YOU LIKE TO INSTALL NAC DRIVER ...
    (comp.lang.tcl)
  • Re: basic questions
    ... Setting a script that runs at 3:00 ... Set chron to run that shell script. ... Debug the GUI application with the REPL. ... You start up the Web browser, then browse the Web, visit a hundred ...
    (comp.lang.lisp)