标签 shell 下的文章

Sample:
api-login-103923

to get the api

echo "api-login-103923"|cut -d"-" -f1

-d is the seprator
-f is the index , starting from 1

RPM编译时遇到这个问题

xecuting(%build): /bin/sh -e /var/tmp/rpm-tmp.HDvAfF
+ umask 022
+ cd /tmp/csmp-build-TLlpXrJT/BUILD
+ cd csmp-2.0.3sp1
+ $'\r'
/var/tmp/rpm-tmp.HDvAfF: line 29: $'\r': command not found
error: Bad exit status from /var/tmp/rpm-tmp.HDvAfF (%build)


RPM build errors:
    Bad exit status from /var/tmp/rpm-tmp.HDvAfF (%build)
make: *** [rpm] Error 1
make: Leaving directory `/root/rpms/xxx'

打开这个文件/var/tmp/rpm-tmp.HDvAfF时,会看到29号有个特殊的字符 ^M

这个其实是CLRF 没转成LF的问题, linux上用yum install dos2unix,修改相应的文件 即 dos2unix filename 即可

第一种方法:定义环境变量

//无需用户名和密码
export http_proxy=http://ip:port
export https_proxy=http://ip:port

//需要用户名和密码
export http_proxy=http://user:password@ip:port
export https_proxy=https://user:password@ip:port

第二种方法:在执行curl时加参数-x

curl -x <[protocol://][user:password@]proxyhost[:port]> url
--proxy <[protocol://][user:password@]proxyhost[:port]> url
--proxy http://user:password@Your-Ip-Here:Port url
-x http://user:password@Your-Ip-Here:Port url


curl -x http://mike:123456@api.baidu.com:3392 https://www.zixi.org

python3 适用,执行shell命令

使用subprocess

import subprocess

def run(args):
    out = subprocess.Popen(args, stderr=subprocess.STDOUT, stdout=subprocess.PIPE, shell=True)
    stdout, stderr = out.communicate()
    return stdout

print(run(['ls', '-l']))

使用os.system

import os
os.system('ps -ef')

使用os.popen

import os
os.popen('ls')