小编SLS*_*SLS的帖子

检查目录是否不存在

我编写了一个脚本来检查var/log目录,它会获取其中的所有目录并检查这些目录中是否有归档目录.如果存档目录不存在,我想创建它,但是一旦创建它,​​脚本就会尝试再次创建它.

vdir=$(sudo sh -c "find /var/log/ -maxdepth 1 -type d ! -name "archive"" )
for i in $vdir ;do
    echo $i
    if [[ ! -d $i/$arc ]];then
        sudo sh -c "mkdir $i/$arc"
        echo "$date:$HN:Creating:$i/$arc:directory" >> logrotation.log
    fi
done
Run Code Online (Sandbox Code Playgroud)

当我执行上面的代码时,它给了我这个错误.似乎脚本没有检查条件.

mkdir: cannot create directory ‘/var/log/speech-dispatcher/archive’: File exists
Run Code Online (Sandbox Code Playgroud)

linux bash shell

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

Python3 askopenfilename错误

我写的Python程序为波动框架GUI基础上,我仍然处于起步阶段,因为我为Python初学者,我使用的文件导入从"askopnefilename",该功能给错误,当我打开和关闭,不会选择文件你能帮我解决一下吗?

代码:

from tkinter import *
from tkinter import filedialog
from tkinter.filedialog import askopenfilename
from mtTkinter import *
import subprocess


def donothing():
   filewin = Toplevel(root)
   button = Button(filewin, text="Do nothing button")
   button.pack()

def OpenFile():
    file = open(askopenfilename(),'r')
    print(root.file)

def Quit():
    root.destroy()

def Test():
    print("Hello world")
    input("Press return to exit")

def Shell():
#    print("Below is the output")
    subprocess.call('./home/shanaka/bash_lerning/function1.sh',shell=True)


root = Tk()
root.title("Volatility")
root.geometry("600x400")

menubar = Menu(root)
startmenu = Menu(menubar, tearoff=0)
startmenu.add_command(label="Import", command=OpenFile)
startmenu.add_separator()
startmenu.add_command(label="Exit", command=Quit)
menubar.add_cascade(label="Start", menu=startmenu)

searchmenu = Menu(menubar, tearoff=0) …
Run Code Online (Sandbox Code Playgroud)

python tkinter python-3.x python-3.4

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

标签 统计

bash ×1

linux ×1

python ×1

python-3.4 ×1

python-3.x ×1

shell ×1

tkinter ×1