import sys, os, datetime, time, urllib
from subprocess import *
List_SP_Servers=["toto1","toto2","toto3"]
ListTraceFile_SP_Servers=["c:\\\\dic1\\\\udic1\\\\file1.txt","c:\\\\dic1\\\\udic1\\\\file2.txt"]
for l__sp in List_SP_Servers:
try:
print '\n--------'+str(l__sp)+'--------'
for l__traces in ListTraceFile_SP_Servers:
#l__cmd1 = '['+'\"psexec\",\"\\\\'+l__sp+'\",'+'\"-nobanner\"'+',\"ls\",\"-al\"'+',"'+l__traces+'\"'+']'
#l__cmd1 = '(['+'\"psexec\",\"\\\\'+l__sp+'\",'+'\"-nobanner\"'+',\"ls\",\"-al\"'+',"'+l__traces+'\"'+'],shell=True,stdout=PIPE).communicate()[0]'
#print l__cmd1
#output1=popen(l__cmd1,shell=True,stdout=PIPE).communicate()[0]
#l__cmd1 = "[\"C:\\Tools\\Sysinternalsuite\\psexec\",\"\\\\\\"%s"\",\"-nobanner\",\"ls\",\"-al\","%s"\"]" % (l__sp,l__traces)
#print 'La vies est -->'+l__cmd1
#l__cmd1_WithCall = "\'psexec\",\"\\\\\\"%s"\",\"-nobanner\",\"ls\",\"-al\" "%s"\'" % (l__sp,l__traces)
l__cmd1_WithCall = "\'psexec \\\%s -nobanner ls -al %s\'" % (l__sp,l__traces)
#l__cmd1_WithCall = "\"psexec\",\"\\\%s,\"ls\",\"-al\",%s" % (l__sp,l__traces)
print 'l__cmd1_WithCall-->',l__cmd1_WithCall
p5=call(l__cmd1_WithCall,shell=True)
print '---->',p5,'<-----'
except:
print '\n'+l__sp+' Can\'t reach it !\n'
The above code gives me error as I am trying to get the last modified date of some files from a Windows server to a remote Windows server. I am on Windows using psexec but maybe they are other solutions to get such information.
I tried using subprocess.call, subprocess.popen, subprocess.check_out
and all give me errors, but when I tried to type directly the command on cmd it is working fine.