Shell script learning call script package file zip method example

Time:2020-2-16

Preface

This article mainly introduces the relevant information about calling scripts to package files into zip, which is shared for your reference and learning. Let’s take a look at the detailed introduction:

Recently, I just touched shell script and wrote a little simple practice. Here is a python call script to perform the packaging operation.

The method is as follows:

The first step is to create a script:


#!/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

Step 2: call the script

I use the script file called by Python to execute. Pay attention to the character format passed in. I write exec_shell in public class here


exec_shell(self, '/bin/sh /data/root/sbin/usercert.sh zip ' + CLIENT + ' "' + zip_psw + '" ' + zip_name)
#Specific methods
import commands
def exec_shell(self, shell):
 (status, out) = commands.getstatusoutput(shell)
 If (status! = 0): ා script execution failed
 self.log.debug("exec [%s] fail. out=%s"%(shell, out))
 else:
 self.log.debug("exec [%s] success. out=%s"%(shell, out))
 return (status, out)

summary

The above is the whole content of this article. I hope that the content of this article can bring some help to your study or work. If you have any questions, you can leave a message to exchange. Thank you for your support for developepaer.

Recommended Today

The application of USB camera in rk3399

The application of USB camera in rk3399 1, introduction UVCFull nameUSB Video Class, is a set of standard customized by usb-if. All USB interface cameras complying with this standard can almost be used directly under Windows Linux and other systems, achieving the similar effect of drive free. Of course, it doesn’t mean that there is […]