Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hi... i m trying to make a batch file which will move my (2 files on 2 different servers which are in C:test.log) log files on server's c:\backup. It will rename it to current date_in.log & in Current date_out.log format after that it will copy those renamed files on my local pc from where ill be executing this batch file.
well what worse i need is it will ask for a user name after matching specific user name it will execute the batch file otherwise it will exit.
what i have managed to make so far is here
===========================================
@echo off
setLocal EnableDelayedExpansion
set Pdate=%date:~4,2%%date:~7,2%%date:~10,4%%1
COLOR 1f
REM ECHO ---- THIS PROGRAM MUST RUN BY THE SYSTEMADMINISTRATOR ONLY ----
echo.
echo.
echo.
echo.
echo.
set cmd=xcopy /q /s /c /d /e /h /i /r /y
set a=\\server1\c$\test.log
set b=\\server1\c$\backup\
set c=\\server2\c$\test.log
set d=\\server2\c$\backup\
set e=c:\backuplogsmove /y %a% %b%\%Pdate%_in.log
Move /y %c% %d%\%Pdate%_out.log%copycmd% %b%\%Pdate%_in.log %e%
%copycmd% %d%\%Pdate%_out.log %e%pause>NUL
==================================
first of all above stated also not working hehe sorry for that... and the main thing what to add so that it can ask for the specified usernames and than executes itself or else exit..like if i enters username testuser which is already in our batch file, if the username matches if will go further otherwise it will exit the batch program..
you kind help would be highly appreciated.
thank you
Chow....!!!

I suppose this next line is intended to avoiding typing the xcopy syntax.
[1] Using an internal or external command like CMD is a BAD idea.
[2] xcopy is not what you need.set cmd=xcopy /q /s /c /d /e /h /i /r /y
::===========================
What you need is:copy %b%\%Pdate%_in.log %e%
copy %d%\%Pdate%_out.log %e%==================================
To get and check user:set /p UN= user name ?
if not !UN!'==testuser' goto :eof
=====================================
If at first you don't succeed, you're about average.M2

thanx for yo help...
actually i tried the way you told me but getting this kind of errors when i enters today's date
============================================
PLEASE ENTER DATE : - 07312008
The system cannot find the file specified.
'"\07312008_in.log"' is not recognized as an internal or external command,
operable program or batch file.
'"\07312008_out.log"' is not recognized as an internal or external command,
operable program or batch file.
=============================================and sorry i wrote the cmd variable actually it was copycmd variable i just 4got to put copy as i know dat to make a system command or predefined variable is not allowed... but still its not copying...
Chow....!!!

So what have you got now?
=====================================
If at first you don't succeed, you're about average.M2

ACTUALLY let me put here my whole file so that you can understand
================================
set /p UN= user name ?
if not !UN!'==testuser' goto :eof
if EXIST goto DOset call1=xcopy /q /s /c /d /e /h /i /r /y
set f=\\admin3\c$\IACopyL*.logset h=\\admin3\c$\IAcopylog_IN
set e=\\admin\c$\IACopy.Log
set g=\\admin\c$\IAlog_out\
set a=C:\backup\logs\
REM COPYING LOG FILES TO THEIR SPECIFIC LOCATIONS (PLEASE REFER THE PATHOF THE VARIABLES FOR THE LOCATIONS)
rem color ba
:DO
%call1% %f% %a%
%call1% %e% %a%REM RENAMING THE LOG FILES WITH CURRENT DATE
ren %a%\IACopyLog.log %Pdate%_in.log
ren %a%\iacopy.log %Pdate%_out.log%call1% %a%\%Pdate%_in.log %h%
%call1% %a%\%Pdate%_out.log %g%rem i have put remark so that it wont delete in testing batch file later on it will be unremarked
rem del /s /q "%f%"
rem del /s /q "%e%"=======================================
so when i executes it asks me to enter username but after that its doing NOTHING
if i disables entering username to test further... the xcopy command also not working at all... i tried to copy command but my senior told me that what will be the ERRORCONTROL to you copy or move command... now i dont know what to answer them... or how to solve dis out... actually we are having 5 ADMINISTRATORS working 24/7 so i need to put all 5's usernames to this file dat also i need to manage and put them in a log file which will show us that who had run the batch file at wat time... i think its being much complex now.. hhehehe sorry if i am asking a lot...
so if i want to use copy or move command rather than xcopy than how to set the errorcontrol which will tell me that here the batch file got the errors or sumthing like that.
so now wat you say... !Chow....!!!

What is this trying to do:
if EXIST goto DO
=====================================
If at first you don't succeed, you're about average.M2

yea if a user enters username testuser than it will execute the commands or else it will exit did i made it right or its wrong ?
or else guide me how can i specify 5 usernames which will be entered by USER and if from those 5 usernames any username is not in list than it will exit otherwise it will execute the batch file by verifying the username which is entered by USER
K2™
System/Network Engineer

same question
=====================================
If at first you don't succeed, you're about average.M2

not getting your point dear... do you want me to remove that or sumthing else...?
K2™
System/Network Engineer

What is this trying to do:
if EXIST goto DO
=====================================
If at first you don't succeed, you're about average.M2

yea if the username exists dan it will point itself to DO string which is written in batch file
K2™
System/Network Engineer

Okie... i have managed that thing to verify the username now... but can you guide me how can i make it a LOG file in which it will save a log file which user had run the batch file on which date ?
========================
set /p UN= PLEASE PROVIDE YOUR IDENTIFICATION :-
if /I %UN%'==testuser1' CALL :do
if /I %UN%'==testuser2' CALL :do
if /I %UN%'==testuser3' CALL :do
if /I %UN%'==testuser4' CALL :do
if /I %UN%'==testuser5' CALL :do
if /I %UN%'==testuser6' CALL :do
) ELSE
goto :error
)
========================K2™
System/Network Engineer

>> %UN% echo %date%
=====================================
If at first you don't succeed, you're about average.M2

okie... i have managed this issue and completed my self.. ill post the whole batch file tomorrow as rite now m not at my job.
thanks a lot for your support dear
K2™
System/Network Engineer

here is the batch file i managed to make so far for any one who wants to use it
=================
@echo off
TITLE GENERATE LOG -set Pdate=%date:~4,2%%date:~7,2%%date:~10,4%%1
COLOR 1fNET USE K: \\server1\C$
cls
NET USE j: \\server2\C$
cls
echo.
ECHO ---- THIS PROGRAM MUST RUN BY THE SYSTEM ADMINISTRATOR ONLY ----
echo.
echo.
echo.
echo.
echo.echo.
echo.
echo.
echo.
echo.set /p UN= PLEASE PROVIDE YOUR IDENTIFICATION :-
if /I %UN%'==testuser1' CALL :do
if /I %UN%'==testuser2' CALL :do
if /I %UN%'==testuser3' CALL :do
if /I %UN%'==testuser4' CALL :do
if /I %UN%'==testuser5' CALL :do
if /I %UN%'==testuser6' CALL :do
) ELSE
goto :error
)
REM COPYING LOG FILES TO THEIR SPECIFIC LOCATIONS
color ba
:DO
k:
MOVE /Y test.log K:\locopy~1\%Pdate%_in.log
copy /y K:\locopy~1\%Pdate%_in.log "C:\Logs\brd" >>"C:\Logs\%Pdate%_%UN%.LOG"
cls
j:
MOVE /Y iacopy.log J:\IAlog_~1\%Pdate%_out.log >>C:\TEST.LOG
copy /y J:\lolog_~1\%Pdate%_out.log "C:\Logs\brd" >>"C:\Logs\%Pdate%_%UN%.LOG"
clsNET USE K: /delete /y
CLS
NET USE j: /delete /y
COLOR 1fecho.
echo.
REM GENERATING OUTPUT TO ADMINISTRATOR THAT THE TASK SUCCESSFULLY COMPLETED
echo - LOGS HAVE BEEN SUCCESSFULLY GENERATED -
echo --------------------
echo.
echo.
echo.
echo.
echo.
echo -- THANK YOU "%UN%" PLEASE PROCESS TAT NOW --
echo.
echo ---- PRESS ANY KEY TO EXIT ----
pause>NUL
exit
:error
NET USE K: /delete /y
CLS
NET USE j: /delete /y
cls
echo.
echo.
echo.
echo.
echo.
echo.
echo.
ECHO ---- "%un%" YOU ARE NOT ALLOWED TO PROCESS LOG FILES ----
echo.
echo.
echo.
echo ---- PLEASE CONTACT SYSTEM ADMINISTRATOR----
echo.
pause>NUL
==========================I hope any one can suggest me any ideas for how can I manage to as ask this batch file the Active Directory user names and passwords i think its not possible by batch file or else any one had done before can suggest something.
K2™
System/Network Engineer

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |