[Tutorial] How to use loginscript and Robocopy

FTP Server, File Server, DDNS, SAMBA, AFP, NFS
Locked
User avatar
thorejoha
Know my way around
Posts: 144
Joined: Mon Mar 24, 2008 9:41 pm

[Tutorial] How to use loginscript and Robocopy

Post by thorejoha »

Please note. Never start .bat and .cmd files from someone before you know whats inside of it.
Rightclick on the file and chose edit. This will open the file in notepad or something for editing.


Tips and tricks about Script, Clockupdate, updates and Robocopy.
  • Do you have problems about holding all the computers in your network up to date.
  • Is there always problems with someone never update there computer.
  • Maybe Dos is the solution for you.
  • Dos is very easy to use, and dont use a lot of memory like other programs.
  • Do you have a Qnas, and want everyone to have the same shares.
  • Just fire up Notepad, and start editing.
I use a DOS loginscript for every computer in my homenetwork.
This gives me the ability to hold the users updated with different things they need.
If I want some changes for the users, I can only change the loginscript, and everything works next time the start the computer.
I also use robocopy too backup files and folders.
If you are using robocopy and have problems with robocopy against Qnap servers, use /FFT in your copylines when copying from windows filesystem too Qnas. This will eliminate the problem with Robocopy just copy the same files every time.


In this Tutorial I have added an example of a standard loginscript for homecomputers.
Login.zip

What will the script do:

1. Updates the clock against NTP timeserver
2. update AVG viruskontrol version 9
3. Keep your shares up to date. If you use robocopy, you can mirror your files and folder to a folder on your Qnas.

Why use the script?
1. You will always have updated clock on your computer
2. Your AVG 9 will stay updated at all time.
3. Make a standard script to add mapping for every computer in your network.
4. Be shure you have a backup of your computers files and folders


How to use the script.
1: Unzip the files.

2: Copy "Standard_login.cmd" to a place on your computer like c:\programs or something

3. Rightclick om the file and create shorcut.

4. Rightclick on the shortcut and chose properties.


5. Chose run minimized window. This will make the file running minimized in the startup


3: Copy the shortcut to startup in your computer.
Start -> program-> startup

4: To do this: Rightclikk and open folder "all users" in the menu
Paste the shortcut into the folder.

5: Restart your computer or dobleclick on the file. The script starts running.


6: If you get some safety warnings . Chose accept every time.


Thats all


Now you can add your own Dos lines to the script.
I have added some examples in the file.

If there are something you dont want to start, but dont want to delete the lines, Just use REM infront of the line.
See the examplefile

If you wounder how to use a dos command just start CMD and type the command and /? after. this will give you a lot of information how to use it. Example: xcopy /? - Just try out and see it your self.


Things you can add wery easy:

First in all my script I use a wait commando.
The line I use is: ping -n 15 127.0.0.1 >NUL
Because Wlan card use some time before they connect I want the script to wait until its ready.
This command makes the Dos command pause for 15 seconds with just pinging the computer localy.
use your stopwatch to take the time from the script starts, to the Wlan card is ready.
Change the nr 15 in the line, with what time it takes + 3-4 seconds.
Then you now it dont start before the network is ready.


net use = Mapping commando for printers and drives.
Example: "net use X: \\10.0.0.100\Qweb"
This will map your share Qweb as a new drive on the local computer.
You can have as many net use commands as you want.
Just put every one in a new line.

net time = Get time from a another computer or server.
Example: "Net time \\10.0.0.100 /set /y" = Get time from the server with Ipadress 10.0.0.100
and correct your computers clock.


Many of my friends use AVG, and I will have this to update every time they start their computer.
Because of this, I add a line in the loginscript.
Like this for version 9 Norwegian: C:\Programfiler\AVG\AVG9\avgupd.exe
If you want to add this in your own script, please locate where the file "avgupd.exe" is.
The norwegian name for programfiles is programfiler.
Maybe its "C:\Programfiles\AVG\AVG9\avgupd.exe" in the english version - Please let me know,
and i will add it for the tutorial.
If you have some other Viruscontrol, I am shure you will find a updatefile you can run.
Just look in the programs directory for some update.exe name


Another line you can use is: "w32tm /resync /nowait"
This command is realy nice. It updates the clock with your NTP server added in the clock settings for windows.
If your friend dont have a server to use the "net time" command against, you can use this.

If your friend have a computer, but not any server. Just create a litle file and ad the lines like this

Code: Select all

rem: scrip start

ping -n 15 127.0.0.1 >NUL
w32tm /resync /nowait
C:\Programfiles\AVG\AVG9\avgupd.exe
exit

rem: script ends
There is a lot of examples you can use in a login script.
You can also use commands like xcopy and robocopy, to copy files and folders every time a computer start.
If you add something like xcopy c:\data /s \\10.0.0.100\backup it will copy all files and folders to your server.
Just run xcopy /? to find what you want in your line.

Robocopy
robocopydocs.zip
Robocopy.zip
UtilitySpotlight2006_11.zip
You can download he newest robocopy from Microsoft downloadpages.
Just search for rktools.exe download in Google.
Then you will find Windows Server 2003 Resource Kit Tools
You can install this on windows XP.
Windows Vista have robocopy already innstalled.
If you dont want to innstall the complete pack, you download robocopy her in the tutorial ,
and paste in to your c:\Windows directory
Then it will work fine.
I have also added the Robocopy GUI. This makes it even easyer to make scripts.

To test if you have robocopy, just start CMD and type robocopy /?
If you have an answer about how too use it, its allready in your Windows directory.
If not, just innstal the rktools file or one of the files from here.

Robocopy is a much more powerfull copyprogram from Microsoft.
If you have robocopy innstalled, it is easy to make copylines in the scripts.
Just remember if you having trouble try using /FFT in the line.
/FFT :: assume FAT File Times (2-second granularity).

Example

Code: Select all

robocopy.exe "c:\testfolder" "\\10.0.0.90\sharename\testfolder" /S /XO /W:3 /R:3 /FFT 
- Put a copy off all files and folders from source to the chosen share.
  • /S = Choose all files and folders in the directorytree
  • /XO = Do not copy files if they already exist with no changes.
  • /W:3 Will make robocopy wait 3 seconds before it tries too copy a file if its busy.
  • /R:3 How many times Robocopy will try to copy a file if its busy.
  • /FFT Add 2 sec delay in the file. Eliminate the problem if your script copy the same files time after time, even if there is no changes. necessary if you copy from Windows filesystem too Linux (Qnas)

Mirroring

Code: Select all

robocopy.exe "c:\testfolder" "\\10.0.0.90\sharename\testfolder" /S /MIR /XO /W:3 /R:1 /FFT 
- This create a mirror of the source on the destination. Read more about /Purge
because using /MIR will delete files in the destination folder if they are remowed from source folder.
/PURGE :: delete dest files/dirs that no longer exist in source.
/MIR :: MIRror a directory tree (equivalent to /E plus /PURGE).
Dont use this command to a share\folder you already have data in. If the folder have data, NOT INCLUDED in the sourche folder, ROBOCOPY will delete them. BE CAREFUL WITH THIS.


The command /FFT is necessary because you run copy to a different filesystem then Windows.

If there are some other things you want Robocopy to do, just start CMD - Type robocopy /? and you will see a lot of things you can use.
robocopydocs.zip
Login.zip
Robocopy.zip
Some links to more "How to: MSDos"
http://www.computerhope.com/msdos.htm
http://en.wikipedia.org/wiki/MSdos


-------------------------------------------------------------------------------
ROBOCOPY :: Robust File Copy for Windows :: Version XP010
-------------------------------------------------------------------------------

Started : Sun Mar 21 12:57:11 2010

Usage :: ROBOCOPY source destination [file [file]...] [options]

source :: Source Directory (drive:\path or \\server\share\path).
destination :: Destination Dir (drive:\path or \\server\share\path).
file :: File(s) to copy (names/wildcards: default is "*.*").

::
:: Copy options :
::
/S :: copy Subdirectories, but not empty ones.
/E :: copy subdirectories, including Empty ones.
/LEV:n :: only copy the top n LEVels of the source directory tree.

/Z :: copy files in restartable mode.
/B :: copy files in Backup mode.
/ZB :: use restartable mode; if access denied use Backup mode.

/COPY:copyflag[s] :: what to COPY (default is /COPY:DAT).
(copyflags : D=Data, A=Attributes, T=Timestamps).
(S=Security=NTFS ACLs, O=Owner info, U=aUditing info).

/SEC :: copy files with SECurity (equivalent to /COPY:DATS).
/COPYALL :: COPY ALL file info (equivalent to /COPY:DATSOU).
/NOCOPY :: COPY NO file info (useful with /PURGE).

/PURGE :: delete dest files/dirs that no longer exist in source.
/MIR :: MIRror a directory tree (equivalent to /E plus /PURGE).

/MOV :: MOVe files (delete from source after copying).
/MOVE :: MOVE files AND dirs (delete from source after copying).

/A+:[RASHNT] :: add the given Attributes to copied files.
/A-:[RASHNT] :: remove the given Attributes from copied files.

/CREATE :: CREATE directory tree and zero-length files only.
/FAT :: create destination files using 8.3 FAT file names only.
/FFT :: assume FAT File Times (2-second granularity).
/256 :: turn off very long path (> 256 characters) support.

/MON:n :: MONitor source; run again when more than n changes seen.
/MOT:m :: MOnitor source; run again in m minutes Time, if changed.

/RH:hhmm-hhmm :: Run Hours - times when new copies may be started.
/PF :: check run hours on a Per File (not per pass) basis.

/IPG:n :: Inter-Packet Gap (ms), to free bandwidth on slow lines.

::
:: File Selection Options :
::
/A :: copy only files with the Archive attribute set.
/M :: copy only files with the Archive attribute and reset it.
/IA:[RASHCNETO] :: Include only files with any of the given Attributes set.
/XA:[RASHCNETO] :: eXclude files with any of the given Attributes set.

/XF file [file]... :: eXclude Files matching given names/paths/wildcards.
/XD dirs [dirs]... :: eXclude Directories matching given names/paths.

/XC :: eXclude Changed files.
/XN :: eXclude Newer files.
/XO :: eXclude Older files.
/XX :: eXclude eXtra files and directories.
/XL :: eXclude Lonely files and directories.
/IS :: Include Same files.
/IT :: Include Tweaked files.

/MAX:n :: MAXimum file size - exclude files bigger than n bytes.
/MIN:n :: MINimum file size - exclude files smaller than n bytes.

/MAXAGE:n :: MAXimum file AGE - exclude files older than n days/date.
/MINAGE:n :: MINimum file AGE - exclude files newer than n days/date.
/MAXLAD:n :: MAXimum Last Access Date - exclude files unused since n.
/MINLAD:n :: MINimum Last Access Date - exclude files used since n.
(If n < 1900 then n = n days, else n = YYYYMMDD date).

/XJ :: eXclude Junction points. (normally included by default).

::
:: Retry Options :
::
/R:n :: number of Retries on failed copies: default 1 million.
/W:n :: Wait time between retries: default is 30 seconds.

/REG :: Save /R:n and /W:n in the Registry as default settings.

/TBD :: wait for sharenames To Be Defined (retry error 67).

::
:: Logging Options :
::
/L :: List only - don't copy, timestamp or delete any files.
/X :: report all eXtra files, not just those selected.
/V :: produce Verbose output, showing skipped files.
/TS :: include source file Time Stamps in the output.
/FP :: include Full Pathname of files in the output.

/NS :: No Size - don't log file sizes.
/NC :: No Class - don't log file classes.
/NFL :: No File List - don't log file names.
/NDL :: No Directory List - don't log directory names.

/NP :: No Progress - don't display % copied.
/ETA :: show Estimated Time of Arrival of copied files.

/LOG:file :: output status to LOG file (overwrite existing log).
/LOG+:file :: output status to LOG file (append to existing log).

/TEE :: output to console window, as well as the log file.

/NJH :: No Job Header.
/NJS :: No Job Summary.

::
:: Job Options :
::
/JOB:jobname :: take parameters from the named JOB file.
/SAVE:jobname :: SAVE parameters to the named job file
/QUIT :: QUIT after processing command line (to view parameters).

/NOSD :: NO Source Directory is specified.
/NODD :: NO Destination Directory is specified.
/IF :: Include the following Files.







[Tutorial] How to make a loginscript in MS Dos [Tutorial] How to hold your computer up to date [Tutorial] How to hold AVG up to date [Tutorial] How to use Robocopy [Tutorial] Problems with robocopy and Qnas
You do not have the required permissions to view the files attached to this post.
My Tutorials:
Tutorial:How to config webserver on Qnas!
Tutorial:How to use loginscript and Robocopy
Tutorial:How to set up DynDNS on Qnas!
Tutorial:How to move large files on Qnas!
Tutorial:How to edit apache.conf on Qnas!
Tutorial:How to seed files and folders in Qget
Tutorial:How to fix slow wordpress on Qnas!

See also Don`s How To guide!
And Frisbe`s signatur for more Tips and Tricks!
_______________________________________
NAS nr 1: TS-109 Pro FW: 3.1.0 Build 0708T - 1 x Seagate 500Gb + 1X USB 500GB Qraid
NAS nr 2: TS-109 Pro II FW: 3.1.0 Build 0708T - 1 x Western Digital 1Tb
____________________________________________________________________________
User avatar
spoon.uk
Been there, done that
Posts: 992
Joined: Tue Jan 06, 2009 7:14 pm
Location: London, United Kingdom
Contact:

Re: [Tutorial] How to use loginscript and Robocopy

Post by spoon.uk »

Right, firstly this isn't really a logon script, these are added to your domain account rather just startup on a single computer.

IF you have 5 computers and need something changing you gotta do it 5 times, you get the idea.

To pause your script use sleep command rather than pinging localhost, its much more elegant.

You script after you filter out all comments and echo, its literally 4 lines...

Code: Select all

ping -n 20 127.0.0.1 >NUL
w32tm /resync /nowait
net use X: \\Qnap_ip_adress\sharename 
C:\Programfiler\AVG\AVG9\avgupd.exe
Also this doesn't make any sense:

Code: Select all

cls
echo off
cls
Your script its really difficult to read because of the way you've structured it. For someone that started with DOS as first OS, its definitely looking rather awful.

If certain share you're trying to connect the on your NAS requires authentication your script will fail as no credentials are supplied with net use command.

From your example:
Example: "net use X: \\10.0.0.100\Qweb"
Quotation marks are not necessary, only the UNC oath needs to be quoted if spaces are present.
sunilmkt
New here
Posts: 7
Joined: Wed Dec 05, 2012 8:06 pm
Contact:

Re: [Tutorial] How to use loginscript and Robocopy

Post by sunilmkt »

It is necessary to keep robocopy.exe to the same folder.
piumpiu
New here
Posts: 4
Joined: Thu Aug 21, 2014 5:32 pm

Re: [Tutorial] How to use loginscript and Robocopy

Post by piumpiu »

I suggest not to use robocopy, but zpaq.
It's a compressor that can hold versions of files, much like time machine.
Locked

Return to “File Sharing”