恢复在后台运行的已删除脚本

时间:2016-09-20 19:08:56

标签: unix process nohup

我有在bg(nohup)中运行的脚本,但它被意外删除了,但现在继续运行我需要编辑已删除的代码。

我现在如何获得该代码。我假设它应该在运行时的某个地方。

1 个答案:

答案 0 :(得分:0)

试试这个:

#!/bin/bash

if [[ ! $1 || $1 == -h || $1 == --help ]]; then
    echo -e "Usage:\n\n\t$0 '[path/]<file name>'"
    exit 1
fi

files=(
    $(file 2>/dev/null /proc/*/fd/* |
        grep "(deleted)'$" | 
        sed -r 's@(:.*broken\s+symbolic\s+link\s+to\s+.|\(deleted\).$)@ @g' |
        grep "$1" |
        cut -d' ' -f1
    )
)

if [[ ${files[@]} ]]; then
    for f in ${files[@]}; do
        echo "fd $f match... Try to copy this fd to another place quickly!"
    done
else
    echo >&2 "No matching fd found..."
    exit 2
fi

未在非GNU-Linux上测试

相关问题