我有以下字符串,我把它分开:
>>> 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)
这怎么可能?
我不知道为什么我在运行这个简单的脚本时会出错:
#!/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) 我有文件"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之间的所有内容.我在这个论坛上尝试了很多解决方案,但没有一个能有效.
我有一个应该在后台运行的脚本.我一打运行bash就必须回答一个问题.我怎么能这样做?
(nohup python script.py lst '<<HERE yes HERE' &)
Run Code Online (Sandbox Code Playgroud) 我有一个包含这两个函数的脚本:
# 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) 任何帮助,将不胜感激.
基本上,我想要替换:
~]$ obvfake
bash: obvfake: command not found
Run Code Online (Sandbox Code Playgroud)
附:
~]$ obvfake
[*] command not found
Run Code Online (Sandbox Code Playgroud)
谢谢.
当我想重新启动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.
问题是什么?
我想获得来源,但我有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) 我有以下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但没有运气.
如果声明我写的有问题
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 ×6
linux ×3
python ×3
apache ×1
attributes ×1
background ×1
conditional ×1
cron ×1
heredoc ×1
httpd.conf ×1
if-statement ×1
mkdir ×1
phantomjs ×1
php ×1
regex ×1
sed ×1
selenium ×1
selinux ×1
split ×1
stderr ×1
stdout ×1
string ×1
unicode ×1