使用Python2.7:sh:c:line 0:意外标记“(”附近出现语法错误)

2024-10-01 17:35:15 发布

您现在位置:Python中文网/ 问答频道 /正文

Python 2.7

我收到以下错误消息。不清楚为什么会这样。我已经找过了,但没有运气。相当基本的脚本。在我们所有的windows环境中都能工作

#!/usr/bin/env python

import os
import time
import subprocess
import platform

#Log Files

source = ['"/home/datatec/ds/datos"' ]

#Backup
target_dir = "/home/datatec/Backup"

#Zip file + date and time
target = "target_dir + os.sep + time.strftime('%Y%m%d') + platform.node()  + '.zip'"

zip_command = zip_command = "zip -r {0} {1}".format(target, ' '.join(source))
err = open('error.txt' , 'w')

#Run the backup + verify
if os.system(zip_command) == 0:

    print('Successful backup to', target)
else:
    print('Backup FAILED')

#create server directory, all folders are moved at end of the week
mkdir = 'ssh logcp@ushsdata01p "cd ../proddata;sleep 3;hn=$ushsdtec01p;mkdir ushsdtec01p;"'
os.system(mkdir)

dz = "rm /home/datatec/Backup/*.zip"
psfiles = "scp  *.zip logcp@ushsdata01p:/proddata/ushsdtec01p/"
print 'TRANSFERRING ZIP FILES!!'
if os.system(psfiles) == 0:
    os.system(dz)
    print ('Files transferred')
else:
       print('TRANSFER FAILED')
       err.write("job failed")
       err.close()

这是输出:

^{pr2}$

Tags: importtargethometimeoszipsystembackup
2条回答

^{}在子shell中执行参数,其中大括号有特殊含义。您应该改为使用^{}。在

但直接的错误是由中的引号引起的

target = "target_dir + os.sep + time.strftime('%Y%m%d') + platform.node() + '.zip'"

这条线应该是

^{pr2}$

首先,不应该引用“target=…”行。在

相关问题 更多 >

    热门问题