self-deleting shell script

后端 未结 4 2042
予麋鹿
予麋鹿 2021-01-30 10:43

I\'ve looked around for an answer to this one but couldn\'t find one.

I have written a simple script that does initial server settings and I\'d like it to remove/unlink

4条回答
  •  北海茫月
    2021-01-30 10:54

    The script can delete itself via the shred command (as a secure deletion) when it exits.

    #!/bin/bash
    
    currentscript="$0"
    
    # Function that is called when the script exits:
    function finish {
        echo "Securely shredding ${currentscript}"; shred -u ${currentscript};
    }
    
    # Do your bashing here...
    
    # When your script is finished, exit with a call to the function, "finish":
    trap finish EXIT
    

提交回复
热议问题