Solved

Need Help Creating Script

Posted on 2014-12-12
10
222 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
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 23

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
 

Author Comment

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

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
NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

 
LVL 23

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 23

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 23

Expert Comment

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

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Utilizing an array to gracefully append to a list of EmailAddresses
This script checks a path to see if a folder exists. If the folder does exist you will get output "The folder has previously been created. No action taken" If not it will create the folder. Then adds one user modify permission to the folder. It …
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to count occurrences of each item in an array.

914 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

17 Experts available now in Live!

Get 1:1 Help Now