Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

help with dos script 1

Status
Not open for further replies.

taloola69

MIS
Dec 12, 2003
17
GB
i am trying to write a batch file which will run on certain machines in the domain and run the sysinternals (am i allowed to say that) pslist.exe.

what i have is:

echo off
echo.
echo This batch program checks all running processes on whatever computer is specified
echo.
echo **************************
echo Programs running on %1
echo **************************
pause
pslist -m \\%1
echo ***************************
echo FINISHED. EXIT?
echo ***************************
pause


what i am needing to know is where do i get the user input from??

i dont want to have to call for example:
batch.bat \\computername
i want to load the batch file and then have it prompt me to enter a computer name?


AND......i have also another program which i am tyring to run, this one does the same but it already has the cpmputer names entered ie.

echo off
echo.
echo This batch program checks all running processes in U16
echo.
echo **************************
echo Programs running on U16NO1
echo **************************
pause
pslist -m \\u16no1
echo **************************
echo Programs running on U16NO2
echo **************************
pause
pslist -m \\u16no2
echo **************************
echo Programs running on U16NO3
echo **************************
pause
pslist -m \\u16no3
echo **************************
echo Programs running on U16NO4
echo **************************
pause

and so on......

BUT what i really want to do is be able to ping the specified host first and if it pings back i want to execeute the pslist.exe but if it doesnt reply (ie turned off) i want to skip to the next ping of the next computer in the list.

something like:

echo off
echo.
echo This batch program checks all running processes in U16
echo.
echo **************************
echo Programs running on U16NO1
echo **************************
ping 10.0.0.0
pause
echo ***************************************
echo Do you now want to run pslist on U16NO1
echo ***************************************
IF I SAY YES IT WILL RUN THE NEXT LINE BUT IF I SAY NO IT WILL SKIP TO PINGING THE NEXT HOST.....
pslist -m \\u16no1
pause
ping 10.0.0.1
......... and so on...

i think it would be quite easy to do but am unsure of the IFs and CALL commands etc.

please help a wannabe scripter?

taloola
 
Depending on the DOS you're using it may be possible to use the 'CHOICE' command within the batch--to be used as an 'input' to some degree. At the DOS prompt type: CHOICE /? to get further info.

Another options is to have the comp.names in a text file and redirect the text file to the batch for input & processing.

Alternatively, the easiest way would be to use QB (which is pretty much available) on Windows machines. If this is a route you want to go, let us know.

Otherwise, the way you are describing the way you want a batch to prompt you for a comp.name, cannot be done in a batch file without alot of scripting.


Let us know what's your pleasure.
--MiggyD
 
Are you sure that QBasic is available on the machine that will be running this code?
 
if not im sure i could get it installed no problem.

i take it its quite easily downloadable etc?

 
There are other posts here that deal with locating QB on the installation disks/CDs. You should scan some of the previous posts for this information.

I found an old file--I seldom use now but keep "just in case"--and modified it slightly. Remember, this is contingent that ALL the computers all have the same base name with an incremented numerical suffix.

Simply copy the following below:

[red]'-----------------------------------------------------------------[/red]
'-Constant elements [you can modify these as necessary]
CONST BaseCompName = "u16no"
CONST BaseAddress = "10.0.0."
'CONST BaseAddress = "127.0.0." '--this is for testing purposes
CONST TempFile = "MiggyD.tmp"
CONST MaxCompNum = 10

'-Variable(s) to be used in SHELLing
strDump$ = " "

'-Initilizing global variable(s)
TempPingFile$ = ENVIRON$("TMP") + "\" + TempFile
DIM ActiveComp(MaxCompNum, 2) AS STRING
FOR Cycle = 0 TO MaxCompNum
ActiveComp(Cycle, 0) = "I"
ActiveComp(Cycle, 1) = BaseCompName + LTRIM$(STR$(Cycle))
ActiveComp(Cycle, 2) = BaseAddress + LTRIM$(STR$(Cycle))
NEXT Cycle


'-First Screen
CLS
PRINT "This program checks all running processes in U16 group."
PRINT STRING$(79, 196)
LOCATE 25, 1
PRINT "--Press ESC key to END program--";
VIEW PRINT 3 TO 23
CLS 2
FOR ICount = 1 TO 100 '-clear KB buffer
strDump$ = INKEY$
NEXT ICount
intDump = 0: ICount = 0 '-reset counter(s)


'-Second Screen -- Ping testing
DO
PRINT "Checking Activity: "; ActiveComp(intDump, 1)
strDump$ = "ping " + ActiveComp(intDump, 2) + " > " + TempPingFile$
IF INKEY$ = CHR$(27) THEN GOTO UserTerminate
SHELL strDump$ '-This will ping the addy
SLEEP 1 '-give computer time to write file
OPEN TempPingFile$ FOR INPUT AS 11
DO
LINE INPUT #11, Trash$
IF INSTR(LCASE$(Trash$), ", received =") THEN
Trash$ = MID$(Trash$, INSTR(LCASE$(Trash$), "received =") + 10, 3)
IF VAL(Trash$) > 0 THEN
PRINT " Computer is active...Do you want to"
INPUT &quot; run PSList? (default=N) <y/N> &quot;; Trash$
IF LEFT$(UCASE$(Trash$), 1) = &quot;Y&quot; THEN
strDump$ = &quot;PSlist -m \\&quot; + ActiveComp(intDump, 1)
SHELL strDump$
END IF
ActiveComp(intDump, 0) = &quot;A&quot; '-set to ACTIVE
ICount = ICount + 1 '-for use below
END IF
END IF
IF INKEY$ = CHR$(27) THEN GOTO UserTerminate
LOOP UNTIL EOF(11)
CLOSE 11
intDump = intDump + 1
LOOP UNTIL intDump > MaxCompNum
'-Possible network failure if = zero.
IF ICount = 0 THEN
CLS 2
COLOR 14
PRINT &quot;There are no active links available.&quot;
PRINT &quot;-->check network connection cable&quot;
PRINT &quot;-->check network server is active&quot;
PRINT
COLOR 15
SLEEP 5
GOTO UserTerminate
END IF


'-Third Screen -- Build screen menu
DIM CompMenu(ICount, 1) AS STRING
CLS 2
PRINT &quot;----------Active links:&quot;
ICount = 1
FOR Cycle = LBOUND(ActiveComp) TO UBOUND(ActiveComp)
IF ActiveComp(Cycle, 0) = &quot;A&quot; THEN
CompMenu(ICount, 0) = ActiveComp(Cycle, 1) '-computer name
CompMenu(ICount, 1) = ActiveComp(Cycle, 2) '-ip addy
PRINT CompMenu(ICount, 0),
ICount = ICount + 1
END IF
NEXT Cycle
'-- Cursor Movement
' ** following section(s) were removed because the above code
' ** pretty much does what you are looking for.
' ** do not forget, you can press the escape key any time to exit.
' ** -- MiggyD

UserTerminate:
CLOSE
KILL TempPingFile$
VIEW PRINT
END
[red]'-----------------------------------------------------------------[/red]

After you have copied this to a *.BAS file, run QB and open this file then press F5 to run it.

Hope this helps.
--MiggyD
 
no, and i never go a chance to say thanks to you either.......

Thanks very much......

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top