2K/XP batch scripting! Need an expert!!!!!
Discussion
Need some help!
I need to create a batch script that will do the following:
- Get the hostname of the machine the script is running on (using hostname command.....)
- Find out if the file "jview.exe" exists on the machine (Using DIR /b - usually in c:windowssystem32)
- Get the current date (using echo %date%)
- Output all the collected data to.wnt
- email output file to an email address with the subject: "Wintel MS Java Detect:"
Can this be done? I've almost got it but i'm finding the pipe command ( | ), doesn't seem to work in XP which is useless when I come to run this script on 2003 servers!!!!!
Any help would be greatly appreciated!!!
Thanks!
I need to create a batch script that will do the following:
- Get the hostname of the machine the script is running on (using hostname command.....)
- Find out if the file "jview.exe" exists on the machine (Using DIR /b - usually in c:windowssystem32)
- Get the current date (using echo %date%)
- Output all the collected data to
- email output file to an email address with the subject: "Wintel MS Java Detect:
Can this be done? I've almost got it but i'm finding the pipe command ( | ), doesn't seem to work in XP which is useless when I come to run this script on 2003 servers!!!!!
Any help would be greatly appreciated!!!
Thanks!
Got that bit but what I need is to add the result of a command to a variable.
ie. Get the output of "hostname", and put it into the variable %current_hostname%.
You need to use | for that but it comes up as an unrecognised command in XP! Works fine in 2K. (Although I still don't know how to do the script!)
ie. Get the output of "hostname", and put it into the variable %current_hostname%.
You need to use | for that but it comes up as an unrecognised command in XP! Works fine in 2K. (Although I still don't know how to do the script!)
No good but thanks! I need something that's more detailed.
I've even gone down the route of trying to create an assembly program to perform my task!!!! Unfortunately, I haven't touched this stuff for about 6-7 years so i'm struggling to say the least.
I've managed to lock up the command prompt several times due to errors!!! d'oh!
Btw....if someone can work out this script, I'll send them a can of beer!
I've even gone down the route of trying to create an assembly program to perform my task!!!! Unfortunately, I haven't touched this stuff for about 6-7 years so i'm struggling to say the least.
I've managed to lock up the command prompt several times due to errors!!! d'oh!
Btw....if someone can work out this script, I'll send them a can of beer!
In Wink 2K the hostname is in the command spec as %COMPUTERNAME%
type 'set' at a DOS Prompt to see the full environment list
so
echo %COMPUTERNAME%>>Myfile.txt
c:
cd
dir *jview.exe* /s >>Myfile.txt
will find jview.exe for you on the C drive, painfully slow on a big disk though
type Myfile.txt
etc
best
Ex
>> Edited by TheExcession on Friday 1st April 12:18
type 'set' at a DOS Prompt to see the full environment list
so
echo %COMPUTERNAME%>>Myfile.txt
c:
cd
dir *jview.exe* /s >>Myfile.txt
will find jview.exe for you on the C drive, painfully slow on a big disk though
type Myfile.txt
etc
best
Ex
>> Edited by TheExcession on Friday 1st April 12:18
Free Command Line emailer - not looked at it too closely but might do the trick for you.
www.beyondlogic.org/solutions/cmdlinemail/cmdlinemail.htm
best
Ex
www.beyondlogic.org/solutions/cmdlinemail/cmdlinemail.htm
best
Ex
Depends how married to the idea of using variables? The following writes all the information you need to a file - called "file.txt" so that you can then email this using a command line mailer - which are fairly common
Lets see how the forum butchers this - copy the three following lines into a file called whatever.bat:
echo %date% > file.txt
hostname >> file.txt
dir %systemroot%\system32\jview.exe >> file.txt
>> Edited by _Dobbo_ on Friday 1st April 12:30
Lets see how the forum butchers this - copy the three following lines into a file called whatever.bat:
echo %date% > file.txt
hostname >> file.txt
dir %systemroot%\system32\jview.exe >> file.txt
>> Edited by _Dobbo_ on Friday 1st April 12:30
TheExcession said:
In Wink 2K the hostname is in the command spec as %COMPUTERNAME%
type 'set' at a DOS Prompt to see the full environment list
so
echo %COMPUTERNAME%>>Myfile.txt
c:
cd
dir *jview.exe* /s >>Myfile.txt
will find jview.exe for you on the C drive, painfully slow on a big disk though
type Myfile.txt
etc
best
Ex
>> Edited by TheExcession on Friday 1st April 12:18
Excession, your a genius! Problem sorted! This is seriously going to save me a LOT of time!
Many Thanks!
Btw.....just in case anyone was interested or needed to know the same....here is the script. Very simple yet I didn't know how to get the hostname as the actual filename.
P.S. If anyone can now work out a command line script that will attach the newly created batch file to an email and have the subject set as the hostname, that would be an even better bonus and even less work for me!
>> Edited by beanbag on Friday 1st April 15:07
Find MS Java Batch Script said:
@echo off
cls
echo.
echo.FindJava Windows Batch Script v1.0 - By Nick
echo.~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
goto find_old_output
--- Search for previous copies of output.txt and rename them to output.bak
--- If the file output.bak exists, it will be deleted
:find_old_output
cd
if exist c:\%computername%.txt goto :rename
goto run
:rename
del c:\%computername%.bak > nul
ren c:\%computername%.txt %computername%.bak
echo.Previous c:\%computername%.txt found! Renamed to c:\%computername%.bak.
echo.
goto run
--- Search for the hostname using command "hostname" and Windows version
--- using the command "ver" and outputting them to %computername%.txt.
:run
echo.Hostname: %computername%>> c:\%computername%.txt
ver >> c:\%computername%.txt
echo. >> c:\%computername%.txt
goto search_java
--- Search for the file "jview.exe" which is located in C:WINDOWSSYSTEM32.
--- If the file is found, it is executed to find the version number.
:search_java
if not exist %systemroot%system32jview.exe goto :nojava
echo.MS Java is installed on this system!>> c:\%computername%.txt
echo. >> c:\%computername%.txt
%systemroot%system32jview.exe | find "Version" >> c:\%computername%.txt
goto output
--- Write to output.txt if no MS Java is found.
:nojava
echo.MS Java is NOT installed on this system>> c:\%computername%.txt
:goto output
--- Display final screen information for user and write the date in output.txt
utput
echo.>> c:\%computername%.txt
echo.Data collected: %date%>> c:\%computername%.txt
echo.Contents of c:\%computername%.txt:
echo.
echo.###################################################
type c:\%computername%.txt
echo.###################################################
echo.
echo.Please email the file: cutput.txt to nick.rennie@hp.com
goto end
:end
P.S. If anyone can now work out a command line script that will attach the newly created batch file to an email and have the subject set as the hostname, that would be an even better bonus and even less work for me!
>> Edited by beanbag on Friday 1st April 15:07
Sounds like you may be better off using a VBS of JS (script) file and using all the scripting objects available such as the FSO (file system object) and the network one (computer name etc), youy can then use the CDO (or equiv) to send the e-mial.
hope that makes sense... and is not just alphabet spagetti...
hope that makes sense... and is not just alphabet spagetti...
beanbag said:
P.S. If anyone can now work out a command line script that will attach the newly created batch file to an email and have the subject set as the hostname, that would be an even better bonus and even less work for me!
>> Edited by beanbag on Friday 1st April 15:07
pebbledash said:
Sounds like you may be better off using a VBS of JS (script) file and using all the scripting objects available such as the FSO (file system object) and the network one (computer name etc), youy can then use the CDO (or equiv) to send the e-mial.
hope that makes sense... and is not just alphabet spagetti...
beanbag said:
P.S. If anyone can now work out a command line script that will attach the newly created batch file to an email and have the subject set as the hostname, that would be an even better bonus and even less work for me!
>> Edited by beanbag on Friday 1st April 15:07
Unfortunately I can't use VBS or JS. Reason being is the systems I will be testing are servers and it's on a client environment so no can do! (I did ask).
The limitations of the NT CLI i guess!
beanbag said:
Unfortunately I can't use VBS or JS. Reason being is the systems I will be testing are servers and it's on a client environment so no can do! (I did ask).
The limitations of the NT CLI i guess!
Hummmm. if its a 2k or 2003 server the scripting subsystem is installed as part of the O/S not sure you can even remove it...
edited to add. I have a scheduled jub that runs on each of my servers at a predefined time, to archive and cleardown all the log files, and send off an e-mail..
>> Edited by pebbledash on Friday 1st April 15:25
beanbag said:
They're not my systems so I don't want to start playing around with them too much.
Plus I think this output from the batch script gives me all I need and it's very simple so the system owners won't mind running it on their systems.
(I've got about 440 servers to run it on!!!!)
I take the point, but I think its all there as standard, for the script side, and seems sillp not to use it. I have lots of scripts and stuff i use regularly and I dont even look at back files these days, logon scripts sheduled tasks etc are all done in JS or VBS. I am not sure how you will do the e-mail in a batch file, unless you resort to some trick code, or install something else, like sendmail. how about the winmgmts interface?
I have a script that can do a full N/W inventory from a single location cute, but hellish to code .
Could you query all the servers from a central location ? It would save a roll out..
I have had a good think and a play. And I can only think of three ways to send the e-mail.
1) Use the CDO (or equiv) scripting object. easy to use and all is installed by default.. but you say this can't be used.
2) Install a sendmail type util on each server, but I would imagine this is a no go, due to the install requirement.
3) If IIS is installed on the servers, and is configured for e-mail, you could create an e-mail file (using Echo) and then move it into the pickup directory and let the IIS mailer do the send.
.......
>> Edited by pebbledash on Friday 1st April 16:29
1) Use the CDO (or equiv) scripting object. easy to use and all is installed by default.. but you say this can't be used.
2) Install a sendmail type util on each server, but I would imagine this is a no go, due to the install requirement.
3) If IIS is installed on the servers, and is configured for e-mail, you could create an e-mail file (using Echo) and then move it into the pickup directory and let the IIS mailer do the send.
.......
>> Edited by pebbledash on Friday 1st April 16:29
Had a chat with the client. Unfortunately not all servers have IIS running on Querying all the servers from a central location is also a no go due to firewall restrictions.
It sounds complicated but I've created a depot area on an HPUX box where the output files automatically copied to.
A script is running on the HPUX box that at set intervals, if it detects any new output files, emails them to me.
Sounds complicated but the company I'm working in is hellish when it comes to running anything on a Windows server due to security and I've got to know the HPUX chaps quite well so they were very obliging to create this email script for me!
>> Edited by beanbag on Friday 1st April 16:52
It sounds complicated but I've created a depot area on an HPUX box where the output files automatically copied to.
A script is running on the HPUX box that at set intervals, if it detects any new output files, emails them to me.
Sounds complicated but the company I'm working in is hellish when it comes to running anything on a Windows server due to security and I've got to know the HPUX chaps quite well so they were very obliging to create this email script for me!
>> Edited by beanbag on Friday 1st April 16:52
Nice solution.
The joys of UNIX... most unfreindly when its working against you, but sometimes its SOOOOO usefull to have one arround.
The joys of UNIX... most unfreindly when its working against you, but sometimes its SOOOOO usefull to have one arround.
beanbag said:
Had a chat with the client. Unfortunately not all servers have IIS running on them or even installed so that's a definate no go.
It sounds complicated but he's created a depot area on an HPUX box where the output file automatically copy to.
A script is run on the HPUX box that at set intervals, if it detects any new outfiles, emails them to me.
Sounds complicated but the company I'm working in is hellish when it comes to running anything on a Windows server due to security and I've got to know the HPUX chaps quite well so they were very obliging to create this email script for me!
Gassing Station | Computers, Gadgets & Stuff | Top of Page | What's New | My Stuff