我在稍微更改 Python 腳本的最后一步時遇到錯誤,有人可以幫我嗎?
1- 請求輸入
vm = 'input your VM name'
#centos
2-手動定義路徑
path = 'var/lib/libvirt/images/centos.qcow2'
#Directory of centos image file
3-獲取日期
var=os.popen('date "%Y%m%d"')
vmdate=var.read()
#20220622
4- 創建一個包含兩個檔案的 Tar 存檔檔案。
os.system('tar cvJf ' vm '.tar.xz ' vm '.xml' ' ' path)
#create a Tar archive file that contains the centos.xml file and centos.qcow2 file. This command works fine and the output is: centos.tar.xz
但
5-當我嘗試在 Tar 存檔 (20220622) 的名稱后添加日期時,出現以下錯誤。(我想把tar檔案名改成centos20220622.tar.xz(vm vmdate.tar.xz))
os.system('tar cvJf ' vm vmdate '.tar.xz ' vm '.xml' ' ' path)
錯誤資訊:
tar: Cowardly refusing to create an empty archive
Try `tar --help' or `tar --usage' for more information.
sh: line 1: /home/aku/bin/.tar.xz: Permission denied
uj5u.com熱心網友回復:
首先添加正斜杠..
path = '/var/lib/libvirt/images/centos.qcow2'
并在您的日期中洗掉 \n ,它會起作用......
>>> vmdate
'20220622\n'
>>> vmdate.rstrip()
'20220622'
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/494770.html
下一篇:將div內的文本與底部中心對齊
