Python Paramiko source modified a bit, wrote an operation command of the log audit, but the log also backspace delete key recorded as ^h this, so changed the code, with the character of the string.
String has attributes of list
>>> a="helloWorld">>> a[:-1] 'Hello Worl '
Escape character
escape character \ (at end of line) newline \ \ backslash symbol \' single quotation mark \' double quotation mark \a Bell \b backspace (Backspace) \e escape \empty \ n line break \v portrait tab \ t horizontal tab \ r Enter \f \oyy octal number yy represents the character, for example: \o12 represents newline \ XYY the character represented by the decimal number yy, for example: \x0a for newline \other Other characters output in normal format
Code section
If Sys.stdin in R: x = Sys.stdin.read (1) if x = = ' \b ': cmd=cmd[:-1] else: cmd+=x # Records.append (x) if x = = ' \ r ': #print "Your input is:", cmd log_line = "-login_user:%s\t|host_addr:%s\t|%s | History_cmd:%s \ n "% (Username,hostname,time.strftime ("%y_%m_%d%h:%m:%s "), cmd) cmd = ' log_file.write ' ( Log_line)
Operation Demo 123456789 Delete 3 6 9 type three keys red as follows
[Email protected]:~/baolei#SHRemote.SH ########################################################1: [Haproxy] w1.dev.haproxy.org192.168.0.105######################################################## before choose items would beSleepa monentplease Choose IP of top:1Please input your username:rootroot192.168.0.105192.168.0.105Rootusername:rootWarning:unknown Host key!Auth by (p) Assword, (R) SA key, or (d) SS Key?[P] Password for[Email protected]192.168.0.105: Here we go! LastLogin: Thu Feb - the: -: - .From192.168.0.106/data/x/tools/team/Env/alias.EnvFatal:not a git repository (or any of the parent directories):. Git/data/x/tools/team/Env/git-completion.Envansible-direc:~ #124578-bash:124578: Command not foundansible-direc:~# Exitlogout***Eof[email protected]:~/baolei# vim/tmp/root/192.168.0. 105_audit_log_2016_02_27.log [email protected]:~/baolei# vim/tmp/root/192.168.0. 105_audit_log_2016_02_27.log [email protected]:~/baolei# vim/tmp/liujianzuo/192.168.0. 102_audit_log_2016_02_27.log [email protected]:~/baolei# vim Interactive.py[email protected]:~/baolei#Tail/tmp/root/192.168.0. 105_audit_log_2016_02_27.log Login_user:root|HOST_ADDR:192.168.0.105|2016_02_27 -: -:Wuyi| History_cmd:lsLogin_user:root|HOST_ADDR:192.168.0.105|2016_02_27 -: -: -|history_cmd:exit Login_user:root|HOST_ADDR:192.168.0.105|2016_02_27 -: +: -| History_cmd:lsLogin_user:root|HOST_ADDR:192.168.0.105|2016_02_27 -: +: in|history_cmd:lll Login_user:root|HOST_ADDR:192.168.0.105|2016_02_27 -: +: -|HISTORY_CMD:SD Login_user:root|HOST_ADDR:192.168.0.105|2016_02_27 -: +: -|history_cmd:exit Login_user:root|HOST_ADDR:192.168.0.105|2016_02_27 -: $: -| History_cmd:9Login_user:root|HOST_ADDR:192.168.0.105|2016_02_27 -: $: +|history_cmd:exit Login_user:root|HOST_ADDR:192.168.0.105|2016_02_27 -: Geneva: -| History_cmd:124578Login_user:root|HOST_ADDR:192.168.0.105|2016_02_27 -: Geneva: Wu| History_cmd:exit
The shell variable is passed into the Python script, and the modified source script is not pasted.
[Email protected]:~/baolei#CatRemote.SH #!/bin/SH#created by Liujianzuolist () {#cd/home/liujianzuo/server/ScriptsEcho "\033[33;1m########################################################\033[0m" awk '{printf "\033[35;1m%s:\t[%-4s]\t%20s\t%s\033[0m\n", Nr,$2,$1, $NF}'Remote_ip.logEcho "\033[33;1m########################################################\033[0m\n"}wai_t () {Echo "\033[32;1m before choose items would be sleep a monent\033[0m\n" # forIinch{1..3}; Do Sleep 0.6&&Echo-E"\033[35;1m..........................\033[0m"; Done#read-P"Please choose IP of top:"Num while true Do if[-Z $num] && [-Z $username]; ThenRead-P"Please choose IP of top:"Num Read-P"Please input your username:"username ContinueElse Breakfi DoneIP=`awk-V ip= $num'NR = = ip{printf "%s:\t[%10s]\t%-20s\t%s\n", Nr,$2,$1, $NF}'Remote_ip.log|awk '{print $NF}''}listwai_tpython=`whichpython 'Echo$username $IPpython demo.py $IP $username
There are several bugs to modify:
In-terminal switch IP, audit log IP to change accordingly.
The login server password failed one time without exiting.
Python's Paramiko source modified a bit, wrote an operation command of the log audit bug modification