記錄板端使用到的shell script一些方式
shell script
如何執行目錄內所有script (run-parts)
- 使用run-parts可以參數給shell script
1 | run-parts /etc/ppp/ip-down.d \ |
如何取得link實際位置 (readlink)
1 | # follow any symlink to find the real file |
檢查檔案是否在存,若不存在則離開script
1 | # If pppconfig has been removed we are not supposed to do anything. |
測試變數是否為空,若是則離開script
1 | # If we don't have a provider we have nothing to do. |
busybox command
run-parts 說明
1 | BusyBox v1.16.1 (2016-02-19 09:03:37 UTC) multi-call binary. |
readlink 說明
1 | Usage: readlink [-fnv] FILE |
shell test 用法
- -x
- True if file exists and is executable
- [ -x .] : 成功回傳0,其它則為非0
1 | DAEMON=/usr/sbin/ez-ipupdate |
1 | test expression |
busybox config
目前embedded是以ash為主,但也新增相容bash部分
1 | Choose your default shell (ash) ---> |
其它
如何取得script自已的pid
使用$$取得pid
t1.sh
1
2
3
4
5
6
7
8
9#!/bin/bash
echo $$
for((i=0; i<11; i=i+1))
do
echo $i
sleep 1
done[root@localhost tt]# ./t1.sh
1
2
3
4
5
618154
0
1
2
3
4check
t1.sh pid為181541
2
3root 18154 18056 0 11:54 pts/2 00:00:00 /bin/bash ./t1.sh
root 18158 18154 0 11:54 pts/2 00:00:00 sleep 1
root 18159 16537 0 11:54 pts/1 00:00:00 ps -ef