Viewing the contents of a deleted shell script that is still running

Viewed 220

Another post offered a solution for a self deleting shell script rm -- "$0"

If this line is inserted at the top of the script then the script will delete itself as soon as it starts running.

Is it possible to get the contents of the deleted script while it continues to run (meaning a process is still showing up via ps -eaf | grep scriptname)?

1 Answers

This way you can restore the script to its original position. $pid contains the PID of your script, e.g. 12345.

pid=12345
cat /proc/$pid/fd/255 > "$(readlink /proc/$pid/fd/255 | sed 's/ (deleted)$//')"
Related