MS-Dos script to run command
Moderator: DosItHelp
MS-Dos script to run command
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
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
'
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%
Last edited by Ed Dyreen on 04 Aug 2011 11:27, edited 1 time in total.
Re: MS-Dos script to run command
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
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
'
That's doable:
This could help:
http://www.dostips.com/DtTipsDateTime.php
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 :)
http://www.dostips.com/DtTipsDateTime.php
Last edited by Ed Dyreen on 04 Aug 2011 11:39, edited 1 time in total.
Re: MS-Dos script to run command
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.
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
'
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.
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 advice using quotes by default otherwise you'll get into problems when the path contains spaces.
Last edited by Ed Dyreen on 04 Aug 2011 11:46, edited 3 times in total.
Re: MS-Dos script to run command
Thx a lot for all the help.
I will try them and let you know.
I will try them and let you know.
Re: MS-Dos script to run command
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
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