From a70d8aab6ac7490da2640461be148462778cfcda Mon Sep 17 00:00:00 2001 From: Raza Rafaideen Date: Sat, 31 Aug 2024 09:15:03 +0100 Subject: [PATCH] Answer Linux (#10311) Answer : You executed a script and while still running, it got accidentally removed. Is it possible to restore the script while it's still running? --- topics/linux/README.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/topics/linux/README.md b/topics/linux/README.md index cb27b83c3..800d61e2c 100644 --- a/topics/linux/README.md +++ b/topics/linux/README.md @@ -2143,6 +2143,20 @@ This is a good article about the topic: https://ops.tips/blog/how-linux-creates-
You executed a script and while still running, it got accidentally removed. Is it possible to restore the script while it's still running?
+It is possible to restore a script while it's still running if it has been accidentally removed. The running script process still has the code in memory. You can use the /proc filesystem to retrieve the content of the running script. +1.Find the Process ID by running +``` +ps aux | grep yourscriptname.sh +``` +Replace yourscriptname.sh with your script name. +2.Once you have the PID, you can access the script's memory through the /proc filesystem. The script will be available at /proc//fd/, where is the process ID of the running script. Typically, the script's file descriptor is 0 or 1. + +You can copy the script content to a new file using the cp command: +``` +cp /proc//fd/0 /path_to_restore_your_file/yourscriptname.sh +``` +Replace with the actual PID of the script and /path_to_restore_your_file/yourscriptname.sh with the path where you want to restore the script. +