Accessing Network Drives via Scheduled Python Task

As previously mentioned, I have a scheduled nightly backup that is written in Python.  Most of it has been working fine but I had not gotten it to copy files to network drives.  I finally got around to correcting that part.  My first attempt was just to map the network drives for the user account that is used to run the task.  No good.

My second attempt was to call a .bat file from python before accessing the network drives and that worked.

The batch file has two lines (one for each network drive):

net use n: \\domain1\sharename mypassword /USER:domain\username
net use t: \\domain2\sharename mypassword /USER:domain\username

And my python script includes two lines to call it before I access the network locations:

import os
os.system('C:/cwi5_bk/mapDrive.bat')
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s