GOTO batchscript
:batchscript
Yup, the other day I had to do some googling to find out how to write some nasty batch script. (GOTO ftw). It’s pretty simple, just enough to prompt you for y/n and then an IF statement to see you typed y. I did this because ideally when you shut the computer down it prompts you to ask if you want to do a sync or not. This is so that if you just want to reboot, you don’t have to wait through it to sync, plus if you haven’t actually changed anything you don’t need to do a check. After writing the script I added it to the logoff scripts so that it would be done when I shutdown. Unfortunately it doesn’t run those scripts until after it shutsdown the whole GUI thing, so it basically just freezes while it waits for you to type ‘y’ but you can’t actually type it. So that didn’t work. I think I’ll just change it so that you just run the file, it does and update and then shutsdown the computer when it’s finished. Or just add it to the task sceduler. It probably uses a small enough amount of resources to just do it’s thing regardless of what I’m doing and it shouldn’t impact whatever I’m doing (unless I’m trying to play Crysis maybe).
Setting up cwrsync was a little strange because rsync still thinks it’s running in linux so you have to deal with the whole absoulte path thing e.g. /usr/… Solution: use absolute path ‘a la unix’, replace backslashes (\) with slashes (/) and put -/cygdrive/- in front of the drive letter.
@echo off
SET /P Choice=Do you want to do a backup before shutting down (y/N)?
IF NOT ‘%Choice%’==’y’ GOTO endSETLOCAL
SET CWRSYNCHOME=”C:\rsync”
SET CYGWIN=nontsec
SET HOME=%HOMEDRIVE%%HOMEPATH%
SET CWOLDPATH=%PATH%
SET PATH=%CWRSYNCHOME%\BIN;%PATH%rsync -av –exclude=*.db –exclude=*.ini “/cygdrive/d/Pictures/” “/cygdrive/z/phill/backups/Pictures”
:end
This is my batch files or .cmd file actally. It syncs up my Pictures folder on my NAS (which has been mapped to Z: drive) with the pictures on my computer. I noticed that when I open up picasa, it seems to change the modified times of the .ini and .db files it puts in the folders. I didn’t see any point to keep these files synced, so I excluded them. Otherwise everytime I opened picasa it would go through and update all these files. Even though they are small, it still takes a while for it to traverse my whole Pictures folder updating these files.
I found that to do this simple task, cwrsync doesn’t actually have to be installed. You just need the binary and some of the .dll files. You don’t need to use the cwrsync server thing either. I guess it just depends on the setup.
Next is to get this going on my parents machine. Hopefully it works in Vista.
Just as a thought, I wonder what would happen if I replaced the the shutdown.exe file with my own one that ran my script and then did shutdown.
Post a Comment