9 Replies Latest reply: Jul 29, 2013 7:34 AM by EdStevens RSS

    Recover Deleted Script file from Memory

    PRaju

      Gurus,

       

      We have created some monitoring script in RedHat linux environment to monitor JVM behaviour,

      Unfortunately someone deleted source file of the script .However script execution not interupted yet.

       

      $ ps -ef |grep -i alert.sh

      praju  15757  3630  0 14:35 pts/0    00:00:00 grep -i alert.sh

      praju  27672     1  0 May10 ?        02:55:59 /bin/bash ./alert.sh

      $

       

      Our bad luck we don't have any backup of that.

       

      Is there any way to get the source file ?

        • 1. Re: Recover Deleted Script file from Memory
          Catch 22

          What is your output of the following command?

           

          # lsof | grep alert.sh
          
          • 2. Re: Recover Deleted Script file from Memory
            PRaju

            $ lsof | grep -i alert.sh

             

            1. alert.sh  27672  c_praju  cwd  
              unknown                                         /proc/27672/cwd (readlink:
              Permission denied)
            2. alert.sh 27672 c_praju rtd unknown /proc/27672/root (readlink: Permission denied)
            3. alert.sh  27672  c_praju  txt  
              unknown                                         /proc/27672/exe (readlink:
              Permission denied)
            4. alert.sh  27672  c_praju
              NOFD                                                   /proc/27672/fd (opendir:
              Permission denied)

               $

             

            $ pwd

            /proc/27672

            $ ls -rlt  cwd

            lrwxrwxrwx 1 praju g999 0 May 10 11:04 cwd -> /Oracle/apps/log/CONV_server1/logs/ora/10.1.3/opmn/oacore_default_group_10

            $

             

            Looks like its softlink and its keep changing.

             

            Regards,

            Raju

            • 3. Re: Recover Deleted Script file from Memory
              Catch 22

              You should try this as superuser(root). See the following example:

               

              Copy and paste the following to the command prompt to create a sample script:

               

              cat > myfile << EOF

              count=1

              count() {

                sleep \$count

              }

              while [ \$count -le 100 ]; do

                count

                count=\$((count +1))

              done

              EOF

               

              Set execute permissions:

               

              # chmod u+x myfile

               

              Execute the script in the background:

               

              # ./myfile &

               

              Delete the file:

               

              # rm -f myfile

               

              Get file descriptor:

               

              # lsof | grep myfile

              bash     7692   root  254r    REG    252,0    102    138779 /root/myfile (deleted)

               

              Verify information:

               

              # ls -l /proc/7692/fd/254

              lr-x------. 1 root root 64 Jul  8 23:26 /proc/7692/fd/254 -> /root/myfile (deleted)

               

              "Recover" the file:

               

              # cp /proc/7692/fd/254 ./myfile.rest

               

              Result:

               

              # cat myfile.rest

              count=1

              count() {

                 sleep $count

              }

              while [ $count -le 100 ]; do

                 count

                 count=$((count +1))

              done

               

              • 4. Re: Recover Deleted Script file from Memory
                PRaju

                I just tried form my user ( owner of the script )

                 

                $ pwd

                /proc/27672/fd

                $ ls -lrt

                total 0

                lr-x------ 1 c_praju g999 64 May 10 11:02 255 -> /home/JVM/alert.sh (deleted)

                l-wx------ 1 c_praju g999 64 May 10 11:02 2 -> /home/JVM/nohup.out

                l-wx------ 1 c_praju g999 64 May 10 11:02 1 -> /home/JVM/nohup.out

                l-wx------ 1 c_praju g999 64 May 10 11:02 0 -> /dev/null

                $ cp 255 /home/JVM/myfile.res

                cp: cannot stat `255': Stale NFS file handle

                $

                 

                Regards,

                Raju    

                • 5. Re: Recover Deleted Script file from Memory
                  WadhahDaouehi

                  Hi,

                  it is like Dude said (with root privilege)


                  For more information look at this URL.

                   

                  I hope this can help you

                  Best Regards

                  • 6. Re: Recover Deleted Script file from Memory
                    Catch 22

                    So perhaps after all the file wasn't deleted, but you lost the connection to the NFS share where the directory and file was provided. To correct the issue you can try to restart the NFS client.

                    • 7. Re: Recover Deleted Script file from Memory
                      PRaju

                      Ok.... Let us contact system admin and let you know status...

                      • 8. Re: Recover Deleted Script file from Memory
                        PRaju

                        SAs are not able to recover it from runnign process, finaly they restored frm latest backup

                         

                        Happy : i got my script

                        Worry : not able to recover from memory.

                        • 9. Re: Recover Deleted Script file from Memory
                          EdStevens

                          PRaju wrote:

                           

                          SAs are not able to recover it from runnign process, finaly they restored frm latest backup

                           

                          Happy : i got my script

                          Worry : not able to recover from memory.

                          Well, that's why we have backups.  If your SA or storage management, or whatever group doesn't backup your scripts to your satisfaction, there's nothing to keep you from maintaining your own 'last restort' code library.

                           

                          Expecting to be able to recover 'from memory' is NOT a backup/recovery plan.