Computing.Net > Forums > Programming > Ghost *.Bat File With Auto Naming?

Ghost *.Bat File With Auto Naming?

Reply to Message Icon

Original Message
Name: twodaend
Date: May 13, 2005 at 07:36:33 Pacific
Subject: Ghost *.Bat File With Auto Naming?
OS: XP Pro
CPU/Ram: AMD 3400+ 512MB
Comment:

I've created a *.bat file based of some of the ideas http://ghost.radified.com/ghost_4.htm. My file will backup and check each of my partitions. The problem is the name of the *.gho file. I like to have my file name to be the drive letter and the date: C_0513. The first 2 characters will be static, but the last 4 will change based on the date but I want to do this automatically based on the date rather than me having to do it manually each time I run my file.

The problem I'm having is getting the date in the numerical month & day format and then adding that to the first 2 characters to form the full file name.

Is this possible to do? If more info is needed, please ask. Thanks in advance for all the help.


Report Offensive Message For Removal


Response Number 1
Name: IVO
Date: May 13, 2005 at 08:00:55 Pacific
Reply: (edit)

What you want can be easily do, only needed is the format of your date as it is related to country settings.

So at prompt type Echo %Date% and report exactly what you see displayed.


Report Offensive Follow Up For Removal

Response Number 2
Name: IVO
Date: May 13, 2005 at 08:06:20 Pacific
Reply: (edit)

Sorry... "do" should be "done" and better you type

Echo [%Date%]


Report Offensive Follow Up For Removal

Response Number 3
Name: twodaend
Date: May 13, 2005 at 08:07:01 Pacific
Reply: (edit)

This is what I get:

C:\>echo %date%
Fri 05/13/2005


Report Offensive Follow Up For Removal

Response Number 4
Name: IVO
Date: May 13, 2005 at 08:14:35 Pacific
Reply: (edit)

Well, to setup your file's name code the following statement in your batch script

Set FileDate=%Date:~4,2%%Date:~7,2%

then use the FileDate variable to complete the file name

C_%FileDate%.gho

Post again if you need more support or anything goes wrong.


Report Offensive Follow Up For Removal

Response Number 5
Name: twodaend
Date: May 13, 2005 at 10:33:20 Pacific
Reply: (edit)

Can a variable be set and used in a ghost batch file? I look on Norton's site, but it does not mention it anywhere. I can't test this until this evening.

This is what I have:
a:\ghost\ghost.exe-clone,mode=pdump,src=1:1,dst=2:1\images\C_0513.gho

This is what I want to do:
Set FileDate=%Date:~4,2%%Date:~7,2%
a:\ghost\ghost.exe-clone,mode=pdump,src=1:1,dst=2:1\images\C_%FileDate%.gho

Is is possible to set a variable at the top and then use it in the norton command statement?


Report Offensive Follow Up For Removal


Response Number 6
Name: Mechanix2Go
Date: May 13, 2005 at 10:57:41 Pacific
Reply: (edit)

Hi two,

Yes, it's possible to set a var then use it in the ghost line.

BUT, if the a:\ means you're booting on a floppy, there will be no built-in %DATE% var. Nor can you use %blah:~

Are you booting in DOS?

M2


If at first you don't succeed, you're about average.


Report Offensive Follow Up For Removal

Response Number 7
Name: twodaend
Date: May 13, 2005 at 11:02:22 Pacific
Reply: (edit)

I'm using a floppy created from the norton boot disk wizard and I've been trying to modify it with my own batch file. Actually it is booting to PC-DOS and not MS-DOS as this is what come with ghost.

Is there a way around the problem you've stated?


Report Offensive Follow Up For Removal

Response Number 8
Name: Mechanix2Go
Date: May 13, 2005 at 11:19:47 Pacific
Reply: (edit)

Hi two,

Yes, but it gets complex.

When your posted earlier the output of:

echo %date%

I guess you were in XP.

Do the same thing in PCDOS and I think you will find that there is no built-in DATE var.

If so, you need to:

echo.|date

And see exactly what the output is.

I can probably write a script to get this done. But the syntax must be EXACT. So do this:

echo.|date>datefile.txt

Then ZIP up the datefile.txt and send it to me.

M2


If at first you don't succeed, you're about average.


Report Offensive Follow Up For Removal

Response Number 9
Name: twodaend
Date: May 13, 2005 at 12:25:03 Pacific
Reply: (edit)

Mechanix2Go

I sent you an emil with the datefile.txt


Report Offensive Follow Up For Removal

Response Number 10
Name: Mechanix2Go
Date: May 13, 2005 at 12:28:36 Pacific
Reply: (edit)

Hi two,

Got the file.

I don't think PC/MS DOS will matter much.

I figured out a few years ago how the get DATE into a ver in DOS. [Very skillfully re-inventing the wheel, since many had done it befotre.]

The additional task here is that you want just MMDD, so after setting date var, we need to get a substring.

Dead rasy in NT; can of worms in DOS.

This should do it:

::** MMDD.bat
@echo off
echo set edsdate=%%4>current.bat
echo.|date>datefile

> %0.d echo N datefile
>> %0.d echo L
>> %0.d echo m 117 11f 116
>> %0.d echo rcx
>> %0.d echo 18
>> %0.d echo N edsdate.bat
>> %0.d echo w
>> %0.d echo q

debug < %0.d

call edsdate

del edsdate.bat
del %0.d
del current.bat
del datefile
::** end MMDD

HTH


M2


If at first you don't succeed, you're about average.


Report Offensive Follow Up For Removal

Response Number 11
Name: twodaend
Date: May 13, 2005 at 12:53:40 Pacific
Reply: (edit)

I tried copying that batch file a mmdd.bat, but when i run it I get a file creation error right away.

Is it possible to read the datefile.txt and just count over the correct amount of characters and store that in a variable.


Report Offensive Follow Up For Removal

Response Number 12
Name: Mechanix2Go
Date: May 13, 2005 at 13:02:13 Pacific
Reply: (edit)

1. Are you booting on a write-protected floppy?

2. That's what the BAT is designed to do.

M2


If at first you don't succeed, you're about average.


Report Offensive Follow Up For Removal

Response Number 13
Name: twodaend
Date: May 13, 2005 at 15:03:13 Pacific
Reply: (edit)

No it's mpt wrote protected, but it did give me an error.

I found this for loop that does this:
A:\>FOR /F "tokens=1* delims=" %G IN (datefile.txt) DO set mydate=%G

And returns this

A:\>set mydate=The current date is: Fri 05/13/2005

A:\>set mydate=Enter the new date: (mm-dd-yy)

The problem is that the mydate variable is set, but it is set to the last item and not the first. If I can get it set to the first, then I can just use another varable and count over to where I can to start.


Report Offensive Follow Up For Removal

Response Number 14
Name: Mechanix2Go
Date: May 13, 2005 at 19:20:06 Pacific
Reply: (edit)

Hi two,

I think you're mixing DOS & NT.

AFAIK, DOS will use none of these:

for /f
tokens
delims

***
Do this just before you try any script:

ver
[enter]

M2


If at first you don't succeed, you're about average.


Report Offensive Follow Up For Removal

Response Number 15
Name: twodaend
Date: May 13, 2005 at 19:39:24 Pacific
Reply: (edit)

PC DOS version 7


Report Offensive Follow Up For Removal

Response Number 16
Name: Mechanix2Go
Date: May 13, 2005 at 19:58:04 Pacific
Reply: (edit)

Hi two,

Apparently PCDOS does support tokens etc.

In which case, go with IVO's code.

***

My ISP is flaking out. Had to reconnect 6 times to read this. So if you don't hear from me for a while, that's why.

Good Luck

M2


If at first you don't succeed, you're about average.


Report Offensive Follow Up For Removal

Response Number 17
Name: twodaend
Date: May 13, 2005 at 21:41:42 Pacific
Reply: (edit)

I tried the script you reccommended earlier, but I start to get File Creation Error starting with the first %0.d line.


Report Offensive Follow Up For Removal

Response Number 18
Name: Mechanix2Go
Date: May 13, 2005 at 21:54:34 Pacific
Reply: (edit)

Hi two,

What name did you give the BAT which gives the file creation error?

And what EXACTLY did you type in to run it?

M2


If at first you don't succeed, you're about average.


Report Offensive Follow Up For Removal

Response Number 19
Name: twodaend
Date: May 13, 2005 at 22:08:58 Pacific
Reply: (edit)

The file name ist getdate.bat and from the A: prompt, I typed getdate.bat


Report Offensive Follow Up For Removal

Response Number 20
Name: Mechanix2Go
Date: May 13, 2005 at 22:39:56 Pacific
Reply: (edit)

Hi two,

OK, there's the problem.

The %0 means "what was typed" so the BAT is trying [and failing] to create a file called:

getdate.bat.d

Try typing in just:

getdate

And I think it will fly.

===

M2


If at first you don't succeed, you're about average.


Report Offensive Follow Up For Removal

Response Number 21
Name: twodaend
Date: May 13, 2005 at 23:06:51 Pacific
Reply: (edit)

I turned the echo on so I could see what is happening and at the debug line and the 1 line below it, I get a:

bad command or file name

On the first del line, I get a:

file not found

I guess this is because of the previouse errors


Report Offensive Follow Up For Removal

Response Number 22
Name: Mechanix2Go
Date: May 13, 2005 at 23:24:53 Pacific
Reply: (edit)

Hi two,

First, with echo on things will surely go wrong.

If you want to troubleshoot, put a PAUSE in and when it pauses, press CTRL-C and terminate so you can check "what's been done so far".

===
I guess I should not have assumed that you'd be sure to have debug on the floppy. If it's not there, you need to put it there.

===
Yes, the other errors are caused by the factors above.


M2


If at first you don't succeed, you're about average.


Report Offensive Follow Up For Removal

Response Number 23
Name: twodaend
Date: May 13, 2005 at 23:45:26 Pacific
Reply: (edit)

I tried using the debug on my xp pro maching in my system32, but it said incompatiable version when using with my boot disk. I tried with both a PC and MS Dos disk. Do you know where I can fine one. Will bootdisk.com have it?


Report Offensive Follow Up For Removal

Response Number 24
Name: Mechanix2Go
Date: May 13, 2005 at 23:57:46 Pacific
Reply: (edit)

Hi two,

To save you any more lost motion, use this one:

DEBUGDOS

M2


If at first you don't succeed, you're about average.


Report Offensive Follow Up For Removal

Response Number 25
Name: twodaend
Date: May 14, 2005 at 00:16:59 Pacific
Reply: (edit)

Thank you, thank you, thank you!!!! You are the greastest. I would have never gotten that in a million years and it still took forever for me to get it even with your help.

Even though i don't completely understand how your script is working (lost of syntax i don't understand), the final result is perfect. I just plugged in the variable into my ghost batch file and it works like a charm.

Hopefylly I'll be able to go through your script and try to understand what excatly is going on, but for the moment I'm just glad it is working.

Question, what is the difference with the debug file you gave me vs. the one on my xp pro system?

Once agin thank you for all your help. You have really been a blessing. Thanks a million.


Report Offensive Follow Up For Removal

Response Number 26
Name: Mechanix2Go
Date: May 14, 2005 at 00:44:44 Pacific
Reply: (edit)

Hi two,

Glad you're finally out of the woods.

Last question first. That debug is essentially "version free", unlike most DOS / windows externals which do a version check when they load. It's written by a Japanese guy.

===
As to what the script is doing.

This line creates the current.bat:

echo set edsdate=%%4>current.bat

This line puts the DATE "output" into a file:

echo.|date>datefile

The block starting with this:

> %0.d echo N datefile

creates a "debug script" which is used later to "pipe" commands to debug so that debug can alter / create the needed files.

There's nothing special about the name of the script. I use %0 because it keeps it generic. {wash n wear code]

In the debug script, the N and L simply name the file and load it.

This line:

m 117 11f 116

MOVES the block at 117 11f to 116, thereby putting the DD immediayely after the MM. [no dash, no space.

===
These two set the new length, chopping off everything after DD.
rcx
18
===
This gives it a new name:

N edsdate.bat

===
Then w q writes and quits.

===
You can guess the rest.


M2


If at first you don't succeed, you're about average.


Report Offensive Follow Up For Removal

Response Number 27
Name: twodaend
Date: May 14, 2005 at 00:51:52 Pacific
Reply: (edit)

Wow, thanks, that is perfect documentation. It will give me a good place to start. Once again, thank you very much. I feel like a kid with a new toy ready to go try it out. Thanks you very much and hope to run into you again if I need help in the future.


Report Offensive Follow Up For Removal

Response Number 28
Name: Mechanix2Go
Date: May 14, 2005 at 01:00:11 Pacific
Reply: (edit)

Hi two,

You owe me two beers.

;*/

When you start experimenting with debug keep in mind that it is very powerful and anything but user friendly.

Best to work from a floppy with the HD unplugged until you get the hang of it.

M2


If at first you don't succeed, you're about average.


Report Offensive Follow Up For Removal

Response Number 29
Name: twodaend
Date: May 14, 2005 at 06:15:13 Pacific
Reply: (edit)

You got it :-)


Report Offensive Follow Up For Removal

Response Number 30
Name: twodaend
Date: May 14, 2005 at 22:56:49 Pacific
Reply: (edit)

I was running my ghost batch file with the new date file and noticed that it was not working. I did some debuging and found out the the date does not display correctly for Sunday's.

For example, I booted from the floppy to just an a: and typed in echo.|date and got The current date is 05-15-2005. The day of the week is missing. I changed the date to 5/16 and it showed The current date is MON 05-15-2005. I also tried next sunday and got The current date is 05-15-2005 in which the day is missing again.

Is this some sort of bug with the date file on sunday not displaying correctly?


Report Offensive Follow Up For Removal

Response Number 31
Name: twodaend
Date: May 14, 2005 at 22:59:28 Pacific
Reply: (edit)

In the above post, where the date is missing on sunday, there are 3 blank spaces where the date would show. (the post took the out)

The current date is {space}{space}{space}05-15-2005


Report Offensive Follow Up For Removal

Response Number 32
Name: Mechanix2Go
Date: May 14, 2005 at 23:20:53 Pacific
Reply: (edit)

Hi two,

The problem is not with the date *FILE*

It seems to be a quirk of the OS.

If I remember, you're using PC DOS.

It's anybody's guess why this:

echo.|date

puts out the *DAY* on some days and not others.

After all we've been through on this, is a switch to plain-vanilla DOS an option?

Hard to imagine that ghost would not work with about any old DOS.

M2


If at first you don't succeed, you're about average.


Report Offensive Follow Up For Removal

Response Number 33
Name: twodaend
Date: May 14, 2005 at 23:46:33 Pacific
Reply: (edit)

well for now it's fine like it is. i'll just remember not to run it on sunday. possible in the future i may switch to ms-dos, but for now no need to change conisdering how much time we put into this.


Report Offensive Follow Up For Removal

Response Number 34
Name: Mechanix2Go
Date: May 15, 2005 at 00:07:54 Pacific
Reply: (edit)

Hi two,

Good call.

Remember if you switch versions that the BAT is hardwired for the EXACT output of the date.

It is unlikely to be the same in a different DOS.

Good luck.

OBW, If it helps anything I can write a BASIC [!] program that will put out MMDD. You'll need about 40KB on the floppy.


M2


If at first you don't succeed, you're about average.


Report Offensive Follow Up For Removal

Response Number 35
Name: twodaend
Date: May 15, 2005 at 09:38:33 Pacific
Reply: (edit)

Naw, might not be worth the effort considering this is just one day a week and I can easily change the day in which I run it. I may even throw in a check to see what the date output is before running the ghost bat file.


Report Offensive Follow Up For Removal

Response Number 36
Name: Mechanix2Go
Date: May 15, 2005 at 10:40:44 Pacific
Reply: (edit)

Hi two,

Well, I wrote it anyway..

MAKMDBAT.EXE

This makes a BAT called MMDD.bat so you need to run the exe then CALL the bat:

****
makmdbat
call mmdd
****

M2


If at first you don't succeed, you're about average.


Report Offensive Follow Up For Removal






Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: Ghost *.Bat File With Auto Naming?

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software




Have you ever used OpenOffice?

Yes, as my main suite.
Yes, occationally.
Yes, but only once.
No, never.


View Results

Poll Finishes In 5 Days.
Discuss in The Lounge