Page 1 of 2 12>
Topic Options
#170882 - 2006-12-01 10:51 AM Directory creation based on date issue
Pax Offline
Getting the hang of it

Registered: 2006-12-01
Posts: 51
Hey All,

Hoping you can help with my little issue.

I am writing a KiX script to run each day. This script rars up data on one network location and transmits it across the WAN to a new location and puts it in a directory based upon the date, then extracts the data.

While doing this, it logs all the information to a log file on the destination drive in a LOGS directory (funnily enough).

My problem is that while
Code:
MD "$ARCHIVEDRIVE\@YEAR@MONTHNO@MDAYNO"

works fine, where $ARCHIVEDRIVE is a declared drive letter at the top of the script and would produce J:\2006121 for today, I can get no variation of
Code:
$ARCHIVE = @YEAR + "-" + @MONTHNO + "-" + @MDAYNO
$ARCHIVE = @YEAR + @MONTHNO + @MDAYNO
$ARCHIVE = @YEAR@MONTHNO@MDAYNO


Work for producing the same result.

The first code option defines $ARCHIVE as being 2019 (riddle me why that happens), as does the second, while the third gives me 121 on one line and 2006 on the next.

I am using KiXtart 2010 4.50.

Can anyone either help me redefine $ARCHIVE obtaining the correct results as per the MD results, or figure out why my definition of $ARCHIVE isn't defining correctly given I want the output (for today, for example to be 2006121)???? I could even handle if it gave the result of 2006-12-1.

Pax

edit: I should note that I am using the $ARCHIVE variable as a base for creating the rar file, log file and copying the data, and don't really want to use @YEAR@MONTHNO@MDAYNO throughout the entire script if I can help it. Would this really work though considering I cannot get KiX to define it correctly at the top.


Edited by Pax (2006-12-01 10:53 AM)

Top
#170888 - 2006-12-01 02:34 PM Re: Directory creation based on date issue [Re: Pax]
Allen Administrator Online   shocked
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4441
Loc: USA
See if this helps explain your problem.

Code:
? @YEAR + @MONTHNO + @MDAYNO
? vartypename(@YEAR + @MONTHNO + @MDAYNO)
?
? "" + @YEAR + @MONTHNO + @MDAYNO
? vartypename("" + @YEAR + @MONTHNO + @MDAYNO)
 

Top
#170889 - 2006-12-01 02:40 PM Re: Directory creation based on date issue [Re: Allen]
Allen Administrator Online   shocked
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4441
Loc: USA
... and you might even consider adding the following modifications so that the directory names are consistent:

Code:
? "" + @YEAR + right("0" + @MONTHNO,2) + right("0" + @MDAYNO,2)
 

Top
#170966 - 2006-12-04 09:44 AM Re: Directory creation based on date issue [Re: Allen]
Pax Offline
Getting the hang of it

Registered: 2006-12-01
Posts: 51
Hey Allen,

I'll have a look at that today. Thanks for the reply,

Pax

edit: seems the first value is defined as a long, while the second is a string, I can see due to the "null" space at the front. It is weird that KiX defines it differently depending on whether MD is used or we are defining a term internally to the script.


Edited by Pax (2006-12-04 09:50 AM)

Top
#170971 - 2006-12-04 11:28 AM Re: Directory creation based on date issue [Re: Pax]
Pax Offline
Getting the hang of it

Registered: 2006-12-01
Posts: 51
OK, I've decided to leave the dates in the non-corrected format, otherwise I'd have to mess around with the MD command, and due to time pressures for this, I will leave it till a possible new revision of the script.

The next issue I've encountered is

ERROR : expected ')'!
Script: F:\.kix
Line : 103

the lines surrounding 103 are;
Code:
If $REPORTFILE <> $ARCHIVEFILE
	SHELL ("cmd.exe /c " + $SCRIPTROOT + "Blat " + $ARCHIVELOG + " -t " + $SupportEmail + " -f " + $Sender + " -s File_Copy_Error -server " + $EMAILSERVER)
ENDIF
;
;---- Extracting files onto Archive
;
$VARSET = WRITELINE (1, "Extracting " + $ARCHIVEDRIVE + "\" + $ARCHIVE + "\" + $ARCHIVE + ".rar" +  @CRLF)
Shell ("cmd.exe /c " + $SCRIPTROOT + "\unrar.exe e -r " + $ARCHIVEDRIVE + "\" + $ARCHIVE + "\" + $ARCHIVE ".rar " + $ARCHIVEDRIVE + "\" + $ARCHIVE + "\" )
	IF @ERROR = 0
		"....Done"


Line 103 is the Shell (unrar)line, not the 'Blat' shell command. I've got a similar line above which does the rar-ing of the data and can run the unrar command by itself fine, so I'm confused as to where there is a missing ')', or a rogue inserted '(',

Pax


Edited by Pax (2006-12-04 11:34 AM)

Top
#170973 - 2006-12-04 11:37 AM Re: Directory creation based on date issue [Re: Pax]
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11564
Loc: CA
Quote:
I am using KiXtart 2010 4.50.


You may need to double-check confirm all code works as expected. There were numerous changes to copy/move/md/rd and all appear to be working well now in version 4.53 (best to update if you can)

As for the errors you will probably need to post the whole script so we can view where the errors might be.

Top
#170974 - 2006-12-04 12:11 PM Re: Directory creation based on date issue [Re: NTDOC]
Pax Offline
Getting the hang of it

Registered: 2006-12-01
Posts: 51
Script posted below as requested ....

As I alluded to, it gets all the way through up to the unraring part of the script. The servers sit in two untrusted domains.

If anything more is needed let me know. I will probably put the @error and @serror in if there was a failure before sending the email, but at the moment I want to get successfuls working,

Pax

Code:
;:KVIS:Edited on 04/12/2006 09:38:57 by Pax.|E:KVIE:
; This is a test script for moving the archive data
;
;--------------------------------------------------------------------------------------------------------------------
;
;---- Script version 0.2
;---- Created by Pax
;---- Last edit date 04/12/2006 by Pax
;
;---- Declare Variables -------
;
$SCRIPTROOT = "\\server1\path\"
$REPORTSTORE = "\\server2\path"
$ARCHIVESTORE = "\\server3\path"
$REPORTUSER = domain1\user
$ARCHIVEUSER = domain2\user
$REPORTDRIVE = I:
$ARCHIVEDRIVE = J:
$ARCHIVE = "" + @YEAR + @MONTHNO + @MDAYNO
? $ARCHIVE
$ARCHIVELOG = $ARCHIVEDRIVE + "\LOGS\" + $ARCHIVE + ".LOG"
? $ARCHIVELOG
$EmailServer = "our.emailserver.net"
$Sender = "sender@@emailserver.net"
$SupportEmail = "support@@emailserver.net"
$EmailAddress = "recipient@@emailserver.net"
;
;---- If the password for the REPORTUSER account changes on server2, change the password on the ARCHIVEUSER account, 
;---- and update the password in this script. Without this the script will fail
;
$USERPASS = password
;
;---- Mapping Archive drive first to create log file
;
? "Mapping the Archive Drive"
USE $ARCHIVEDRIVE $ARCHIVESTORE /USER:$ARCHIVEUSER /PASSWORD:$USERPASS
	IF @ERROR = 0
		"....Done"
	ELSE
		"..Failed"
		SHELL ("cmd.exe /c " + $SCRIPTROOT + "Blat " + $ARCHIVELOG + " -t " + $SupportEmail + " -f " + $Sender + " -s Archive_Mapping_failure -server " + $EMAILSERVER)
		GOTO END
	ENDIF
;
$VARSET = OPEN(1, $ARCHIVESTORE + "\LOGS\" + $ARCHIVE + ".LOG", 5)
? @DATE
$VARSET = WRITELINE (1, "The current date is " + @DATE + @CRLF)
;
;---- Do drive mapping for Report drive to move the data
;
$VARSET = WRITELINE (1, "Mapping the Report Drive")
USE $REPORTDRIVE $REPORTSTORE /USER:$REPORTUSER /PASSWORD:$USERPASS
	IF @ERROR = 0
		"....Done"
		$VARSET = WRITELINE(1, "....Done" + @CRLF)
	ELSE
		"..Failed"
		$VARSET = WRITELINE(1, "..Failed" + @CRLF)
		SHELL ("cmd.exe /c " + $SCRIPTROOT + "Blat " + $ARCHIVELOG + " -t " + $SupportEmail + " -f " + $Sender + " -s Report_Mapping_failure -server " + $EMAILSERVER)
		GOTO END
	ENDIF
? "Creating current date folder"
$VARSET = WRITELINE (1, "Creating current date folder")
MD "$ARCHIVEDRIVE@YEAR@MONTHNO@MDAYNO"
;MD "$ARCHIVEDRIVE@YEAR + right("0" + @MONTHNO,2) + right("0" + @MDAYNO,2)"
	IF @ERROR = 0
		"....Done"
		$VARSET = WRITELINE(1, "....Done" + @CRLF)
	ELSE
		"..Failed"
		$VARSET = WRITELINE(1, "..Failed" + @CRLF)
		SHELL ("cmd.exe /c " + $SCRIPTROOT + "Blat " + $ARCHIVELOG + " -t " + $SupportEmail + " -f " + $Sender + " -s Archive_directory_creation_failure -server " + $EMAILSERVER)
		GOTO END
	ENDIF
$VARSET = WRITELINE (1, "Compressing current KPI data on Report Drive")
Shell ("cmd.exe /c " + $SCRIPTROOT + "\rar.exe a -r -t -y " + $REPORTDRIVE + "\" + $ARCHIVE + ".Rar " + $REPORTDRIVE + "\*")
$VARSET = WRITELINE (1, "Copying report to current date folder")
COPY $REPORTDRIVE + "\" + $ARCHIVE + ".Rar" $ARCHIVEDRIVE + "\" + $ARCHIVE
	IF @ERROR = 0
		"....Done"
		$VARSET = WRITELINE(1, "....Done" + @CRLF)
	ELSE
		"..Failed"
		$VARSET = WRITELINE(1, "..Failed" + @CRLF)
		$VARSET = WRITELINE(1, GetDiskSpace ($ARCHIVEDRIVE) + @CRLF)
		SHELL ("cmd.exe /c " + $SCRIPTROOT + "Blat " + $ARCHIVELOG + " -t " + $SupportEmail + " -f " + $Sender + " -s Archive_Mapping_failure -server " + $EMAILSERVER)
		GOTO END
	ENDIF
;
;---- Compare copied filesizes
;
$REPORTFILE = GetFileSize ($REPORTDRIVE + $ARCHIVE + ".rar") /1024
$VARSET = WRITELINE (1, "Report RAR file size is " + $REPORTFILE + @CRLF)
$ARCHIVEFILE = GetFileSize ($ARCHIVEDRIVE + "\" + $ARCHIVE + "\" + $ARCHIVE + ".rar") /1024
$VARSET = WRITELINE (1, "Archive rar file size is " + $ARCHIVEFILE + @CRLF)
If $REPORTFILE <> $ARCHIVEFILE
	SHELL ("cmd.exe /c " + $SCRIPTROOT + "Blat " + $ARCHIVELOG + " -t " + $SupportEmail + " -f " + $Sender + " -s File_Copy_Error -server " + $EMAILSERVER)
ENDIF
;
;---- Extracting files onto Archive
;
$VARSET = WRITELINE (1, "Extracting " + $ARCHIVEDRIVE + "\" + $ARCHIVE + "\" + $ARCHIVE + ".rar" +  @CRLF)
Shell ("cmd.exe /c " + $SCRIPTROOT + "\unrar.exe e -r " + $ARCHIVEDRIVE + "\" + $ARCHIVE + "\" + $ARCHIVE ".rar " + $ARCHIVEDRIVE + "\" + $ARCHIVE + "\" )
	IF @ERROR = 0
		"....Done"
		$VARSET = WRITELINE(1, "....Done" + @CRLF)
	ELSE
		"..Failed"
		$VARSET = WRITELINE(1, "..Failed" + @CRLF)
		$VARSET = WRITELINE(1, GetDiskSpace ($ARCHIVEDRIVE) + @CRLF)
		SHELL ("cmd.exe /c " + $SCRIPTROOT + "Blat " + $ARCHIVELOG + " -t " + $SupportEmail + " -f " + $Sender + " -s Issue_Extracting_Files_From_Archive -server " + $EMAILSERVER)
		GOTO END
	ENDIF
;
;---- Removing archive rar file and files from Report Drive
;
RD $REPORTDRIVE /Q
$VARSET = WRITELINE (1, "Removing archive RAR file and files from Report Drive" + @CRLF)
	IF @ERROR = 0
		"....Done"
		$VARSET = WRITELINE(1, "....Done" + @CRLF)
	ELSE
		"..Failed"
		$VARSET = WRITELINE(1, "..Failed" + @CRLF)
		SHELL ("cmd.exe /c " + $SCRIPTROOT + "Blat " + $ARCHIVELOG + " -t " + $SupportEmail + " -f " + $Sender + " -s Issue_removing_files_from_HR01 -server " + $EMAILSERVER)
		GOTO END
	ENDIF
;
;---- Email success report to maintaining group
;
SHELL ("cmd.exe /c " + $SCRIPTROOT + "Blat " + $ARCHIVELOG + " -t " + $EmailAddress + " -f " + $Sender + " -s " + @DATE + "_KPI_Archive_Success -server " + $EMAILSERVER)
:END
;USE $REPORTDRIVE /DEL
;USE $ARCHIVEDRIVE /DEL


Edited by Pax (2006-12-04 03:01 PM)

Top
#170975 - 2006-12-04 12:40 PM Re: Directory creation based on date issue [Re: Pax]
Mart Moderator Online   content
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4641
Loc: The Netherlands
How about breaking that looooooong commented line so we can read the post on one screen instead of scrolling miles to the right \:\)

Edited by Mart (2006-12-04 12:40 PM)
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#170979 - 2006-12-04 03:02 PM Re: Directory creation based on date issue [Re: Mart]
Pax Offline
Getting the hang of it

Registered: 2006-12-01
Posts: 51
Originally Posted By: Mart
How about breaking that looooooong commented line so we can read the post on one screen instead of scrolling miles to the right \:\)
It's that damn KixStarter I tells you...

fixed ;\)

Pax

Top
#171032 - 2006-12-05 02:59 AM Re: Directory creation based on date issue [Re: Pax]
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11564
Loc: CA
Well unless it is bad editing on your part the script HAS to fail.


PHP:
$REPORTUSER = domain1user $ARCHIVEUSER = domain2user $REPORTDRIVE = I: $ARCHIVEDRIVE = J:


Those vars need to be within quotes

I would also HIGHLY recommend that you place this type of header at the top of your script. It will force you to make sure you code cleanly.

PHP:
If Not @LogonMode Break On Else Break Off EndIf Dim $SO $SO=SetOption('Explicit','On') $SO=SetOption('NoVarsInStrings','On') $SO=SetOption('NoMacrosInStrings','On') $SO=SetOption('WrapAtEOL','On')


Again, bad editing????

Code:
$USERPASS = password


Unless you REALLY have to, I would recode the script so that you don't keep issuing the WriteLine over and over. I would attempt to write the log one time when needed only with a single write.


You use a USE statement without checking if the drive is already mapped or not. You should check and verify.

You attempt to use NoVarsInStrings and then you go and do this:

Code:
MD "$ARCHIVEDRIVE@YEAR@MONTHNO@MDAYNO"


You're using GOTO END I would really recode and remove all GOTO statements.

You attempt to remove a file/dir without checking if it exists or if you're even in the correct path/location. Very easy to delete or RD an entire structure if LEN is not correct. i.e. You can start an RD from the root of a drive which will give you the opportunity to rebuild the system if something like that happens.

Please take a crack at making the suggested changes and let us know how it goes please.

Top
#171033 - 2006-12-05 03:03 AM Re: Directory creation based on date issue [Re: NTDOC]
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11564
Loc: CA
Oh... I see I mentioned it and you did not respond to it.

Again - HIGHLY recommend using KiXtart 4.53

This is NOT a logon script so I see no reason not to use the latest version of KiXtart.

Top
#171049 - 2006-12-05 01:00 PM Re: Directory creation based on date issue [Re: NTDOC]
Pax Offline
Getting the hang of it

Registered: 2006-12-01
Posts: 51
Originally Posted By: NTDOC
Well unless it is bad editing on your part the script HAS to fail.


PHP:
$REPORTUSER = domain1user $ARCHIVEUSER = domain2user $REPORTDRIVE = I: $ARCHIVEDRIVE = J:


Those vars need to be within quotes

The drive mappings have been working perfectly fine without using the quote marks up to this point. It is one reason I commented out the drive deletions in the END section so I can see what is being done when it fails.
Originally Posted By: NTDOC
I would also HIGHLY recommend that you place this type of header at the top of your script. It will force you to make sure you code cleanly.

PHP:
If Not @LogonMode Break On Else Break Off EndIf Dim $SO $SO=SetOption('Explicit','On') $SO=SetOption('NoVarsInStrings','On') $SO=SetOption('NoMacrosInStrings','On') $SO=SetOption('WrapAtEOL','On')


Again, bad editing????

Code:
$USERPASS = password


Unless you REALLY have to, I would recode the script so that you don't keep issuing the WriteLine over and over. I would attempt to write the log one time when needed only with a single write.

I am using it for now so I can trouble shoot at what stage the script would fail providing there were no parsing errors, which currently there are. I shall consider moving the writeline events at a later stage once I know the script runs through with no errors. At the moment, it is part of my own error checking. As for the $USERPASS, no, this was for removing identifiable. Any testing I am doing is running as a locally logged on user as the user who runs the script(in the scheduled task) won't have the ability to logon to the machine, only to run the scheduled task.

Originally Posted By: NTDOC
You use a USE statement without checking if the drive is already mapped or not. You should check and verify.

You attempt to use NoVarsInStrings and then you go and do this:

Code:
MD "$ARCHIVEDRIVE\@YEAR@MONTHNO@MDAYNO"

I'll go back and review checking the drive mappings, thanks for the suggestion.

My original post in this thread was about why MD creates the directory how I wanted it created, yet pre-defining $ARCHIVE works differently, even through we are dealing with KiX internal commands and macros. The suggestions I've been given only gave a work around, and no reason why they seems to be dealt with differently, so I'm working only on what I know.

Originally Posted By: NTDOC
You're using GOTO END I would really recode and remove all GOTO statements.

You attempt to remove a file/dir without checking if it exists or if you're even in the correct path/location. Very easy to delete or RD an entire structure if LEN is not correct. i.e. You can start an RD from the root of a drive which will give you the opportunity to rebuild the system if something like that happens.

Please take a crack at making the suggested changes and let us know how it goes please.

What would you suggest to use instead of GOTO statements. If there is a failure in one section I don't want the entire script to continue running when I know it will fail.

I could move the failure condition commands to the a seperate section called FAIL to recode reused code, which would include the WRITELINE commands, but once again, this would require GOTO, unless there is a more elegant way to deal with this. I wouldn't say I am a great scripter, but this is all I know at the moment.

I have taken your comments on board about RD, but I've been told that the files, etc I have to move are a series of files, directories and subdirectories, and are dymanic, so this is the best way I can see of dealing with it, mapping to the root of the store, so using RD won't remove anything above this level, and I do have to remove all contents of the "dump" directory.

Should I use a variation of the DIR command for this instead? I don't know how this deals with directories and subdirectories as I've never used it, and only seen it referenced briefly in the forums,

Pax

Top
#171050 - 2006-12-05 01:01 PM Re: Directory creation based on date issue [Re: NTDOC]
Pax Offline
Getting the hang of it

Registered: 2006-12-01
Posts: 51
Originally Posted By: NTDOC
Well unless it is bad editing on your part the script HAS to fail.


PHP:
$REPORTUSER = domain1user $ARCHIVEUSER = domain2user $REPORTDRIVE = I: $ARCHIVEDRIVE = J:


Those vars need to be within quotes

The drive mappings have been working perfectly fine without using the quote marks up to this point. It is one reason I commented out the drive deletions in the END section so I can see what is being done when it fails.
Originally Posted By: NTDOC
I would also HIGHLY recommend that you place this type of header at the top of your script. It will force you to make sure you code cleanly.

PHP:
If Not @LogonMode Break On Else Break Off EndIf Dim $SO $SO=SetOption('Explicit','On') $SO=SetOption('NoVarsInStrings','On') $SO=SetOption('NoMacrosInStrings','On') $SO=SetOption('WrapAtEOL','On')


Again, bad editing????

Code:
$USERPASS = password


Unless you REALLY have to, I would recode the script so that you don't keep issuing the WriteLine over and over. I would attempt to write the log one time when needed only with a single write.

I am using it for now so I can trouble shoot at what stage the script would fail providing there were no parsing errors, which currently there are. I shall consider moving the writeline events at a later stage once I know the script runs through with no errors. At the moment, it is part of my own error checking. As for the $USERPASS, no, this was for removing identifiable. Any testing I am doing is running as a locally logged on user as the user who runs the script(in the scheduled task) won't have the ability to logon to the machine, only to run the scheduled task.

Originally Posted By: NTDOC
You use a USE statement without checking if the drive is already mapped or not. You should check and verify.

You attempt to use NoVarsInStrings and then you go and do this:

Code:
MD "$ARCHIVEDRIVE\@YEAR@MONTHNO@MDAYNO"

I'll go back and review checking the drive mappings, thanks for the suggestion.

My original post in this thread was about why MD creates the directory how I wanted it created, yet pre-defining $ARCHIVE works differently, even through we are dealing with KiX internal commands and macros. The suggestions I've been given only gave a work around, and no reason why they seems to be dealt with differently, so I'm working only on what I know.

Originally Posted By: NTDOC
You're using GOTO END I would really recode and remove all GOTO statements.

You attempt to remove a file/dir without checking if it exists or if you're even in the correct path/location. Very easy to delete or RD an entire structure if LEN is not correct. i.e. You can start an RD from the root of a drive which will give you the opportunity to rebuild the system if something like that happens.

Please take a crack at making the suggested changes and let us know how it goes please.

What would you suggest to use instead of GOTO statements. If there is a failure in one section I don't want the entire script to continue running when I know it will fail.

I could move the failure condition commands to the a seperate section called FAIL to recode reused code, which would include the WRITELINE commands, but once again, this would require GOTO, unless there is a more elegant way to deal with this. I wouldn't say I am a great scripter, but this is all I know at the moment.

I have taken your comments on board about RD, but I've been told that the files, etc I have to move are a series of files, directories and subdirectories, and are dymanic, so this is the best way I can see of dealing with it, mapping to the root of the store, so using RD won't remove anything above this level, and I do have to remove all contents of the "dump" directory.

Should I use a variation of the DIR command for this instead? I don't know how this deals with directories and subdirectories as I've never used it, and only seen it referenced briefly in the forums,

Pax

Top
#171083 - 2006-12-06 03:51 AM Re: Directory creation based on date issue [Re: Pax]
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11564
Loc: CA
Well the reason your code doesn't supply the dates you're wanting is that it is adding the values together.

Here is some code that will give you the DATE and TIME into your var.


PHP:
Dim $Archive $Archive = Trim(Join(Split(@DATE,'/'),'-'))+'_'+Trim(Join(Split(@TIME,':'),'')) 'Archive Date for var is: ' + $Archive ?


.

Top
#171084 - 2006-12-06 03:57 AM Re: Directory creation based on date issue [Re: Pax]
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11564
Loc: CA
I have confirmed that you can seemingly use STRINGS without quotes for some reason. I would list that as a BUG but will wait for input from some of the other long term coders to get their input.

From the user manual:

Quote:

When using KiXtart, note the following rules:
  • Strings can contain any characters, except the \0 (NULL) and \x1a (end of file) characters.
  • Script commands should be separated by white space — that is, any combination of spaces, tabs, or new line characters.
  • Strings must be enclosed in quotation marks.

    For example:
    'String with a dash (-) in it.' ; String with a dash (-) in it.



.

Top
#171085 - 2006-12-06 04:58 AM Re: Directory creation based on date issue [Re: Pax]
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11564
Loc: CA
Okay here is an UNTESTED semi rewrite of your code.
Please review the code and update/modify/change as needed to function properly in your environment.

PHP:
;:KVIS:Edited on 04/12/2006 09:38:57 by Pax.|E:KVIE: ; This is a test script for moving the archive data ; ;-------------------------------------------------------------------------------------------------------------------- ; ;---- Script version 0.2 ;---- Created by Pax ;---- Last edit date 04/12/2006 by Pax ;---- Last edit date 12/5/2006 by NTDOC ; ;---- Declare Variables ------- ; If Not @LogonMode Break On Else Break Off EndIf Dim $SO $SO=SetOption('Explicit','On') $SO=SetOption('NoVarsInStrings','On') $SO=SetOption('NoMacrosInStrings','On') $SO=SetOption('WrapAtEOL','On') Dim $SCRIPTROOT, $REPORTSTORE, $ARCHIVESTORE, $REPORTUSER, $ARCHIVEUSER, Dim $REPORTDRIVE, $ARCHIVEDRIVE, $ARCHIVE, $ARCHIVELOG Dim $EmailServer, $Sender, $SupportEmail, $EmailAddress Dim $USERPASS $SCRIPTROOT = '\\server1\path\' $REPORTSTORE = 'server2path' $ARCHIVESTORE = 'server3path' $REPORTUSER = 'domain1user' $ARCHIVEUSER = 'domain2user' $REPORTDRIVE = 'I:' $ARCHIVEDRIVE = 'J:' $ARCHIVE = Trim(Join(Split(@DATE,'/'),'-'))+'_'+Trim(Join(Split(@TIME,':'),'')) $ARCHIVE ? $ARCHIVELOG = $ARCHIVEDRIVE + 'LOGS' + $ARCHIVE + ".LOG" $ARCHIVELOG ? $EmailServer = 'our.emailserver.net' $Sender = 'sender@@emailserver.net' $SupportEmail = 'support@@emailserver.net' $EmailAddress = 'recipient@@emailserver.net' ; ;---- If the password for the REPORTUSER account changes on server2, change the password on the ARCHIVEUSER account, ;---- and update the password in this script. Without this the script will fail ; $USERPASS = 'password' ; ;---- Mapping Archive drive first to create log file ; "Mapping the Archive Drive" ? Dim $Err, $SErr USE $ARCHIVEDRIVE + $ARCHIVESTORE /USER:$ARCHIVEUSER /PASSWORD:$USERPASS $Err = @ERROR $SErr = @SERROR IF @ERROR = 0 '....Done' ? ELSE '..Failed: ' + $SErr ? SHELL ("%comspec% /c " + $SCRIPTROOT + "Blat " + $ARCHIVELOG + " -t " + $SupportEmail + " -f " + $Sender + " -s Archive_Mapping_failure -server " + $EMAILSERVER) Quit $Err ENDIF ; Dim $VARSET $VARSET = OPEN(1, $ARCHIVESTORE + 'LOGS' + $ARCHIVE + '.LOG', 5) @DATE ? $VARSET = WRITELINE (1, 'The current date is ' + @DATE + @CRLF) ; ;---- Do drive mapping for Report drive to move the data ; $VARSET = WRITELINE (1, 'Mapping the Report Drive') Dim $Err, $SErr USE $REPORTDRIVE + $REPORTSTORE /USER:$REPORTUSER /PASSWORD:$USERPASS $Err = @ERROR $SErr = @SERROR IF @ERROR = 0 "....Done" ? $VARSET = WRITELINE(1, '....Done' + @CRLF) ELSE "..Failed: " + $SErr ? $VARSET = WRITELINE(1, '..Failed' + @CRLF) SHELL ("%comspec% /c " + $SCRIPTROOT + "Blat " + $ARCHIVELOG + " -t " + $SupportEmail + " -f " + $Sender + " -s Report_Mapping_failure -server " + $EMAILSERVER) Quit $Err ENDIF "Creating current date folder" ? $VARSET = WRITELINE (1, 'Creating current date folder') Dim $Err, $SErr MD $ARCHIVEDRIVE + '' + $ARCHIVE $Err = @ERROR $SErr = @SERROR IF @ERROR = 0 '....Done' ? $VARSET = WRITELINE(1, '....Done' + @CRLF) ELSE '..Failed: ' + $SErr ? $VARSET = WRITELINE(1, '..Failed' + @CRLF) SHELL ("%comspec% /c " + $SCRIPTROOT + "Blat " + $ARCHIVELOG + " -t " + $SupportEmail + " -f " + $Sender + " -s Archive_directory_creation_failure -server " + $EMAILSERVER) Quit $Err ENDIF $VARSET = WRITELINE (1, 'Compressing current KPI data on Report Drive') Shell ("%comspec% /c " + $SCRIPTROOT + "\rar.exe a -r -t -y " + $REPORTDRIVE + "\" + $ARCHIVE + ".Rar " + $REPORTDRIVE + "\*") $VARSET = WRITELINE (1, 'Copying report to current date folder') Dim $Err, $SErr COPY $REPORTDRIVE + '' + $ARCHIVE + '.Rar' $ARCHIVEDRIVE + '' + $ARCHIVE $Err = @ERROR $SErr = @SERROR IF @ERROR = 0 '....Done' ? $VARSET = WRITELINE(1, '....Done' + @CRLF) ELSE '..Failed: ' + $SErr ? $VARSET = WRITELINE(1, '..Failed' + @CRLF) $VARSET = WRITELINE(1, GetDiskSpace ($ARCHIVEDRIVE) + @CRLF) SHELL ("%comspec% /c " + $SCRIPTROOT + "Blat " + $ARCHIVELOG + " -t " + $SupportEmail + " -f " + $Sender + " -s Archive_Mapping_failure -server " + $EMAILSERVER) Quit $Err ENDIF ; ;---- Compare copied filesizes ; $REPORTFILE = GetFileSize ($REPORTDRIVE + '' + $ARCHIVE + '.rar') /1024 $VARSET = WRITELINE (1, 'Report RAR file size is ' + $REPORTFILE + @CRLF) $ARCHIVEFILE = GetFileSize ($ARCHIVEDRIVE + '' + $ARCHIVE + '' + $ARCHIVE + '.rar') /1024 $VARSET = WRITELINE (1, 'Archive rar file size is ' + $ARCHIVEFILE + @CRLF) If $REPORTFILE <> $ARCHIVEFILE SHELL ("%comspec% /c " + $SCRIPTROOT + "Blat " + $ARCHIVELOG + " -t " + $SupportEmail + " -f " + $Sender + " -s File_Copy_Error -server " + $EMAILSERVER) ENDIF ; ;---- Extracting files onto Archive ; $VARSET = WRITELINE (1, 'Extracting ' + $ARCHIVEDRIVE + "\" + $ARCHIVE + "\" + $ARCHIVE + ".rar" + @CRLF) Dim $Err, $SErr Shell ("%comspec% /c " + $SCRIPTROOT + "\unrar.exe e -r " + $ARCHIVEDRIVE + "\" + $ARCHIVE + "\" + $ARCHIVE ".rar " + $ARCHIVEDRIVE + "\" + $ARCHIVE + "\" ) $Err = @ERROR $SErr = @SERROR IF @ERROR = 0 '....Done' ? $VARSET = WRITELINE(1, '....Done' + @CRLF) ELSE '..Failed: ' + $SErr ? $VARSET = WRITELINE(1, '..Failed' + @CRLF) $VARSET = WRITELINE(1, GetDiskSpace ($ARCHIVEDRIVE) + @CRLF) SHELL ("%comspec% /c " + $SCRIPTROOT + "Blat " + $ARCHIVELOG + " -t " + $SupportEmail + " -f " + $Sender + " -s Issue_Extracting_Files_From_Archive -server " + $EMAILSERVER) Quit $Err ENDIF ; ;---- Removing archive rar file and files from Report Drive ; If LEN($REPORTDRIVE)>2 Dim $Err, $SErr RD $REPORTDRIVE /Q $VARSET = WRITELINE (1, 'Removing archive RAR file and files from Report Drive' + @CRLF) $Err = @ERROR $SErr = @SERROR IF @ERROR = 0 '....Done' ? $VARSET = WRITELINE(1, '....Done' + @CRLF) ELSE '..Failed: ' + $SErr ? $VARSET = WRITELINE(1, '..Failed' + @CRLF) SHELL ("%comspec% /c " + $SCRIPTROOT + "Blat " + $ARCHIVELOG + " -t " + $SupportEmail + " -f " + $Sender + " -s Issue_removing_files_from_HR01 -server " + $EMAILSERVER) Quit $Err ENDIF Else 'The REPORTDRIVE var was empty so did not write' ? EndIf ; ;---- Email success report to maintaining group ; SHELL ("%comspec% /c " + $SCRIPTROOT + "Blat " + $ARCHIVELOG + " -t " + $EmailAddress + " -f " + $Sender + " -s " + @DATE + "_KPI_Archive_Success -server " + $EMAILSERVER)


.

Top
#171094 - 2006-12-06 10:39 AM Re: Directory creation based on date issue [Re: NTDOC]
Pax Offline
Getting the hang of it

Registered: 2006-12-01
Posts: 51
Originally Posted By: NTDOC
Okay here is an UNTESTED semi rewrite of your code.
Please review the code and update/modify/change as needed to function properly in your environment.


Hey NTDOC,

Thanks for that. Most unexpected, and I do say I'm quite shocked that you'd spend the time on it. Thank you muchly for your time.

I will go over it now and compare to what I've got now to see what I can learn from it. There are quite a few functions I've never used before, so will have to read up on what they do.

5 * for you \:\)

Pax

Top
#171095 - 2006-12-06 11:44 AM Re: Directory creation based on date issue [Re: Pax]
Pax Offline
Getting the hang of it

Registered: 2006-12-01
Posts: 51
Just had another thought on your suggestion about the WRITELINEs I seem to be doing everywhere.

Would it be a better choice to open the logfile, and immediately below it use
PHP:
RedirectOutput($ARCHIVELOG)

and remove the WRITELINE commands? This would mean I could capture the output from Blat, RAR and UNRAR directly to the log file, as I think this would be served well in the file.

The benefits would be that if there are problems, then I can just comment out that line and see it on screen running it manually. Also the script would be smaller and easier to diagnose if problem turn up instead of having screen output and log file output seperately?

Ideas?

Pax


Edited by Pax (2006-12-06 11:44 AM)

Top
#171096 - 2006-12-06 12:26 PM Re: Directory creation based on date issue [Re: Pax]
Mart Moderator Online   content
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4641
Loc: The Netherlands
RedirectOutput will send all screen output to the log file. So if you do not output the stuff from a function or command to the screen it will not show in the log file.
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#171097 - 2006-12-06 12:46 PM Re: Directory creation based on date issue [Re: Mart]
Pax Offline
Getting the hang of it

Registered: 2006-12-01
Posts: 51
Originally Posted By: Mart
RedirectOutput will send all screen output to the log file. So if you do not output the stuff from a function or command to the screen it will not show in the log file.


No that's fine, the script is going to run as a scheduled task, so won't be seen by anyone anyway.

If this means I won't need to double up on writing to the screen and log seperately and it will capture all SHELL run programs' output, then this is what I want.

I just wanted to check that this is the case, and then if I have to run it manually I can comment out the RedirectOutput line and see everything to screen to troubleshoot.

I know that if there is the something I specifically want to appear on screen I can do a RedirectOutput("") before it, and then return to dumping to the logfile using RedirectOutput($ARCHIVELOG) after the section I want on screen.

Pax

Top
Page 1 of 2 12>


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 166 anonymous users online.
Newest Members
amelindarķe, Nims123, davidscroegh, davidscroe, DFGHJGH
17625 Registered Users

Generated in 0.109 seconds in which 0.034 seconds were spent on a total of 14 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org