寫在前面的話:
- 版權聲明:本文爲博主原創文章,轉載請註明出處!
- 博主是一個小菜鳥,並且非常玻璃心!如果文中有什麼問題,請友好地指出來,博主查證後會進行更正,啾咪~~
- 每篇文章都是博主現階段的理解,如果理解的更深入的話,博主會不定時更新文章。
- 本文最後更新時間:2020.5.19
正文開始
假設開機需要自動執行的腳本文件名稱爲MyStartup
腳本內容爲:
#!/bin/bash
ls /root/ > /root/doc.txt
記得一定要有可執行權限:chmod +x MyStartup
方法一
腳本放在目錄/root/
下
配置方法
添加啓動 my_startup,其中 Name
和 Description
都是自己寫的,隨意寫,Command
爲 /root/MyStartup(需要自啓動腳本的完整路徑):
方法二
執行腳本:
#!/bin/bash
# 刪除可能已存在的 MyStartup
FileName="MyStartup"
rm /etc/init.d/$FileName
rm /etc/rc3.d/S01$FileName
rm /etc/rc4.d/S01$FileName
rm /etc/rc5.d/S01$FileName
# 向 MyStartup 中寫入需要執行的命令
echo "#!/bin/bash" > /etc/init.d/$FileName
echo "ls /root/ > /root/doc.txt" >> /etc/init.d/$FileName
chmod +x /etc/init.d/$FileName
ln -s /etc/init.d/$FileName /etc/rc3.d/S01$FileName
ln -s /etc/init.d/$FileName /etc/rc4.d/S01$FileName
ln -s /etc/init.d/$FileName /etc/rc5.d/S01$FileName