Solved

Need Help Creating Script

Posted on 2014-12-12
10
242 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 25

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 25

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
What, When and Where - Security Threats from Q1

Join Corey Nachreiner, CTO, and Marc Laliberte, Information Security Threat Analyst, on July 26th as they explore their key findings from the first quarter of 2017.

 

Author Comment

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

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 25

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 25

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 25

Expert Comment

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

Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

This script can help you clean up your user profile database by comparing profiles to Active Directory users in a particular OU, and removing the profiles that don't match.
A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

635 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