using python 2.7 : sh: -c: line 0: syntax error near unexpected token `('
<p>Python 2.7</p>

<p>I am getting the following error message. Not clear as to why this is. I have searched and no luck. Fairly basic script. Has worked across all our windows environments</p>

<pre><code>#!/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()
</code></pre>

<p>this is the output:</p>

<pre><code>sh: -c: line 0: syntax error near unexpected token `('
sh: -c: line 0: `zip -r target_dir + os.sep + time.strftime('%Y%m%d') + platform.node()  + '.zip' "/home/datatec/ds/datos"'
Backup FAILED
</code></pre>
