Linux shell 脚本判断ttyUSB设备节点是否存在
2016-10-28 19:42
501 查看
使用shell判断设备节点是否存在,例如插入4G Modem Sierra模组到Linux系统后,会生成一系列的TTY设备,一般会有一个可以收发AT命令。例如设备节点为 /dev/ttyUSB2 的字符设备。
判断脚本如下:
wait_for_ttyUSB2() {
while true
do
echo "dev=$TTY2"
if [ -c "$TTY2" ]; then
echo "$TTY2 is exist"
break
fi
echo "wait for $TTY2 ready, and check again after 1s"
sleep 1s
done
}
下面列出了与文件类型或者设备类型相对应的判断条件。
* -b file = True if the file exists and is block special file. 如果该文件存在并且是块特殊文件。
* -c file = True if the file exists and is character special file.如果该文件存在并且是字符特殊文件
* -d file = True if the file exists and is a directory. 如果该文件存在并且是一个目录。
* -e file = True if the file exists. 如果该文件存在
* -f file = True if the file exists and is a regular file 如果该文件存在并且是一个普通文件
* -g file = True if the file exists and the set-group-id bit is set. 如果该文件存在并且设置了组ID位。
* -k file = True if the files’ “sticky” bit is set. 如果文件的sticky “粘性”位被设置。
* -L file = True if the file exists and is a symbolic link. 该文件存在并且是一个符号链接。
* -p file = True if the file exists and is a named pipe. 该文件存在并且是一个命名管道。
* -r file = True if the file exists and is readable. 文件存在并且是可读的
* -s file = True if the file exists and its size is greater than zero. 文件存在,它的大小是大于零
* -S file = True if the file exists and is a socket. 文件存在并且是一个套接字
* -t fd = True if the file descriptor is opened on a terminal. 文件描述符是在一个终端上打开的
* -u file = True if the file exists and its set-user-id bit is set. 文件存在,它的设置用户ID位被设置了
* -w file = True if the file exists and is writable. 文件存在并且可写
* -x file = True if the file exists and is executable. 文件存在并且是可执行的
* -O file = True if the file exists and is owned by the effective user id. 文件存在并且是所拥有的有效用户ID
* -G file = True if the file exists and is owned by the effective group id. 文件存在并且拥有有效的gruop id。
参照上面的说明,我们要判断一个文件存在而不管其类型,那么可以使用 -e,如果要同时检查其类型,那么我们可以使用相对应的判断条件。
判断脚本如下:
wait_for_ttyUSB2() {
while true
do
echo "dev=$TTY2"
if [ -c "$TTY2" ]; then
echo "$TTY2 is exist"
break
fi
echo "wait for $TTY2 ready, and check again after 1s"
sleep 1s
done
}
下面列出了与文件类型或者设备类型相对应的判断条件。
* -b file = True if the file exists and is block special file. 如果该文件存在并且是块特殊文件。
* -c file = True if the file exists and is character special file.如果该文件存在并且是字符特殊文件
* -d file = True if the file exists and is a directory. 如果该文件存在并且是一个目录。
* -e file = True if the file exists. 如果该文件存在
* -f file = True if the file exists and is a regular file 如果该文件存在并且是一个普通文件
* -g file = True if the file exists and the set-group-id bit is set. 如果该文件存在并且设置了组ID位。
* -k file = True if the files’ “sticky” bit is set. 如果文件的sticky “粘性”位被设置。
* -L file = True if the file exists and is a symbolic link. 该文件存在并且是一个符号链接。
* -p file = True if the file exists and is a named pipe. 该文件存在并且是一个命名管道。
* -r file = True if the file exists and is readable. 文件存在并且是可读的
* -s file = True if the file exists and its size is greater than zero. 文件存在,它的大小是大于零
* -S file = True if the file exists and is a socket. 文件存在并且是一个套接字
* -t fd = True if the file descriptor is opened on a terminal. 文件描述符是在一个终端上打开的
* -u file = True if the file exists and its set-user-id bit is set. 文件存在,它的设置用户ID位被设置了
* -w file = True if the file exists and is writable. 文件存在并且可写
* -x file = True if the file exists and is executable. 文件存在并且是可执行的
* -O file = True if the file exists and is owned by the effective user id. 文件存在并且是所拥有的有效用户ID
* -G file = True if the file exists and is owned by the effective group id. 文件存在并且拥有有效的gruop id。
参照上面的说明,我们要判断一个文件存在而不管其类型,那么可以使用 -e,如果要同时检查其类型,那么我们可以使用相对应的判断条件。
相关文章推荐
- shell脚本判断设备节点是否存在
- shell脚本判断设备节点是否存在
- Linux Shell 判断块设备节点是否存在
- Linux Shell 判断块设备节点是否存在
- Android车机启动后判断是否存在USB存储设备
- Linux shell脚本中判断变量文件目录:权限、是否存在、空值、相等
- Linux shell脚本判断输入目录是否存在,并输出目录所在磁盘使用量
- Linux shell脚本中判断变量文件目录:权限、是否存在、空值、相等
- Linux shell脚本中判断变量文件目录:权限、是否存在、空值、相等
- Linux系统shell脚本判断变量文件目录:权限、是否存在、空值、相等
- Linux系统shell脚本判断变量文件目录:权限、是否存在、空值、相等
- mssql判断一个函数名是否存在脚本sql
- Linux系统shell脚本判断变量文件目录:权限、是否存在、空值、相等
- 执行SQL脚本语句判断是否已经存在
- 【转】c# 注册表操作,创建,删除,修改,判断节点是否存在
- Linux shell判断文件是否存在
- shell脚本循环判断进程是否存在
- Linux系统shell脚本判断变量文件目录:权限、是否存在、空值、相等
- 执行SQL脚本语句判断是否已经存在
- Linux系统shell脚本判断变量文件目录:权限、是否存在、空值、相等