Page 1 of 1 1
Topic Options
#199024 - 2010-07-16 12:31 PM get a variable from the shell command
Roh Offline
Fresh Scripter

Registered: 2009-09-29
Posts: 7
Loc: Germany
Hi

is it possible to get the variable from a "shell" command?
we work with vmware view client and i want to read out some variables from the basic system like processor etc.
The vmware client works with win xp and the basic system is a linux client.
now i want to use the linux uname command to read out the linux hardware. the command i use from the windows client to read out the linux machine is like "plink -ssh -l root -pw xyz 172.25.xx.yy uname -p".
then i get as result for example "Intel(R) Atom(TM) CPU 330 @ 1.60GHz".
in kix i can write the command shell " plink -ssh -l root -pw xyz 172.25.xx.yy uname -p" and i can see the same result.
is it possible to get this result as a variable for writing it for example in a database?
thank for some ideas

Top
#199025 - 2010-07-16 01:40 PM Re: get a variable from the shell command [Re: Roh]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4402
Loc: New Jersey
Sure - look for the UDF called WSHpipe(). It allows you to run a command via WSH and capture the output.
 Code:
$aResult = WSHpipe('plink -ssh -l root -pw xyz 172.25.xx.yy uname -p')
This returns an array of output lines that you can enumerate.

The copy here combines STDOUT and STDERR into a single array. I have a modified version on my web site's Resources page that returns a 2-element array of arrays, with STDOUT in one element and STDERR in the other.

Either one will do what you want - return the output of a command in a variable. The other common way is to redirect the output to a file and then use Open/ReadLine to read the data, but that is (in my opinion) messy.

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#199026 - 2010-07-16 02:12 PM Re: get a variable from the shell command [Re: Glenn Barnas]
Roh Offline
Fresh Scripter

Registered: 2009-09-29
Posts: 7
Loc: Germany
hi glenn, thank you for your answer that seems not bad.
but look if i try it like you has written i get as result "wshpipe".

i think i have to activate first the udf.
how does it work activating udf?

Frank

Top
#199028 - 2010-07-16 03:54 PM Re: get a variable from the shell command [Re: Roh]
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4572
Loc: USA
Wshpipe returns an array... so you will either have to loop through the results or target the specific line you want.

for each $result in wshpipe("yourcommandhere")
? $result
next

or
$results=wshpipe("yourcommandhere")
$result0=$results[0]
$result1=$results[1]
;...


WSHPipe -
http://www.kixtart.org/forums/ubbthreads.php?ubb=showflat&Number=83201

The rest of the UDFs are here -
http://www.kixtart.org/forums/ubbthreads.php?ubb=postlist&Board=7&page=1

How to use UDFs -
http://www.kixtart.org/forums/ubbthreads.php?ubb=showflat&Number=81943#Post81943


Edited by Allen (2010-07-16 04:15 PM)
_________________________
(... better days ahead)

Top
#199034 - 2010-07-17 12:15 PM Re: get a variable from the shell command [Re: Allen]
Roh Offline
Fresh Scripter

Registered: 2009-09-29
Posts: 7
Loc: Germany
hi thank you for your answers.
i have tested your suggestions but it doesnīt work. I get an error "invalid function call, missing ')'
but i canīt see the reason for this error because iīm thinking i have written all brackets isnīt it...?

here is my code:

function wshpipe ()
$test = wshpipe('plink -ssh -l root -pw xyz 129.0.xx.yy uname -p')



endfunction

for each $test in wshpipe("plink -ssh -l root -pw xyz 129.0.xx.yy uname -p")
? $test
next

where is the error?
thank you for your answers

Frank

Top
#199036 - 2010-07-17 04:11 PM Re: get a variable from the shell command [Re: Roh]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4402
Loc: New Jersey
You need to download the WSHpipe UDF (either here or from my site) and either paste a copy of the function into your script, or use CALL 'path\to\whspipe.udf' to load it at run-time.

Please review ALL of the links that Allen posted, particularly 'How to use UDFs'.

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#199037 - 2010-07-17 04:38 PM Re: get a variable from the shell command [Re: Glenn Barnas]
Roh Offline
Fresh Scripter

Registered: 2009-09-29
Posts: 7
Loc: Germany
oh finally i have understood how does it works.
i have to use the original udf code either by copiing into the script or calling it with the call command.

this was the secret for me till yet.

thank you all!

frank

Top
Page 1 of 1 1


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

Who's Online
0 registered and 2220 anonymous users online.
Newest Members
Viginette, ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder
17888 Registered Users

Generated in 0.204 seconds in which 0.138 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