1
0
mirror of https://github.com/bregman-arie/devops-exercises.git synced 2024-11-19 20:31:47 +02:00

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?
This commit is contained in:
Raza Rafaideen 2024-08-31 09:15:03 +01:00 committed by GitHub
parent 193c4302d6
commit a70d8aab6a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -2143,6 +2143,20 @@ This is a good article about the topic: https://ops.tips/blog/how-linux-creates-
<details>
<summary>You executed a script and while still running, it got accidentally removed. Is it possible to restore the script while it's still running?</summary><br><b>
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/<PID>/fd/, where <PID> 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/<PID>/fd/0 /path_to_restore_your_file/yourscriptname.sh
```
Replace <PID> 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.
</b></details>
<a name="questions-linux-memory"></a>