Python Forum
Problem executing a script on a remote host
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Problem executing a script on a remote host
#4
Update.
Here is a file I'm trying to execute remotely. It runs fine, no errors if executed manually, no errors.
but if called remotely it does nothing. Sad
I'm not sure how to debug it. Cry

script:
import subprocess,socket,shutil,time 
import os.path

drl ='A'
e_ip ='XX.X.X.X'
mp_string = "net use"+" "+drl+":"+" \\\\"+e_ip+"\\"+"C$"	# <-- String to mount
dr_one ="\\\\"+e_ip+"\\"+"C$"+"\\"+"02"+"\\"+"logs"	# <-- First Directory to get logs from

delete_st = "net use"+" "+drl+":"+" "+"/delete /yes"

sys_name = socket.gethostname()
print(sys_name)                   # <-- System name

make_dp ='C:\\02\\dt\\'+sys_name  # <-- Directory to Copy Files to...
if not os.path.exists(make_dp):
    os.mkdir(make_dp)  

monitor = 0	
with open('C:\\02\\dt\\Num_OF_Files_Copied.txt','w') as num_of_f_copied :  # <- Log files for the script 
    num_of_f_copied.write(sys_name+'\n')
    try:
        subprocess.call(mp_string,shell=True)   # <-- Mounting Cell

        if dr_one :
            print(' Dir Exits -',dr_one)			
            num_of_f_copied.write(' Dir Exits -'+dr_one+'\n')		
            
            for items in os.listdir(dr_one) :  		
                items=items.strip()
                itemspath = os.path.join(dr_one,items)				
                #print(' ALL ITEMS', itemspath)  
			
                if os.path.isfile(itemspath):
                    items=items.strip()
                    num_of_f_copied.write(' ITEMS -'+items+'\n') 			
                    #print(' File Only ->', items)			
                    if 'Monitor.' in items : 	# <-- Monitor is in the name of the files
                        print(' Monitor Files -> ',itemspath)
                        num_of_f_copied.write(' MONITORS -> '+itemspath+'\n')
                        
                        try :  						
                            shutil.copy(itemspath,make_dp)
                            num_of_f_copied.write(' Copying Files -> '+itemspath+'\n')								
                            monitor+=1
                        except OSError as cpf :
                            print(' Failed to copy files','\n')
                            num_of_f_copied.write(' Failed to copy files'+'\n')							
    except OSError as er :
        print(" Error scanning or Copying ->", er)			
print(' Number of files copied ->',monitor)
subprocess.call(delete_st)	
Thank you.
Reply


Messages In This Thread
RE: Problem executing a script on a remote host - by tester_V - Sep-26-2021, 04:25 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Triggering a ps1 script in remote windows server via http python request jasveerjassi 1 383 Jan-26-2024, 07:02 PM
Last Post: deanhystad
Question How can I import a variable from another script without executing it ThomasFab 12 7,841 May-06-2022, 03:21 PM
Last Post: bowlofred
  where to host my python script tomtom 1 1,270 Feb-09-2022, 06:45 AM
Last Post: ndc85430
  Script stop work after 3 actioins - PLEASE WHERE IS THE PROBLEM? rondon442 0 1,568 Sep-27-2021, 05:40 PM
Last Post: rondon442
  Failing to connect to a host with WMI tester_V 6 4,399 Aug-10-2021, 06:25 PM
Last Post: tester_V
  cant use ping, sudo or other commands in remote shell script. throwaway34 7 3,619 May-17-2021, 11:29 AM
Last Post: throwaway34
  problem with sphinx and file directory in script kiyoshi7 0 2,296 Mar-11-2021, 03:52 PM
Last Post: kiyoshi7
  problem about slope in python script for bitcoin trading fisher_garry 1 2,513 Sep-02-2020, 01:39 PM
Last Post: fisher_garry
  Problem running script within console koepjo 3 9,915 Mar-26-2020, 07:11 AM
Last Post: koepjo
  How to gather information from remote host using ansible module in python amritjsr 0 2,047 Jul-20-2019, 01:17 AM
Last Post: amritjsr

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020