To delete logs, you need to switch the user to specify the directory for deletion. Therefore, you need to determine whether the script can be automatically implemented. The direct su command fails, so telnet to the local machine is used.
<Br/> #! /Usr/bin/KSh <br/> infile = "file. in "<br/> OUTFILE =" file. out "<br/> RM $ infile <br/> RM $ OUTFILE <br/> mknod $ infile P <br/> touch $ OUTFILE <br/> # file description 7 out and 8 for in <br/> exec 7 <> $ OUTFILE #### a common file is used to store command output <br/> exec 8 <> $ infile #### an MPs queue file is used as the standard input. </P> <p> # directory is retrieved cyclically, the directory is the user name <br/> for VAR in 'ls/data01/data' <br/> DO <br/> sleep 2 <br/> echo "Change User to $ VaR "</P> <p> # telnet <br/> Telnet localhost <& 8> & 7 2> & 1 & </P> <p> sleep 1 </P> <p> # enter the user name <br/> echo "$ Var"> $ infile <br/> sleep 2 </P> <p> # enter the password <br/> echo "$ Var" 123456 >>$ infile <br/> sleep 1 <br/> echo "Who am I" >>$ infile <br/> sleep 1 </P> <p> # Run the DELETE command <br/> echo "find/data01/data/$ var/worklog/log/-name "*. log "-mtime + 1-exec Rm-f {}/; ">>ininfile <br/> sleep 10 <br/> echo" find/data01/data/$ var/worklog/*/log/-name "*. log "-mtime + 1-exec Rm-f {}/; ">>ininfile <br/> sleep 10 </P> <p> # exit <br/> echo" exit "> $ infile <br/> sleep 2 <br /> done </P> <p> stty echo <br/>
Refer:
Http://blog.sina.com.cn/s/blog_716358dc0100lj6d.html