Automatically switch the shell to delete the small log script

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.