首页 > 数据库 > Oracle > [20191215]seq控制执行顺序.txt
[20191215]seq控制执行顺序.txt
--//我测试经常使用seq+xargs控制循环执行次数,记录一下工作中遇到的问题.
1.测试次数过1e6的情况:
--//一般测试循环次数不会太多,不会遇到这个问题.如果过了1e6.
$ seq 1000000 1000002
1e+06
1e+06
1e+06
--//解决方法如下:
$ seq -f "%7.0f" 1000000 1000002
1000000
1000001
1000002
--//这个版本我知道仅仅出现在rh 5.9 的版本(顺便说一下版本的bash问题多多).bash version如下:
# echo $BASH_VERSION
3.2.25(1)-release
--//包括Bash Code Injection Vulnerability CVE-2014-7169.简单的测试代码:
$ env x='() { :;}; echo vulnerable' bash -c "echo this is a test"
vulnerable
this is a test
--//如果出现vulnerable显示,说明有问题,我们exadata就有这个bug包括后台的服务器.其它高版本bash shell没有这个问题:
$ echo $BASH_VERSION
4.4.12(3)-release
$ seq 1000000 1000002
1000000
1000001
1000002
2.执行启动慢的问题.
--//测试例子:
$ cat a.txt
exec :v_a := &&1;
select * from t where id = :v_a;
commit;
$ cat t1.sh
#!/bin/bash
sqlplus -s -l scott/book <<EOF
set feedback off
variable v_a number;
$(seq 1000000 | xargs -IQ echo -e "@ a.txt Q" )
quit
EOF
--//如果执行t1.sh,会遇到执行启动缓慢的问题,因为bash shell要完全展开seq 1000000 | xargs -IQ echo -e "@ a.txt Q" 的输出后
--//才开始执行.要将seq 1000000 | xargs -IQ echo -e "@ a.txt Q" 放在外面,改写如下:
$ mknod /tmp/oop.pipe p
$ ls -l /tmp/oop.pipe
prw-r--r-- 1 oracle oinstall 0 2019-11-04 10:44:02 /tmp/oop.pipe
--//建立一个管道设备.
$ cat t1.sh
#!/bin/bash
seq 1000000 | xargs -IQ echo -e "@ a.txt Q" > /tmp/oop.pipe &
sqlplus -s -l scott/book <<EOF
set feedback off
variable v_a number;
@ /tmp/oop.pipe
quit
EOF
3.另外发现seq也可以拼成一行,使用-s参数.
$ seq -s ":" 10
1:2:3:4:5:6:7:8:9:10
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/267265/viewspace-2668702/ ,如需转载,请注明出处,否则将追究法律责任。