Page 1 of 1
MS-Dos script to run command
Posted: 04 Aug 2011 07:34
by kouliscon
Hello all
I need help by someone if possible for the following:
I need to run a command of copy at a .bat file only if the user which logged in that computer is the same name as the computername.
So something like that:
If %username% = %computername% then goto 1 if not 2
1
robocopy c:\docs d:\docs *.*
end
2
end
Can anybody help?
Thanks
Re: MS-Dos script to run command
Posted: 04 Aug 2011 08:10
by Ed Dyreen
'
Code: Select all
If /i ["%username%"] == ["%computername%"] (
::
robocopy c:\docs d:\docs *.*
) else (
::
echo.commands please...
)
Code: Select all
:main ()
::(
If /i ["%username%"] == ["%computername%"] (
::
call :function1 $parameters
) else call :function2 $parameters
::
pause
::)
exit /b %$error%
:function1 ( $parameters )
::(
robocopy c:\docs d:\docs *.*
::)
exit /b %$error%
:function2 ( $parameters )
::(
echo.commands please...
::)
exit /b %$error%
Re: MS-Dos script to run command
Posted: 04 Aug 2011 10:00
by kouliscon
thx a lot i will try them and let you know.
i need another help pls.
at the command where is the robocopy i have:
robocopy c:\docs d:\docs *.* /log:d:\docs\log\%username%.log
is there a way to save this %username%.log each day a different file
So if Monday today to be
%username%Mon.log
if Tuesday
%username%Tue.log
the reason is i want to keep a weeks old the logs for verification.
Thx in advance
Re: MS-Dos script to run command
Posted: 04 Aug 2011 11:19
by Ed Dyreen
'
That's doable:
Code: Select all
@echo off
for /f "tokens=1 delims= " %%! in (
"%date%"
) do set "$File=%username%_%%~!.LOG"
echo.$File=%$File%_
You are now ready to over/write this log :)
This could help:
http://www.dostips.com/DtTipsDateTime.php
Re: MS-Dos script to run command
Posted: 04 Aug 2011 11:28
by kouliscon
Hello
Thx for the fast reply.
I need this new log per day to be created when I run the robocopy command.
In other words
Robocopy c:\data d:\files /log:d:\data\log\%username%_%%~.log
You think you can modify it?
Thx for the link.
Re: MS-Dos script to run command
Posted: 04 Aug 2011 11:33
by Ed Dyreen
'
Code: Select all
@echo off
for /f "tokens=1 delims= " %%! in (
"%date%"
) do set "$LOG.File=%username%_%%~!.LOG"
If /i ["%username%"] == ["%computername%"] (
::
Robocopy "c:\data" "d:\files" /log:"d:\data\log\%$LOG.File%"
)
I never use robocopy so I'm unsure /log: will accept quoted params, it should though...
I advice using quotes by default otherwise you'll get into problems when the path contains spaces.
Re: MS-Dos script to run command
Posted: 04 Aug 2011 11:36
by kouliscon
Thx a lot for all the help.
I will try them and let you know.
Re: MS-Dos script to run command
Posted: 16 Aug 2011 06:33
by kouliscon
Hello
Sorry for the late responce but i was away.
Out of the 4 scripts which you wrote below the first 2 are working ok.
the last one which i am interested for the log i can tell you the following:
1) it doesnt copy the copy from location 1 to location 2.
2) it does creat a log file at location /log:"d:\data\log\%$LOG.File%" but the name of the file is %$LOG.File% maybe that can point you where the mistake is.
Thx in advance