学校校园网在linux下是用Inode 802.1X Client for Linux 认证客户端 使用命令 linux1x -d 认证上网,经常掉线,每次重新登录时会提示Error: an instance of this program has been run already!

本来可以使用linux1x -k 来取消登录,不过也会不灵,不如直接杀掉进程方便。所以原来总会重复的使用  ps aux|grep 'linux1x' 来查看进程号,再用KILL命令。这样才麻烦,本来想写个SHELL,后来看了IPYTHON,果然是个神器,直接建个宏搞定,简单易懂。

In [1]: ps=!ps aux 

In [2]: pid=ps.grep('linux1x').fields(1)[0]

In [3]: print 'pid is',pid
pid is 6669

In [4]: !sudo kill ${pid} 

In [5]: print 'kill %s success!'
kill %s success!

In [6]: %macro killlinux1x 1-5
Macro `killlinux1x` created. To execute, type its name (without quotes).
Macro contents:
ps = _ip.magic("sc -l =ps aux")
pid=ps.grep('linux1x').fields(1)[0]
print 'pid is',pid
_ip.system("sudo kill ${pid} ")
print 'kill %s success!'

  

使用 %store命令把宏保存下来,以下次启动IPYTHON 还能调用killlinux1x
In [7]: %store killlinux1x
Stored 'killlinux1x' (Macro)

调用killlinux1x 

In [8]: killlinux1x
------> killlinux1x()
pid is 8303
kill %s success!

  

ipython 神器!!!

posted on 2012-02-19 16:15  lincolnlin  阅读(284)  评论(0编辑  收藏  举报