shell如何调用脚本将文件打包zip
这篇文章给大家分享的是有关shell如何调用脚本将文件打包zip的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。
方法如下:
第一步,创建脚本:
#!/bin/sh CERT_DIR_ZIP=/data/cert/keys zip_user(){ zip -P $zip_psw /data/frontend/tmp/$zip_name.zip $client/* } if [ "x$1" = "xzip" ];then cd $CERT_DIR_ZIP client=$2 zip_psw=$3 zip_name=$4 zip_user cd - fi
第二步:调用脚本
我这里用的是python调用的脚本文件去执行,注意传入的字符格式。我这里exec_shell写在公共类中.
exec_shell(self, '/bin/sh /data/root/sbin/usercert.sh zip ' + CLIENT + ' "' + zip_psw + '" ' + zip_name)
#具体方法 import commands def exec_shell(self, shell): (status, out) = commands.getstatusoutput(shell) if (status != 0): # 执行脚本失败 self.log.debug("exec [%s] fail. out=%s"%(shell, out)) else: self.log.debug("exec [%s] success. out=%s"%(shell, out)) return (status, out)
感谢各位的阅读!关于“shell如何调用脚本将文件打包zip”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,让大家可以学到更多知识,如果觉得文章不错,可以把它分享出去让更多的人看到吧!