日期:2014-05-16 浏览次数:20704 次
[root@RHEL6A shcode]# ls config nohup.out sh12.sh sh14.sh sh16.sh sh18.sh sh20.sh sh22.sh sh24.sh sleep.sh ftpautologin.sh sh11.sh sh13.sh sh15.sh sh17.sh sh19.sh sh21.sh sh23.sh sh25.sh temp.sh [root@RHEL6A shcode]# ./sh25.sh [root@RHEL6A shcode]# ls config nohup.out sh13.sh sh16.sh sh19.sh sh22.sh sh25.sh ftpautologin.sh sh11.sh sh14.sh sh17.sh sh20.sh sh23.sh sleep.sh mylog.txt sh12.sh sh15.sh sh18.sh sh21.sh sh24.sh temp.sh [root@RHEL6A shcode]# cat mylog.txt hello ls: cannot access aaabbbccc: No such file or directory [root@RHEL6A shcode]# cat sh25.sh #!/bin/sh exec 1>mylog.txt 2>&1 echo 'hello' ls aaabbbccc [root@RHEL6A shcode]#
------解决方案--------------------
exec就可以了。
------解决方案--------------------
exec 1>mylog.txt 2>&1
基础
------解决方案--------------------
这种问题自己试一下不就知道了,还是用前面贴的代码示例:
[root@RHEL6A shcode]# ./sh25.sh >> mylog2.txt [root@RHEL6A shcode]# ls config mylog.txt sh12.sh sh15.sh sh18.sh sh21.sh sh24.sh temp.sh ftpautologin.sh nohup.out sh13.sh sh16.sh sh19.sh sh22.sh sh25.sh mylog2.txt sh11.sh sh14.sh sh17.sh sh20.sh sh23.sh sleep.sh [root@RHEL6A shcode]# cat mylog.txt hello ls: cannot access aaabbbccc: No such file or directory [root@RHEL6A shcode]# cat mylog2.txt [root@RHEL6A shcode]#