expect not working well with banner messages - expect

I'm using expect-lite to communicate with a router. however the router has some customized banner message set and expect doesn't seem to work very well with it. Specifically, when I login in to the router, the cursor was placed at the following location.
***********************************************
* *
* some unuseful info here.. *
* *
***********************************************($cursor)
normally I can just hit enter in an interactive shell and it can then bring me to the normal router shell, I have expected "*" and then send a new line character, but it doesn't seem to work well.
Can you shed some light on this ?
Thanks.

What I would do is add exp_internal 1 somewhere at the beginning of your script, and that way you can see what expect is receiving, and why it is not matching your pattern.
Feel free to add that information to the question if you need some help with interpreting what you get from it.

with the default options to expect ("glob" patterns, documented here), * is a wildcard and will match anything (including nothing). Make sure you're expecting a literal asterisk:
expect -re {\*$}
Here I'm using a regular expression to find an asterisk anchored at the end of the string.

Related

XTerm js not handling special characters like \n "\u001b[H\u001b[2J\u001b[3J" in term.write

I am using Xterm Js to create a console in my web browser, so far I have successfully implemented the functionality on server side but having a problem when it comes to represent the output
When I type in clear command in my XTerm it returns \u001b[H\u001b[2J\u001b[3J which I believe is a correct output from my back-end, however when I write this output using term.write it posts the entire string instead of clearing the screen
Same goes for my ls command it returns <file_name_1>\n<file_name_2>\n<file_name_3>\n It prints all the \n instead of going to a new line.
How do I make XTerm Js NOT to 'sanitize' the output and make those special characters perform their respective task like \n for new line, etc without simply posting the string.

visit a Full URL with parameter value

I'm trying to make a bash script to send a GET requests
also I'm trying to provide a URL access after changing some parameter value
problem:
when I hover over the link it will only underline URL without parameters values(check the following screen)
when I entered the URL it will redirect me to:
http://testphp.vulnweb.com/artists.php?artist=
I'm wondering if there is a solution for this case or not
Thank you in advance
Note that it's the terminal and not your script that decides what's considered part of a URL for the purpose of selecting or clicking.
But what I can suggest is to Use the URL encoding for those special characters instead of explicit special characters:
%27 = Single Quote **'**
%3C = Less than **<**
%3E = More than **>**
For example
URL=http://testphp.vulnweb.com/artists.php?artist=
PARTIAL_URL=$URL%3Cscript%3E
That will be shown http://testphp.vulnweb.com/artists.php?artist=<script>
Maybe that would do the trick

Start firefox from a terminal window, open a text file and position the text shown at a specified line

I would like to improve the help facility in a Fortran program by opening the user guide in a separate browser (Firefox) window whenever the user type a ?
as answer to a question the program asks.
I can use call system('path/firefox -file user_guide.hlp')
to open the help file. But additionally I would like to position the text in the browser window at a specified line in the help text.
I know which lines in the help file that should be relevant for the user because inside the Fortran program I keep track of the commands the user has made (I use a command line interface, no GUI). At present I print these lines in the terminal window running the program but this limits the amount of lines I can print and obscures the program output. With the whole user guide available in a separate window the user may also easily search for additional explanations elsewhere in the user guide, I do not expect he or she will voluntarily read the user guide.
Thanks for any help
Bo Sundman
You cannot go to specific lines but you could try using named anchor tabs. In the help file,
<a name="1"/>
help topic 1
<a name="2"/>
help topic 2
When you issue your call to firefox, to go to anchor 2
system('path/firefox -file user_guide.html#2')
This should work on all browsers. The newer ones will also take id= instead of name=
EDIT
If the above doesn't work, try
system('path/firefox "file://path/user_guide.html#2"')
EDIT 2
If both the firefox path and html file path have spaces, on Windows, 8.3 filenames can be used. Use dir/x to find out what the 8.3 filenames are. Alternatively filenames with spaces can be used; the syntax is pretty weird
call execute_command_line('""C:\...\firefox.exe" "file://x:\...\userguide.html#2""')
start string with '
Use 2 double quotes for the first double quote ""
Add your pathname to firefox
Use 1 double quote to terminate the path name
add a space
Use 1 double quote to start the parameter
Add the parameter
Use 2 double quotes to terminate
end the string with '

bash: how to make a clickable link with query parameters?

I am trying to dump url on the terminal that needs to be clickable, and the url comes with a query parameter. For example --
google='https://www.google.com/search?q='
orgname='foo bar'
gsearch=$google\'$orgname\'
echo "details: $orgname ($gsearch)"
But the problem is that the clickable link totally omits everything after the q=, i.e. does not include the string 'foo bar', please see the image below --
How do I make a clickable link that includes the query (i.e. the whole url in the braces above)?
Please also note that I am adding quote in the search parameter since the it may contain spaces.
Single quotes are not valid in URLs. Use the URL encoding %27 instead:
google='https://www.google.com/search?q='
orgname='foo'
gsearch=$google%27$orgname%27
echo "details: $orgname ($gsearch)"
Note that it's the terminal and not your script that decides what's considered part of a URL for the purpose of selecting or clicking. The above results in
https://www.google.com/search?q=%27foo%27
which is more clickable in most terminals. The script can't specify what's the extent of the URL except through expressing it in such a standard way that each individual terminal emulator has a decent chance of recognizing it.
PS: I don't think Google cares about surrounding single quotes.

Handling difference between strings returned in history change handler

I've got an app that receives urls after the # sign and responds to them with a History ValueChangeHandler. Serious problem: the urls are escaped differently on different browsers.
For example, when I go to #riley%2Blark%40gmail.com, Chrome sends my ValueChangeHandler riley%2Blark%40gmail.com while FireFox sends riley+lark#gmail.com. This is a terrible difference if I want to run URL.decodeQueryString on them because I'll end up with an extra space in Firefox.
How can I handle this, short of writing separate implementations for different browsers?
I can think of two possible solutions:
U could try adding another parameter
to the token so that the token was
of the for
#riley%2Blark%40gmail.com/%2B-a-space
on receiving the token, check the
second part of the token. If the
second part contains a %2B,
urldecode the token. else replace '+' with
You can also try using Location.hash
through JSNI. I reckon the results
ought to be uniform.

Resources