shell脚本中执行python脚本并接收其返回值的例子


1.在shell脚本执行python脚本时,需要通过python脚本的返回值来判断后面程序要执行的命令

例:有两个py程序 hello.py

def main():

    print "Hello"

if __name__=='__main__': main() world.py

def main(): print "Hello"

if __name__=='__main__': main()


shell 脚本 test.sh
python hello.py

python world.py

执行sh test.sh 打印结果为
  hello

  world

在hello.py中通过返回值 让shell脚本通过参数来判断,

hello.py这样写

import sys

def main(): try: print "hello" sys.exit(0) except: sys.exit(1)

if __name__=='__main__': main()

shell 脚本改为

python hello.py

if [ $?==0 ];then

    exit

else

        python world.py        

fi

就可以判断了

linux系统中的列出敏感用户的脚本代码
此处的敏感用户是指这个用户属于多个组,或者这个用户属于的组名跟这个用户名不一样#!/bin/bash#listuserwhobelongtomorethanonegroup#andlistuserwhobelongtothegroupwhich

a10 config backup for aXAPI
#!/bin/bash###################################################scriptbyVincentyu#createdat20140306#a10configbackupforaXAPIversion:2.1###################################################A10IP="1.1.1.11.1

一键备份gitolite服务器的Shell脚本
运行一次就能够把gitolite服务器上的仓库备份到本地.第一次运行会创建远程仓库的本地镜像,以后每次运行会把本地镜像更新.本程序只支持ssh方式其他