我四处寻找这个问题的答案,却找不到答案.
我编写了一个简单的脚本来执行初始服务器设置,我希望它在完成时从根目录中删除/取消链接.我已经尝试了一些我用Google搜索的解决方案(例如/ bin/rm $ test.sh),但脚本似乎总是保持不变.这可能吗?下面是我的脚本到目前为止.
#! /bin/bash
cd /root/
wget -r -nH -np --cut-dirs=1 http://myhost.com/install/scripts/
rm -f index.html* *.gif */index.html* */*.gif robots.txt
ls -al /root/
if [ -d /usr/local/psa ]
then
echo plesk > /root/bin/INST_SERVER_TYPE.txt
chmod 775 /root/bin/*
/root/bin/setting_server_ve.sh
rm -rf /root/etc | rm -rf /root/bin | rm -rf /root/log | rm -rf /root/old
sed -i "75s/false/true/" /etc/permissions/jail.conf
exit 1;
elif [ -d /var/webmin ]
then
echo webmin > /root/bin/INST_SERVER_TYPE.txt
chmod 775 /root/bin/*
/root/bin/setting_server_ve.sh
rm -rf /root/etc | rm -rf /root/bin | rm -rf /root/log | rm -rf /root/old
sed -i "67s/false/true/" /etc/permissions/jail.conf
break
exit 1;
else
echo no-gui > /root/bin/INST_SERVER_TYPE.txt
chmod 775 /root/bin/*
/root/bin/setting_server_ve.sh
rm -rf /root/etc | rm -rf /root/bin | rm -rf /root/log | rm -rf /root/old
sed -i "67s/false/true/" /etc/permissions/jail.conf
break
exit 1;
fi
Run Code Online (Sandbox Code Playgroud)
ric*_*cho 73
rm -- "$0"
Run Code Online (Sandbox Code Playgroud)
应该做的伎俩.$ 0是执行脚本的完整路径的魔术变量.
zie*_*mer 22
这对我有用:
#!/bin/sh
rm test.sh
Run Code Online (Sandbox Code Playgroud)
也许你真的不想在'$ test.sh'中加上'$'?
小智 7
脚本退出时可以通过shred 命令(作为安全删除)删除自身。
#!/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
Run Code Online (Sandbox Code Playgroud)