Solved

Need Help Creating Script

Posted on 2014-12-12
10
230 Views
Last Modified: 2014-12-14
Greeting Experts,

I am need of some help creating a script or batch file that can do the following steps below… I not a very good when it comes to script and hoped somebody out there can give me a hand…

1)      Create a folder in the root of C:\drive  called Mbam (i.e. C:\Folder)
2)      Map a network drive ( i.e. net use x: \\Server\fileshare)
3)      Copy the contents of the file share to local C:\mbam folder  
4)      Close the network share
5)      Change directory from C:\ to C:\Folder
6)      Start another bat file called batch.bat
7)      Once batch.bat file has completed Change directory from C:\Folder to C:\Folder\data\logs
8)      Map another network drive (i.e. net use x: \\Server\fileshare2)
9)      copy the log file from local folder to fileshare
10)      Close the network share
11)      Remove the Mbam folder from C:\drive ( i.e. C:\rmdir /S  C:\Folder
0
Comment
Question by:amstoots
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 4
10 Comments
 
LVL 24

Expert Comment

by:NVIT
ID: 40496785
Looks like you pretty much wrote it yourself.

md c:\mbam
net use x: \\Server\fileshare
xcopy /e /y x:\ c:\mbam
net use x: /delete /yes
cd c:\folder
call batch.bat
cd C:\Folder\data\logs
net use x: \\Server\fileshare2
xcopy /e /y . x:\
net use x: /delete /yes
rd c:\mbam

Open in new window

0
 

Author Comment

by:amstoots
ID: 40497998
The script worked pretty good.... but is there a way to rename the log file to the device name its running on and the date ( i.e. DeviceName-MM-dd-YYYY.txt)
0
 
LVL 24

Expert Comment

by:NVIT
ID: 40498054
Glad it's working.

For the log filenames... I assume  your log filename is set in batch.bat. You can add this to it:

Put the CALL before where you set your log filenames:
call :SetDateVar
echo LogFN=%LogFN%

Open in new window


Put SetDateVar somewhere near the end. You may have to add goto :eof depending where you put it. Note: This example is verbose for clarification.

:SetDateVar
set DateVar=%date%
set YYYY=%DateVar:~10,4%
set MM=%DateVar:~4,2%
set DD=%DateVar:~7,2%
set LogFN=%ComputerName%-%MM%-%DD%-%YYYY%.txt
goto :EOF

Open in new window

0
Forrester Webinar: xMatters Delivers 261% ROI

Guest speaker Dean Davison, Forrester Principal Consultant, explains how a Fortune 500 communication company using xMatters found these results: Achieved a 261% ROI, Experienced $753,280 in net present value benefits over 3 years and Reduced MTTR by 91% for tier 1 incidents.

 

Author Comment

by:amstoots
ID: 40498116
Would I put this in front of c:\ rename
0
 
LVL 24

Expert Comment

by:NVIT
ID: 40498145
If you post your code at that area it would expedite.
Also... If you run this multiple times a day, we'd have to revise the log filename to include the time.
0
 
LVL 24

Expert Comment

by:NVIT
ID: 40498163
Yes. If nothing happens after the rename you can put everything under SetDateVar before the rename
0
 

Author Comment

by:amstoots
ID: 40498501
Ok, I have been playing around with this attempting to add the ":SetDateVar" in the batch.file.. Not sure how it needs to be added to the existing code...


md c:\mbam
net use x: /delete /yes
net use x: \\server\fileshare
xcopy /e /y x:\ c:\folder
net use x: /delete /yes
cd c:\folder
file.exe /update -silent
file.exe /scan -flash -log -silent -remove 
cd C:\folder\data\logs
 rename  ([b] Would I Place the code Here[/b])
net use x: \\Server\Fileshare2
xcopy /e /y file-*.txt x: 
net use x: /delete /yes
cd C:\
rd /S /q c:\folder

Open in new window



:SetDateVar
set DateVar=%date%
set YYYY=%DateVar:~10,4%
set MM=%DateVar:~4,2%
set DD=%DateVar:~7,2%
set LogFN=%ComputerName%-%MM%-%DD%-%YYYY%.txt
goto :EOF

Open in new window

0
 
LVL 24

Accepted Solution

by:
NVIT earned 500 total points
ID: 40498503
If C:\folder\data\logs is where your log file is, then yes.
md c:\mbam
net use x: /delete /yes
net use x: \\server\fileshare
xcopy /e /y x:\ c:\folder
net use x: /delete /yes
cd c:\folder
file.exe /update -silent
file.exe /scan -flash -log -silent -remove 
cd C:\folder\data\logs

set DateVar=%date%
set YYYY=%DateVar:~10,4%
set MM=%DateVar:~4,2%
set DD=%DateVar:~7,2%
set LogFN=%ComputerName%-%MM%-%DD%-%YYYY%.txt

ren YourLogFilename.txt %LogFN%

net use x: \\Server\Fileshare2
xcopy /e /y file-*.txt x: 
net use x: /delete /yes
cd C:\
rd /S /q c:\folder

Open in new window

0
 

Author Closing Comment

by:amstoots
ID: 40498595
The script works perfect ... thanks for all the help....
0
 
LVL 24

Expert Comment

by:NVIT
ID: 40498649
You're welcome, amstoots.. It has been a pleasure.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How to know the backup date of a restored DB? 4 47
Exporting days since LastLogonTime 5 30
Powershell Code 4 30
[IIS FTP 7.5] Change FTP home dir for 300 accounts 7 27
Synchronize a new Active Directory domain with an existing Office 365 tenant
In threads here at EE, each comment has a unique Identifier (ID). It is easy to get the full path for an ID via the right-click context menu. However, we often want to post a short link within a thread rather than the full link. This article shows a…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

740 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question