需求:公司卡片機容量太小,只有100G,由於使用的人比較的多,開機使用后有時候就會出現磁盤空間占滿數據寫不進去的情況,影響工作進度,而且每次使用完都得關掉卡片機,所以就有必要寫個清理磁盤的腳本,當卡片機開機啟動后執行腳本,如果磁盤達到設置的閾值,就進行空間的清理.
rc.local腳本
rc.local腳本是一個ubuntu開機后會自動執行的腳本,我們可以在該腳本內添加命令行指令。該腳本位於/etc/路徑下,需要root權限才能修改。
該腳本具體格式如下:
#!/bin/sh -e # # rc.local # # This script is executed at the end of each multiuser runlevel. # Make sure that the script will "exit 0" on success or any other # value on error. # # In order to enable or disable this script just change the execution # bits. # # By default this script does nothing. #/bin/sh /home/saneri/new_service.sh #腳本范例 exit 0
注意: 一定要將命令添加在 exit 0之前
方法2:
如何給ubuntu添加一個開機啟動腳本
1,新建個腳本文件new_service.sh
#!/bin/bash # command content # .................................. exit 0
2,設置權限
sudo chmod 755 new_service.sh
3,把腳本放置到啟動目錄下
sudo mv new_service.sh /etc/init.d/
4,將腳本添加到啟動腳本
執行如下指令,在這里90表明一個優先級,越高表示執行的越晚
cd /etc/init.d/
sudo update-rc.d new_service.sh defaults 90
移除Ubuntu開機腳本
sudo update-rc.d -f new_service.sh remove