[Python] Operations auxiliary scripts

Source: Internet
Author: User


The following code is tested under Python 2.6.6


Add an account and change your password:

(Note: Linux expect command can also be completed, interactive auto-input function)

#!/usr/bin/env pythonaccount =  ' sl_t1 ' passwd= ' a1p2p3l4e5 ' cmd_useradd =  ' useradd  %s '  %  (account)        #添加用户命令, modify Import subprocess as as needed  spdef useradd ():cmd =  ' export lc_all=en_us && %s '  %  (cmd _useradd) F=open ('/dev/null ',  ' W ')  ret = sp.call (cmd, shell=true,  stdout=f,  STDERR=F) F.close () return retdef passwd ():cmd =  ' export lc_all=en_us & & passwd %s '  %  (account) F=open ('/dev/null ',  ' W ') p = sp. Popen (CMD, SHELL=TRUE, STDIN=SP. PIPE, STDOUT=F, STDERR=F) p.stdin.write ("%s\n"  %  (passwd)) p.stdin.write ("%s\n"  %  (passwd)) F.close () return p.wait () Def pymain (): #print   ' useradd:  ',  useradd () #print   ' passwd :  ',  passwd () ret = useradd () if not 0==ret:print  ' UserAdd  ', retreturnret = passwd () if not 0==ret:print  ' passwd  ',retreturn  print  ' Done '     #如果工作正常返回done, otherwise failed to return the steps and error code if __name__== ' __main__ ':p ymain ()





[Python] Operations auxiliary scripts

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.