Solved

Need Help Creating Script

Posted on 2014-12-12
10
219 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
  • 6
  • 4
10 Comments
 
LVL 23

Expert Comment

by:NVIT
Comment Utility
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
Comment Utility
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 23

Expert Comment

by:NVIT
Comment Utility
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
 

Author Comment

by:amstoots
Comment Utility
Would I put this in front of c:\ rename
0
 
LVL 23

Expert Comment

by:NVIT
Comment Utility
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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 23

Expert Comment

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

Author Comment

by:amstoots
Comment Utility
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 23

Accepted Solution

by:
NVIT earned 500 total points
Comment Utility
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
Comment Utility
The script works perfect ... thanks for all the help....
0
 
LVL 23

Expert Comment

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

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
This article will help you understand what HashTables are and how to use them in PowerShell.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

772 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now