小编MLS*_*LSC的帖子

在Python中以特定模式打印字母

我有以下字符串,我把它分开:

>>> st = '%2g%k%3p'
>>> l = filter(None, st.split('%'))
>>> print l
['2g', 'k', '3p']
Run Code Online (Sandbox Code Playgroud)

现在我要打印两次g字母,k字母一次和p字母三次:

ggkppp
Run Code Online (Sandbox Code Playgroud)

这怎么可能?

python regex string

21
推荐指数
4
解决办法
1689
查看次数

在bash脚本中找不到mkdir命令

我不知道为什么我在运行这个简单的脚本时会出错:

#!/bin/bash

read -p "Please enter directory name: " DIR
read -p "Please enter the path: " PATH
mkdir -p "$PATH/$DIR"
Run Code Online (Sandbox Code Playgroud)
line 7: mkdir: command not found
Run Code Online (Sandbox Code Playgroud)

bash mkdir

13
推荐指数
2
解决办法
2万
查看次数

使用linux bash替换文件中两个字符串之间的文本

我有文件"acl.txt"

 192.168.0.1
 192.168.4.5
 #start_exceptions
 192.168.3.34
 192.168.6.78
 #end_exceptions
 192.168.5.55
Run Code Online (Sandbox Code Playgroud)

和另一个文件"例外"

 192.168.88.88
 192.168.76.6
Run Code Online (Sandbox Code Playgroud)

我需要用例外文件的内容替换#start_exceptions和#end_exceptions之间的所有内容.我在这个论坛上尝试了很多解决方案,但没有一个能有效.

linux bash sed

9
推荐指数
1
解决办法
6672
查看次数

在后台使用HERE_DOC方法运行脚本

我有一个应该在后台运行的脚本.我一打运行bash就必须回答一个问题.我怎么能这样做?

(nohup python script.py lst '<<HERE yes HERE' &)
Run Code Online (Sandbox Code Playgroud)

bash background heredoc

8
推荐指数
1
解决办法
2502
查看次数

AttributeError:'NoneType'对象没有属性'split'

我有一个包含这两个函数的脚本:

# Getting content of each page
def GetContent(url):
    response = requests.get(url)
    return response.content

# Extracting the sites
def CiteParser(content):
    soup = BeautifulSoup(content)
    print "---> site #: ",len(soup('cite'))
    result = []
    for cite in soup.find_all('cite'):
        result.append(cite.string.split('/')[0])
    return result
Run Code Online (Sandbox Code Playgroud)

当我运行程序时,我有以下错误:

result.append(cite.string.split('/')[0])
AttributeError: 'NoneType' object has no attribute 'split'
Run Code Online (Sandbox Code Playgroud)

输出样本:

URL: <URL That I use to search 'can be google, bing, etc'>
---> site #:  10
site1.com
.
.
.
site10.com

URL: <URL That I use to search 'can be google, bing, …
Run Code Online (Sandbox Code Playgroud)

python attributes split

8
推荐指数
1
解决办法
6万
查看次数

如何替换"bash:$ COMMAND:command not found"消息?

任何帮助,将不胜感激.

基本上,我想要替换:

~]$ obvfake
bash: obvfake: command not found
Run Code Online (Sandbox Code Playgroud)

附:

~]$ obvfake
[*] command not found
Run Code Online (Sandbox Code Playgroud)

谢谢.

linux bash stdout stderr

7
推荐指数
2
解决办法
2389
查看次数

权限被拒绝:httpd:无法打开错误日志文件/ etc/httpd/logs/error_log

当我想重新启动centOS 6.7上的httpd searvice时,我有以下错误:

/etc/init.d/httpd restart
Stopping httpd:                                            [FAILED]
Starting httpd: (13)Permission denied: httpd: could not open error log file /etc/httpd/logs/error_log.
Unable to open logs
                                                           [FAILED]
Run Code Online (Sandbox Code Playgroud)

这是error_log:

ls -Z /etc/httpd/logs/error_log
-rw-r--r--. root root unconfined_u:object_r:var_t:s0   /etc/httpd/logs/error_log
Run Code Online (Sandbox Code Playgroud)

我也禁用了selinux.

问题是什么?

php apache selinux httpd.conf

7
推荐指数
1
解决办法
2万
查看次数

类型错误:“unicode”对象不可调用

我想获得来源,但我有ERROR

>> from selenium import webdriver
>> driver = webdriver.PhantomJS()
>> url='http://google.com'
>> cont=driver.page_source(url)
>> print cont
>> driver.quit()
Run Code Online (Sandbox Code Playgroud)

错误:

Traceback (most recent call last):
  File "u.py", line 6, in <module>
    cont=driver.page_source(url)
TypeError: 'unicode' object is not callable
Run Code Online (Sandbox Code Playgroud)

python unicode selenium phantomjs

6
推荐指数
2
解决办法
4万
查看次数

Bash脚本命令在cron中不起作用

我有以下bash脚本来读取日志并检查暴力,然后使用iptables阻止违反IP.

#!/bin/bash
#blah blah run some commands to get the IP
iptables -A INPUT -s $p -j REJECT --reject-with icmp-host-prohibited
echo "BANNED $p FOR $COUNT ATTEMPTS" |wall
Run Code Online (Sandbox Code Playgroud)

我做了chmod 755.当我从终端运行命令时它运行正常.但是当我crontab -e以root用户身份设置cronjob时,它会获取IP并将"BANNED ..."消息回显到墙上,但没有任何内容添加到iptables列表中.

PS.我试过了两次#!/bin/bash,#!/bin/sh但没有运气.

linux bash cron

5
推荐指数
1
解决办法
4914
查看次数

检查bash中if语句中的两个条件

如果声明我写的有问题

var1=`COMMAND | grep <Something>`
if [ -n "$var1" ] && if [[ "$var1" != string ]]; then
    .
    .
    .
fi
Run Code Online (Sandbox Code Playgroud)

我想写if if语句检查:

如果var1不为null 并且如果string(可能是helloword)不在var1中那么就做.

我怎样才能做到这一点?

bash conditional if-statement

4
推荐指数
1
解决办法
5831
查看次数