为什么这个脚本在Kali Linux中工作,而不是Ubuntu

2022-10-15 07:38:36标签linuxbashubuntu
提问

我正在尝试在Ubuntu上运行一个脚本,我已经在Kali Linux(它运行得很好)构建,但它不会在Ubuntu上运行。 我已经改变了shebang,以匹配Ubuntu运行脚本的Bash位置。/ myscript。sh和bash myscript。没有运气。有趣的是,当复制到Ubuntu Bash终端时,命令确实会工作。 跑步时什么都没有发生。word。 当运行时。myscript -d word我得到如下错误: 任何帮助都将不胜感激

#!/usr/bin/bash
# Imported variables
source <(grep -E '^\w+=' /root/scripts/variables.sh)
ZONE_ID=$zoneID
cloudflareAPItoken=$cloudflareAPItoken
domainName=$domainName
serverName=$servername
function help {
    echo "This is the help test"
}
findID () {
    curl -X GET "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/dns_records" \
    -H "Authorization: Bearer $cloudflareAPItoken" \
    -H 'Content-Type: application/json' \
    | $(python3 -c "import sys,json
data=json.loads(sys.stdin.read())
if data['success']:
    for item in data['result']:
        if item['name']=='$OPTARG.emailtesting.co.uk':
            f = open('demofile.txt', 'w')
            f.write(item['id'])
            f.close()") 
}
deleteDNS () {
    curl -X DELETE "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/dns_records/$(cat demofile.txt)" \
    -H "Authorization: Bearer $cloudflareAPItoken" \
    -H "Content-Type: application/json" \
    | python -m json.tool;
    rm demofile.txt 
}
listAllDNS () {
    curl -X GET "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/dns_records" \
    -H "Authorization: Bearer $cloudflareAPItoken" \
    -H 'Content-Type: application/json' \
    | $(python -c $"import sys,json, re
data=json.loads(sys.stdin.read())
f = open('dnsLIST.txt', 'w')
if data['success']:
    for dict in data['result']:
        if dict['type'] == 'A' and dict['name'] != '$domainName':           
            f.write(dict['name'] + '\n')
else:
    print('ERROR(' + str(data['errors'][0]['code']) + '): ' + data['errors'][0]['message'])
f.close()
fin = open('dnsLIST.txt', 'r')
fout = open('dnsLISTredone.txt', 'w')
for line in fin:
    new_line = re.sub(r'(.+)($domainName)$',r'\1',line)
    new_line=new_line[:-2] + '\n'
    fout.write(new_line)
fin.close()
fout.close()
")
}
addSubDomain () {
    curl -s -X POST "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/dns_records" \
    -H "Authorization: Bearer $cloudflareAPItoken" \
    -H "Content-Type: application/json" \
    --data "{\"type\":\"A\",\"name\":\"$OPTARG\",\"content\":\"$serverName\",\"ttl\":120,\"proxied\":false}" | jq
}
if [[ ${#} -eq 0 ]]; then
    help
    exit 1
fi
optstring="hd:la:"
while getopts ${optstring} arg; do
    case ${arg} in
        h)
            help;;
    d)
        findID
        deleteDNS
        exit 1
        ;;
    l) 
        listAllDNS;;
    a)
        addSubDomain;;
        ?)
            echo "Invalid option: -${OPTARG}."
            exit 2;;
    esac
done

curl: (92) HTTP/2 stream 0 was not closed cleanly: PROTOCOL_ERROR (err 1)
Traceback (most recent call last):
  File "<string>", line 2, in <module>
  File "/usr/lib/python3.8/json/__init__.py", line 357, in loads
    return _default_decoder.decode(s)
  File "/usr/lib/python3.8/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/lib/python3.8/json/decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

▼版权说明

相关文章也很精彩
推荐内容
更多标签
相关热门
全站排行
随便看看

错说cuoshuo.com——程序员的报错记录

部分内容根据CC版权协议转载,如果您希望取消转载请发送邮件到cuoshuo8@163.com

辽ICP备19011660号-5