
import sys

_args = sys.argv

if __name__ == "__main__":
    if len(_args) == 5:
        keys_file = _args[1]
        target_file = _args[2]
        result_file = _args[3]
        log_file = _args[4]

        try:
            with open(keys_file, 'r') as k:
                keys = k.readlines()
                keys = [key.strip().split('@')[0] for key in keys]
                keys = [key for key in keys if key != '']
            with open(target_file, 'r') as t:
                target_lines = t.readlines()

            log = open(log_file, 'w')

            with open(result_file, 'w') as r:
                for line in target_lines:
                    if line.split(':')[0] in keys or \
                       line.split(':')[3] != '12':
                        r.write(line)
                    else:
                        log.write(line)

            log.close()

        except Exception as e:
            print(str(e))
            sys.exit()
    else:
        print('==================================================')
        print('python passwd_change.py keys passwd passwd_new log')
        print('==================================================')


import sys

_args = sys.argv

if __name__ == "__main__":
    if len(_args) == 8:
        keys_file = _args[1]
        passwd_orig = _args[2]
        passwd_new = _args[3]
        passwd_log = _args[4]
        shadow_orig = _args[5]
        shadow_new = _args[6]
        shadow_log = _args[7]

        try:
            with open(keys_file, 'r') as k:
                keys = k.readlines()
                keys = [key.strip().split('@')[0] for key in keys]
                keys = [key for key in keys if key != '']

            with open(passwd_orig, 'r') as po:
                passwd_lines = po.readlines()

            passwd_log = open(passwd_log, 'w')
            passwd_new_keys = []

            with open(passwd_new, 'w') as pn:
                for line in passwd_lines:
                    if line.split(':')[0] in keys or \
                       line.split(':')[3] != '12':
                        pn.write(line)
                        passwd_new_keys.append(line.split(':')[0])
                    else:
                        passwd_log.write(line)

            passwd_log.close()

            with open(shadow_orig, 'r') as so:
                shadow_lines = so.readlines()

            shadow_log = open(shadow_log, 'w')

            with open(shadow_new, 'w') as sn:
                for line in shadow_lines:
                    if line.split(':')[0] in passwd_new_keys:
                        sn.write(line)
                    else:
                        shadow_log.write(line)

            shadow_log.close()

        except Exception as e:
            print(str(e))
            sys.exit()
    else:
        print('==================================================')
        print('python passwd_change.py keys passwd passwd_new passwd_log' +
              ' shadow shadow_new shadow_log')
        print('==================================================')

Add shadow changing support according to our new passwd.
Add shadow changing support according to our new passwd.

  
  import sys
  
  _args = sys.argv
  
  if __name__ == "__main__":
-     if len(_args) == 5:
+     if len(_args) == 8:
          keys_file = _args[1]
-         target_file = _args[2]
-         result_file = _args[3]
+         passwd_orig = _args[2]
+         passwd_new = _args[3]
-         log_file = _args[4]
+         passwd_log = _args[4]
+         shadow_orig = _args[5]
+         shadow_new = _args[6]
+         shadow_log = _args[7]
  
          try:
              with open(keys_file, 'r') as k:
                  keys = k.readlines()
                  keys = [key.strip().split('@')[0] for key in keys]
                  keys = [key for key in keys if key != '']
-             with open(target_file, 'r') as t:
-                 target_lines = t.readlines()
  
-             log = open(log_file, 'w')
+             with open(passwd_orig, 'r') as po:
+                 passwd_lines = po.readlines()
  
+             passwd_log = open(passwd_log, 'w')
+             passwd_new_keys = []
+ 
-             with open(result_file, 'w') as r:
+             with open(passwd_new, 'w') as pn:
-                 for line in target_lines:
+                 for line in passwd_lines:
                      if line.split(':')[0] in keys or \
                         line.split(':')[3] != '12':
-                         r.write(line)
+                         pn.write(line)
+                         passwd_new_keys.append(line.split(':')[0])
                      else:
-                         log.write(line)
+                         passwd_log.write(line)
  
-             log.close()
+             passwd_log.close()
+ 
+             with open(shadow_orig, 'r') as so:
+                 shadow_lines = so.readlines()
+ 
+             shadow_log = open(shadow_log, 'w')
+ 
+             with open(shadow_new, 'w') as sn:
+                 for line in shadow_lines:
+                     if line.split(':')[0] in passwd_new_keys:
+                         sn.write(line)
+                     else:
+                         shadow_log.write(line)
+ 
+             shadow_log.close()
  
          except Exception as e:
              print(str(e))
              sys.exit()
      else:
          print('==================================================')
-         print('python passwd_change.py keys passwd passwd_new log')
+         print('python passwd_change.py keys passwd passwd_new passwd_log' +
+               ' shadow shadow_new shadow_log')
          print('==================================================')
  
Add shadow changing support according to our new passwd.
## Code Before:

import sys

_args = sys.argv

if __name__ == "__main__":
    if len(_args) == 5:
        keys_file = _args[1]
        target_file = _args[2]
        result_file = _args[3]
        log_file = _args[4]

        try:
            with open(keys_file, 'r') as k:
                keys = k.readlines()
                keys = [key.strip().split('@')[0] for key in keys]
                keys = [key for key in keys if key != '']
            with open(target_file, 'r') as t:
                target_lines = t.readlines()

            log = open(log_file, 'w')

            with open(result_file, 'w') as r:
                for line in target_lines:
                    if line.split(':')[0] in keys or \
                       line.split(':')[3] != '12':
                        r.write(line)
                    else:
                        log.write(line)

            log.close()

        except Exception as e:
            print(str(e))
            sys.exit()
    else:
        print('==================================================')
        print('python passwd_change.py keys passwd passwd_new log')
        print('==================================================')

## Instruction:
Add shadow changing support according to our new passwd.
## Code After:

import sys

_args = sys.argv

if __name__ == "__main__":
    if len(_args) == 8:
        keys_file = _args[1]
        passwd_orig = _args[2]
        passwd_new = _args[3]
        passwd_log = _args[4]
        shadow_orig = _args[5]
        shadow_new = _args[6]
        shadow_log = _args[7]

        try:
            with open(keys_file, 'r') as k:
                keys = k.readlines()
                keys = [key.strip().split('@')[0] for key in keys]
                keys = [key for key in keys if key != '']

            with open(passwd_orig, 'r') as po:
                passwd_lines = po.readlines()

            passwd_log = open(passwd_log, 'w')
            passwd_new_keys = []

            with open(passwd_new, 'w') as pn:
                for line in passwd_lines:
                    if line.split(':')[0] in keys or \
                       line.split(':')[3] != '12':
                        pn.write(line)
                        passwd_new_keys.append(line.split(':')[0])
                    else:
                        passwd_log.write(line)

            passwd_log.close()

            with open(shadow_orig, 'r') as so:
                shadow_lines = so.readlines()

            shadow_log = open(shadow_log, 'w')

            with open(shadow_new, 'w') as sn:
                for line in shadow_lines:
                    if line.split(':')[0] in passwd_new_keys:
                        sn.write(line)
                    else:
                        shadow_log.write(line)

            shadow_log.close()

        except Exception as e:
            print(str(e))
            sys.exit()
    else:
        print('==================================================')
        print('python passwd_change.py keys passwd passwd_new passwd_log' +
              ' shadow shadow_new shadow_log')
        print('==================================================')
