Solved

Need Help Creating Script

Posted on 2014-12-12
10
223 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 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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

I thought I'd write this up for anyone who has a request to create an anonymous whistle-blower-type submission form created using SharePoint 2010 (this would probably work the same for 2013). It's not 100% fool-proof but it's as close as you can get…
A brief introduction to what I consider to be the best editor for PowerShell.
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…

773 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