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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

interactive shell within perl program? 1

Status
Not open for further replies.

TheNewbie81

Technical User
Feb 12, 2007
15
IE
Hi,

Im trying to start an x25 session from within a perl script. Basically im trying to create a small script which allows a user to enter an x25 address, the script will then execute a x25 command and connect to a device and display the shell of the device so that it can then receive commands etc. is it possible to kick of a shell from within a perl program?
 
I don't really understand what you're trying to do, but you can start a shell from within a perl script by enclosing it within back quotes. For example, to open a bash shell from within a perl script you could the following. Hope this helps.

#!/usr/bin/perl
`bash`;
 
cheers for responding.

abit of background would help i suppose.

I want to the program to be able to start a x25 session to a HLR. in the perl script i will have options for the user to specify the HLR they wish to connect to, this will then open a shell towards this network node that the use can then do what they like in this shell, so within the script i need to call something along the lines of the following to establish this x25 session :

#!/usr/bin/perl

#Choice of HLR
{
1 = 1011235
2 = 1011234
3 = 1011233
4 = 1011232
}

#get input from user

#execute this command substituting the x25 address with the user choice

/mds1/ftm/bin/mtp_protocol -c "/dev/x25 1_1011235" -l 2 -P "AXE>" -Q "AXE>" -R "AXE>"


#ideally this will then establish a shell to the HLR node allowing the user access to the node
 
if all you want the perl script for is to get the user input and nothing else, look into exec()

Code:
[gray]#!/usr/bin/perl[/gray]
[url=http://perldoc.perl.org/functions/use.html][black][b]use[/b][/black][/url] [green]warnings[/green][red];[/red]
[black][b]use[/b][/black] [green]diagnostics[/green][red];[/red]


[gray][i]#Choice of HLR[/i][/gray]
[url=http://perldoc.perl.org/functions/my.html][black][b]my[/b][/black][/url] [blue]%choices[/blue] = [red]([/red]
[fuchsia]1[/fuchsia] => [fuchsia]1011235[/fuchsia],
[fuchsia]2[/fuchsia] => [fuchsia]1011234[/fuchsia],
[fuchsia]3[/fuchsia] => [fuchsia]1011233[/fuchsia],
[fuchsia]4[/fuchsia] => [fuchsia]1011232[/fuchsia],
[red])[/red][red];[/red]

[maroon]enter[/maroon][red]([/red][red])[/red][red];[/red]

[url=http://perldoc.perl.org/functions/sub.html][black][b]sub[/b][/black][/url] [maroon]enter[/maroon] [red]{[/red]
   [url=http://perldoc.perl.org/functions/print.html][black][b]print[/b][/black][/url] [red]"[/red][purple]Enter a choice [1 2 3 or 4]: [/purple][red]"[/red][red];[/red]
   [url=http://perldoc.perl.org/functions/chomp.html][black][b]chomp[/b][/black][/url] [red]([/red][black][b]my[/b][/black] [blue]$in[/blue] = <STDIN>[red])[/red][red];[/red]
   [olive][b]if[/b][/olive] [red]([/red][url=http://perldoc.perl.org/functions/exists.html][black][b]exists[/b][/black][/url] [blue]$choices[/blue][red]{[/red][blue]$in[/blue][red]}[/red][red])[/red] [red]{[/red]
      [url=http://perldoc.perl.org/functions/exec.html][black][b]exec[/b][/black][/url][red]([/red][red]"[/red][purple]/mds1/ftm/bin/mtp_protocol -c [purple][b]\"[/b][/purple]/dev/x25 1_[blue]$choices[/blue]{[blue]$in[/blue]}[purple][b]\"[/b][/purple]  -l 2 -P [purple][b]\"[/b][/purple]AXE>[purple][b]\"[/b][/purple] -Q [purple][b]\"[/b][/purple]AXE>[purple][b]\"[/b][/purple] -R [purple][b]\"[/b][/purple]AXE>[purple][b]\"[/b][/purple][/purple][red]"[/red][red])[/red][red];[/red]
   [red]}[/red]
   [olive][b]else[/b][/olive] [red]{[/red]
      [maroon]enter[/maroon][red]([/red][red])[/red][red];[/red]
   [red]}[/red]
[red]}[/red]
[tt]------------------------------------------------------------
Pragmas (perl 5.8.8) used :
[ul]
[li]diagnostics - Produce verbose warning diagnostics[/li]
[li]warnings - Perl pragma to control optional warnings[/li]
[/ul]
[/tt]

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top