2 커밋 62e46ef47e ... be2ff6a2cd

작성자 SHA1 메시지 날짜
  Sven Velt be2ff6a2cd Fix for awk/os-release with different OS 5 년 전
  Sven Velt f8934c59f9 Converted to python3 5 년 전
1개의 변경된 파일7개의 추가작업 그리고 7개의 파일을 삭제
  1. 7 7
      ssh-wrapper.py

+ 7 - 7
ssh-wrapper.py

@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 
 import os
 import re
@@ -10,7 +10,7 @@ allowed = [
 		##### System informations
 		r'^/usr/bin/lsb_release\s+-d$',		# Linux
 		r'^/(usr/)?bin/uname\s+-mrs$',		# Linux, BSD & others
-		r'''^/(usr/)?s?bin/awk -F'"' -e '/PRETTY_NAME/{ print \$2; }' /etc/os-release''',		# Linux: /etc/os-release via awk for get_os.py
+		r'''^/(usr/)?s?bin/awk -F'"' (-e\s*)?'/PRETTY_NAME/{ print \$2; }' /etc/os-release''',		# Linux: /etc/os-release via awk for get_os.py
 
 		##### Complete command lines (Monitoring-Plugins on Debian)
 		r'^/usr/lib/nagios/plugins/check_disk -w \d+% -c \d+% -p /[/a-z]*$',
@@ -33,7 +33,7 @@ allowed = [
 
 cmdline = os.getenv('SSH_ORIGINAL_COMMAND')
 if not cmdline:
-	print 'This is just a wrapper, no command specified!'
+	print('This is just a wrapper, no command specified!')
 	sys.exit(3)
 
 for maybe in allowed:
@@ -42,13 +42,13 @@ for maybe in allowed:
 
 		try:
 			cmd = subprocess.Popen(cmdline, stdout=subprocess.PIPE)
-		except Exception, exc:
-			print 'Could not execute plugin ("%s"): %s' % (' '.join(cmdline), exc)
+		except Exception as exc:
+			print('Could not execute plugin ("%s"): %s' % (' '.join(cmdline), exc))
 			sys.exit(3)
 		else:
-			print cmd.communicate()[0].rstrip()
+			print(cmd.communicate()[0].rstrip().decode('utf-8'))
 			sys.exit(cmd.returncode)
 
-print '%s: No allowed command found!' % sys.argv[0]
+print('%s: No allowed command found!' % sys.argv[0])
 sys.exit(3)