Page 1 of 2 12>
Topic Options
#16750 - 2002-01-28 10:15 PM To Shell or not to Shell?
Austin Offline
Seasoned Scripter

Registered: 2002-01-24
Posts: 439
How about this shell out... whats wrong?

shell '%compspec% for /F "Skip=2 tokens=2 delims=." %%A in ('ping -n 1 %clientname%') do set TSLoc=%%A'
$location=%TSLoc%
goto tsprtmap

_________________________
Austin Henderson

Top
#16751 - 2002-01-28 10:28 PM Re: To Shell or not to Shell?
Bryce Offline
KiX Supporter
*****

Registered: 2000-02-29
Posts: 3167
Loc: Houston TX
First:

What are you trying to do?

Top
#16752 - 2002-01-28 10:30 PM Re: To Shell or not to Shell?
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11629
Loc: CA
Hello Austin,

You many need to use the /C on the comspec and you may need to use a single % since you are calling it from a command line and not from a batch file. Does the command work from a command prompt if you call it EXACTLY as you have it here in the code? Verify with using a variable as the command without the SHELL, then calling the variable so as to show on screen what the command is trying to run.

I have found that trying to call a FOR command from a shell out from KiX is difficult trying to get all the proper quote marks, as they do make a difference to the FOR command as well.

If you have too much trouble you may want to try creating a batch file on the fly and shelling out and running the batch file.

Top
#16753 - 2002-01-28 10:35 PM Re: To Shell or not to Shell?
Austin Offline
Seasoned Scripter

Registered: 2002-01-24
Posts: 439
basically what I am trying to do is different based upon what the user is doing... this command is for if the user is hitting a terminal server I need to snag the ip of the workstation hitting the terminal server... so that I can determine where they are ane thus what to do from that point. If the user is hitting this script locally I use

$TSUser="N"
$octetarray=split ("@ipaddress0",".")
$location=val($octetarray[1])

to get the ip but this will not work for me when they are hitting the TS.. I have the command working in bat but I am a baby in kix and just trying to convert.

Thanks

_________________________
Austin Henderson

Top
#16754 - 2002-01-28 10:37 PM Re: To Shell or not to Shell?
Austin Offline
Seasoned Scripter

Registered: 2002-01-24
Posts: 439
very interesting sugguestion... now my next question can I set a variable in kix that I set in that bat file I called out in the shell? so that I can use that variable in the kix script?

thanks

_________________________
Austin Henderson

Top
#16755 - 2002-01-28 10:38 PM Re: To Shell or not to Shell?
Austin Offline
Seasoned Scripter

Registered: 2002-01-24
Posts: 439
In bat I am positive that

for /F "Skip=2 tokens=2 delims=." %%A in ('ping -n 1 %clientname%') do set LOCATION=%%A

works...

_________________________
Austin Henderson

Top
#16756 - 2002-01-28 10:44 PM Re: To Shell or not to Shell?
Austin Offline
Seasoned Scripter

Registered: 2002-01-24
Posts: 439
for /F "Skip=2 tokens=2 delims=." %A in ('ping -n 1 %clientname%') do set LOCATION=%A

works from command line

_________________________
Austin Henderson

Top
#16757 - 2002-01-28 10:47 PM Re: To Shell or not to Shell?
Austin Offline
Seasoned Scripter

Registered: 2002-01-24
Posts: 439
what does /C do for me in shell..

first problem is that it is comspec not compspec.. sorry that was dumb.. but it still doesnt work

_________________________
Austin Henderson

Top
#16758 - 2002-01-28 11:02 PM Re: To Shell or not to Shell?
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Austin,
The KiX SHELL command enables you to run a program. %comspec% is an environment variable the points to the command interpreter need to run certain DOS programs and internal DOS commands which include batch commands. On NT systems %comspec% would likely be "C:\WINNT\system32\cmd.exe" The /c switch, actually "C:\WINNT\system32\cmd.exe /c" tells the command interpreter to run the command that follows. You can do a "CMD /?" from a DOS box for more info.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#16759 - 2002-01-28 11:23 PM Re: To Shell or not to Shell?
Austin Offline
Seasoned Scripter

Registered: 2002-01-24
Posts: 439
OK i tried the bat method

shell '%comspec% /C %WINDIR%\Login\Kix\tsping.bat'
$location=%TSLoc%

but it seems as if the variable TSLoc is not coming back set from the bat file.. the bat file gets the variable but will it stay set when it returns to the kix script?

_________________________
Austin Henderson

Top
#16760 - 2002-01-28 11:39 PM Re: To Shell or not to Shell?
Austin Offline
Seasoned Scripter

Registered: 2002-01-24
Posts: 439
If I run the bat file by itself I can confirm that the TSLoc variable is set
_________________________
Austin Henderson

Top
#16761 - 2002-01-29 12:22 AM Re: To Shell or not to Shell?
Austin Offline
Seasoned Scripter

Registered: 2002-01-24
Posts: 439
It seems that the variable is not returning is there a way to make it stick when I set it in the bat file that is called with the shell command so that I can set it in the kix script?
_________________________
Austin Henderson

Top
#16762 - 2002-01-29 12:30 AM Re: To Shell or not to Shell?
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Austin,
When you SHELL out to another command interpreter, it has its own copy of the environment. You would need to use a utility to copy its environment to the parent running KiX.

Why not try keeping it all in KiX? If you want insight into IP subnet checking within KiX, look to Sealeapord's IsInSubnet() - Checks if a given IP address is in a specified subnet UDF.

_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#16763 - 2002-01-29 12:34 AM Re: To Shell or not to Shell?
Austin Offline
Seasoned Scripter

Registered: 2002-01-24
Posts: 439
agreed.. but note that I am using the ip address of %clientname%... can I make this work?
_________________________
Austin Henderson

Top
#16764 - 2002-01-29 12:38 AM Re: To Shell or not to Shell?
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Even though Jens' example shows an IP for NetworkID, you can substitute with a var. I did a quick test using:

$ClientName=%clientname%
isinsubnet('10.0.0.1','$ClientName','255.0.0.0')

_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#16765 - 2002-01-29 12:41 AM Re: To Shell or not to Shell?
Austin Offline
Seasoned Scripter

Registered: 2002-01-24
Posts: 439
I suppose I am still confused.. I am looking to get X in the address: A.X.A.A and store it as a variable $location. but the tricky part is I need it to get the IP of %clientname% I do not understand the link that you sent me. I am sorry this is only my second day using kix.
_________________________
Austin Henderson

Top
#16766 - 2002-01-29 12:43 AM Re: To Shell or not to Shell?
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
I thought you might just use Jens' UDF for inspiration to write one that returns the particular octet you're looking for as does the one-liner batch you have.

Jens' UDF just returns a true or false.

_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#16767 - 2002-01-29 12:43 AM Re: To Shell or not to Shell?
Austin Offline
Seasoned Scripter

Registered: 2002-01-24
Posts: 439
Is there not simply a way in bat file that I could set the variable to be persistent for that user? Could not be local machine because it will changed based upon where the TS users are coming from
_________________________
Austin Henderson

Top
#16768 - 2002-01-29 12:55 AM Re: To Shell or not to Shell?
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
As I mentioned before, there are utilities that can copy the environment from the child to the parent. A quick search on Google may turn something up. WinSet.exe comes to mind, but to be honest, I've never used it.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#16769 - 2002-01-29 12:55 AM Re: To Shell or not to Shell?
Austin Offline
Seasoned Scripter

Registered: 2002-01-24
Posts: 439
I have corrected the issue by checking the computername in the first bat file that is called and setting the variable with my ping command at that point.. it hols this way. Any sugguestions are still requested.

Thank you

_________________________
Austin Henderson

Top
Page 1 of 2 12>


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

Who's Online
0 registered and 1183 anonymous users online.
Newest Members
batdk82, StuTheCoder, M_Moore, BeeEm, min_seow
17885 Registered Users

Generated in 0.075 seconds in which 0.028 seconds were spent on a total of 13 queries. Zlib compression enabled.

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