Tcl expect error with spawning telnet: invalid command name - scripting

How do I send just a "return" to this telnet server:
got New York
spawn telnet rainmaker.wunderground.com
Trying 35.160.169.47...
Connected to rainmaker.wunderground.com.
Escape character is '^]'.
------------------------------------------------------------------------------
* Welcome to THE WEATHER UNDERGROUND telnet service! *
------------------------------------------------------------------------------
* *
* National Weather Service information provided by Alden Electronics, Inc. *
* and updated each minute as reports come in over our data feed. *
* *
* **Note: If you cannot get past this opening screen, you must use a *
* different version of the "telnet" program--some of the ones for IBM *
* compatible PC's have a bug that prevents proper connection. *
* *
* comments: jmasters#wunderground.com *
------------------------------------------------------------------------------
Press Return to continue:invalid command name ""
while executing
"[tutstack::connect "New York"]"
(file "main.tcl" line 6)
code:
package provide weather 1.0
package require Tcl 8.5
package require Expect
namespace eval ::tutstack {
}
proc ::tutstack::connect {arg1} {
puts "got $arg1"
spawn telnet rainmaker.wunderground.com
set telnet $spawn_id
expect -nocase "Press Return to continue:"
send "$arg1"
}
main:
lappend auto_path /home/thufir/NetBeansProjects/spawnTelnet/telnet/api
package require weather 1.0
[tutstack::connect "New York"]
I've tried variations on send "\r" without success.
Ultimately, would want the script to only partially automate responses and leave the connection open.
expected result:
thufir#dur:~/NetBeansProjects/spawnTelnet/telnet$
thufir#dur:~/NetBeansProjects/spawnTelnet/telnet$ telnet rainmaker.wunderground.com
Trying 35.160.169.47...
Connected to rainmaker.wunderground.com.
Escape character is '^]'.
------------------------------------------------------------------------------
* Welcome to THE WEATHER UNDERGROUND telnet service! *
------------------------------------------------------------------------------
* *
* National Weather Service information provided by Alden Electronics, Inc. *
* and updated each minute as reports come in over our data feed. *
* *
* **Note: If you cannot get past this opening screen, you must use a *
* different version of the "telnet" program--some of the ones for IBM *
* compatible PC's have a bug that prevents proper connection. *
* *
* comments: jmasters#wunderground.com *
------------------------------------------------------------------------------
Press Return to continue:
Press Return for menu
or enter 3 letter forecast city code--
WEATHER UNDERGROUND MAIN MENU
******************************
1) U.S. forecasts and climate data
2) Canadian forecasts
3) Current weather observations
4) Ski conditions
5) Long-range forecasts
6) Latest earthquake reports
7) Severe weather
8) Hurricane advisories
9) Weather summary for the past month
10) International data
11) Marine forecasts and observations
12) Ultraviolet light forecast
X) Exit program
C) Change scrolling to screen
H) Help and information for new users
?) Answers to all your questions
Selection:
Ideally, I'd like some responses automated but would ultimately want to enter text which is sent to the telnet server as well -- depending on the logic. But for right now, just trying to script some responses.
see also:
expect - telnet connection

thanks meuh:
thufir#dur:~/NetBeansProjects/spawnTelnet/telnet$
thufir#dur:~/NetBeansProjects/spawnTelnet/telnet$ tclsh main.tcl
got New York
spawn telnet rainmaker.wunderground.com
Trying 35.160.169.47...
Connected to rainmaker.wunderground.com.
Escape character is '^]'.
------------------------------------------------------------------------------
* Welcome to THE WEATHER UNDERGROUND telnet service! *
------------------------------------------------------------------------------
* *
* National Weather Service information provided by Alden Electronics, Inc. *
* and updated each minute as reports come in over our data feed. *
* *
* **Note: If you cannot get past this opening screen, you must use a *
* different version of the "telnet" program--some of the ones for IBM *
* compatible PC's have a bug that prevents proper connection. *
* *
* comments: jmasters#wunderground.com *
------------------------------------------------------------------------------
Press Return to continue:thufir#dur:~/NetBeansProjects/spawnTelnet/telnet$
thufir#dur:~/NetBeansProjects/spawnTelnet/telnet$
thufir#dur:~/NetBeansProjects/spawnTelnet/telnet$ cat main.tcl
lappend auto_path /home/thufir/NetBeansProjects/spawnTelnet/telnet/api
package require weather 1.0
tutstack::connect "New York"
thufir#dur:~/NetBeansProjects/spawnTelnet/telnet$
thufir#dur:~/NetBeansProjects/spawnTelnet/telnet$ cat api/weather.tcl
package provide weather 1.0
package require Tcl 8.5
package require Expect
namespace eval ::tutstack {
}
proc ::tutstack::connect {arg1} {
puts "got $arg1"
spawn telnet rainmaker.wunderground.com
set telnet $spawn_id
expect -nocase "Press Return to continue:"
send "$arg1"
}
thufir#dur:~/NetBeansProjects/spawnTelnet/telnet$

Related

Using X11 forwarding to display gnuplot through ssh

I'm using ssh to do some computations on a remote server, which is in linux whereas my computer is Windows 10. I would like to be able to see plots from gnuplot, but a priori it does not plot anything.
From what I've read, it seems I need to setup X11 forwarding. I installed VcXsrv X server with everything default, and set "export DISPLAY=localhost:0" in the ssh terminal, but then I get an error like pictured below.
From here it seems less clear to me what I should do. It seems many people have a variety of issues which lead to this error, but I don't think I'm doing anything particularly complicated. Some things have mentioned checking some kind of config file or trying something like localhost:10 or 137 or something else, but I'm not even sure if my profile has that kind of config file, and I have no clue how to choose what number to put after localhost.
I'm quite new to this kind of thing so any help is appreciated.
I cannot help with the question of how to get the Windows end of an X11 connection working, but depending on the resolution or type of graphics output needed you may be able to use one of the other gnuplot output modes.
"set term dumb" will send low resolution character-cell graphics back to the terminal window you are typing in. This should work anywhere. The output would look like this:
1 + ***
| ** **
| * * sinc(x) *******
0.8 | * *
| * *
| * *
0.6 | * *
| * *
| * *
0.4 | * *
| * *
0.2 | * *
| ** * * **
| **** *** * * *** ****
0 | *** ** * * ** ***
|** ** * * ** ***
| *** ** ** ***
-0.2 | ****** ******
|
|
-0.4 +-------------------------------------------------------------------------------+
-10 -5 0 5 10
If on the Windows end you run a terminal emulator capable of sixel graphics, then much higher resolution color graphics can be sent directly back to the terminal using "set terminal sixel". See screenshot below.
More complicated options are also possible that involve piping files (png jpeg svg pdf ...) back through the x11 connection for separate display on the Windows end.

Jupyter: export as PDF when notebook itself has LaTeX included

I have an IPython notebook, and I want to export it as a pdf with latex. This works for notebooks which do not contain LaTeX themselves, but when I directly use latex inside the notebook and then try to import it as an pdf, I get the following error:
nbconvert failed: PDF creating failed, captured latex output:
Failed to run "['xelatex', 'notebook.tex', '-quiet']" command:
This is XeTeX, Version 3.141592653-2.6-0.999993 (TeX Live 2021/Arch Linux) (preloaded format=xelatex)
restricted \write18 enabled.
entering extended mode
(./notebook.tex
LaTeX2e <2020-10-01> patch level 4
L3 programming layer <2021-02-18>
(/usr/share/texmf-dist/tex/latex/base/article.cls
Document Class: article 2020/04/10 v1.4m Standard LaTeX document class
(/usr/share/texmf-dist/tex/latex/base/size11.clo))
... more sty files (I shortened the log)
(/usr/share/texmf-dist/tex/latex/jknapltx/mathrsfs.sty)
No file notebook.aux.
(/usr/share/texmf-dist/tex/latex/base/ts1cmr.fd)
(/usr/share/texmf-dist/tex/latex/caption/ltcaption.sty)
*geometry* driver: auto-detecting
*geometry* detected driver: xetex
*geometry* verbose mode - [ preamble ] result:
* driver: xetex
* paper: <default>
* layout: <same size as paper>
* layoutoffset:(h,v)=(0.0pt,0.0pt)
* modes:
* h-part:(L,W,R)=(72.26999pt, 469.75502pt, 72.26999pt)
* v-part:(T,H,B)=(72.26999pt, 650.43001pt, 72.26999pt)
* \paperwidth=614.295pt
* \paperheight=794.96999pt
* \textwidth=469.75502pt
* \textheight=650.43001pt
* \oddsidemargin=0.0pt
* \evensidemargin=0.0pt
* \topmargin=-37.0pt
* \headheight=12.0pt
* \headsep=25.0pt
* \topskip=11.0pt
* \footskip=30.0pt
* \marginparwidth=59.0pt
* \marginparsep=10.0pt
* \columnsep=10.0pt
* \skip\footins=10.0pt plus 4.0pt minus 2.0pt
* \hoffset=0.0pt
* \voffset=0.0pt
* \mag=1000
* \#twocolumnfalse
* \#twosidefalse
* \#mparswitchfalse
* \#reversemarginfalse
* (1in=72.27pt=25.4mm, 1cm=28.453pt)
(/usr/local/share/texmf/tex/latex/ucs/ucsencs.def)
(/usr/share/texmf-dist/tex/latex/hyperref/nameref.sty
(/usr/share/texmf-dist/tex/latex/refcount/refcount.sty)
(/usr/share/texmf-dist/tex/generic/gettitlestring/gettitlestring.sty))
Package hyperref Warning: Rerun to get /PageLabels entry.
(/usr/share/texmf-dist/tex/latex/amsfonts/umsa.fd)
(/usr/share/texmf-dist/tex/latex/amsfonts/umsb.fd)
(/usr/share/texmf-dist/tex/latex/jknapltx/ursfs.fd)
LaTeX Warning: No \author given.
! Missing $ inserted.
<inserted text>
$
l.393 \begin{matrix}
?
! Emergency stop.
<inserted text>
$
l.393 \begin{matrix}
No pages of output.
Transcript written on notebook.log.
I honestly don't know what I should do with this.
What I also noticed by using the command line was, that generating the tex file works fine. But then converting it to a pdf wiht pdflatex yields the same error as above.
The notebook uses latex like this:

How to understand the output of rabbitmqctl commands

$rabbitmqctl list_queues
Timeout: 60.0 seconds ...
Listing queues for vhost / ...
privateTransactionQ 2
amq.gen-o9dl3Zj7HxS50gkTC2xbBQ 0
task_queue 0
Output of rabbitmqctl looks like this. I cant make out what each column is meant for. How can I see the meaning of each column?
There is no "easy" solution for this, but we're IT and we can build them. I'm not an expert in RabbitMQ nor in programming, but I'll give my best to give a good answer to this one, just in case someone lands in here looking for help.
Let's take the exact case of listing the queues from rabbitmqctl console. By typing "rabbitmqctl" you get the list of available commands:
Commands:
[...]
list_queues [-p <vhost>] [--online] [--offline] [--local] [<queueinfoitem> ...] [-t <timeout>]
[...]
Assuming you know what a vhost and queue are, let's say you want to list all the queues in vhost "TEST", then you would need to type:
> rabbitmqctil list_queues -p TEST
Timeout: 60.0 seconds ...
Listing queues for vhost TEST ...
test.queue 0
By default, you only get the "name" of the queue and its "current depth".
Where do you find all the parameters of the queues? Pay special attention to the word "queueinfoitem" in the help instruction you typed first. If you see the rabbitmqctl help instructions (by typing "rabbitmqctl"), at the end of the instruction you can see a list of available options for the parameter "".
Now let's see an example where you want to see a more advanced status of the queue, per say: messages ready in queues, messages in status unacknowledged, messages RAM, consumers, consumer's memory utilization, state of the queue and of course, its name.
You are right about one thing: rabbitmqctl doesn't return the result in a friendly way. By default, you get this:
rabbitmqctl list_queues -p TEST messages_ready, messages_unacknowledged, messages_ram, consumers, consumer_utilisation, state, name
Timeout: 60.0 seconds ...
Listing queues for vhost TEST ...
0 0 0 0 running test.queue
But with a bit of immagination, you can achieve this:
----------------------------------------------------------
Msg. * Msg. * Msg. ** ** Cons. ** **** Name
Rdy * Unack * RAM *** Cons. * Util. ** State ***
----------------------------------------------------------
0 0 0 0 running test.queue
It's no big deal, but it's better than the default.
I achieved that with a small python script:
import os
vhosts = os.popen("rabbitmqctl list_vhosts name").read()
logging.info(vhosts)
vhosts = vhosts.split("\n",1)[1]
vhosts = vhosts[:-1]
vhosts = vhosts.split("\n")
for vhost in vhosts:
header_a = "Msg. * Msg. * Msg. ** ** Cons. ** **** Name\n"
header_b = "Rdy * Unack * RAM *** Cons. * Util. ** State *** \n"
dash = "----------------------------------------------------------\n"
queues = os.popen("rabbitmqctl list_queues -p " + vhost + " messages_ready, messages_unacknowledged, messages_ram, consumers, consumer_utilisation, state, name").read()
queues = queues.split("\n",2)[2]
queues_list = dash + header_a + header_b + dash + queues
print(queues_list)
Of course this can be improved in so many ways and critics are always welcome, I still hope it helps someone.
Cheers.

Automating SQL script

I am new to programming world. I have a SQL script which needs to be automated. The automation required is as follows :
1) Script should run every sunday
2) Automatically dump the results in to DUMP_YYYYMMDDHH24MISS.txt
3) Result set is tar gziped
4) upload to SFTP URL with provided username and password.
I am using :
UNIX,
Vertica DB
Can the Gurus here please help ?
This is really 4 questions and should probably asked as such. To answer in the current format though:
1) Schedule a Task Automatically - Crontab
In the terminal, type crontab -e.
If you want something every Sunday at 1am, add the following line:
0 1 * * * 0 /path/to/script/script.sh
This will execute the script every Sunday.
2) Setting the output of the command
I'm only familiar with oracle. The format is probably similar. In order to get the filename as you want it, you'd use the date function as follows. (This is how I would do it in with Oracle):
d=$(date +%Y%M%D%H%M)
var=$(sqlplus -s / as blahblahblah
select * from stuff;
exit
EOF
)
file_name=DUMP_${d}MISS.txt
echo "${var}" >> ${file_name}
Note that your date command is probably different, if you do a man page on date it will tell you which parameters you'd need to get the date formatted as you like.
3) Taring the output
tar -xvf ${file_name}
4) Send over SFTP
You'd have to authenticate the sftp, that is beyond the scope of what anyone can answer without more details. Once you have the machines setup to authenticate, you would do:
sftp username#server<<EOF
put ${file_name}
EOF

gmail api to mark all messages as read

I recently switched permanently to the plain html version of gmail because it plays better with vimperator and now I have 4000 unread messages that were hidden in the social and promotion tabs. I want to mark all those as read. Is there a way to do that without requesting for each message like they do here with imaplib
If you want to mark absolutely everything in your INBOX as read, execute this IMAP command after logging in and SELECTing the INBOX:
tag STORE 1:* +FLAGS (\Seen)
You can do this with imaplib, any socket library, or just a SSH enabled TCP program, such as socat or openssl s_client.
Here's a transcript of the commands necessary to mark all messages read with GMail:
$ openssl s_client -connect imap.gmail.com:993 -crlf
* OK Gimap ready for requests from 208.65.73.143 f185mb90387173ioe
a LOGIN [username] [password]
* CAPABILITY IMAP4rev1 UNSELECT IDLE NAMESPACE QUOTA ID XLIST CHILDREN X-GM-EXT-1 UIDPLUS COMPRESS=DEFLATE ENABLE MOVE CONDSTORE ESEARCH UTF8=ACCEPT
a OK [username] [name] authenticated (Success)
b SELECT INBOX
* FLAGS (\Answered \Flagged \Draft \Deleted \Seen $Phishing $Forwarded Yellow $NotPhishing)
* OK [PERMANENTFLAGS (\Answered \Flagged \Draft \Deleted \Seen $Phishing $Forwarded Yellow $NotPhishing \*)] Flags permitted.
* OK [UIDVALIDITY 7] UIDs valid.
* 3617 EXISTS
* 0 RECENT
* OK [UIDNEXT 39807] Predicted next UID.
* OK [HIGHESTMODSEQ 4076284]
b OK [READ-WRITE] INBOX selected. (Success)
c STORE 1:* +FLAGS (\Seen)
* 1 FETCH (FLAGS (\Seen))
* 2 FETCH (FLAGS (\Seen))
...
* 3617 FETCH (FLAGS (\Seen))
c OK Success
d LOGOUT
* BYE LOGOUT Requested
d OK 73 good day (Success)
If you have a lot of messages, you may want to use +FLAGS.SILENT with the STORE command, which won't cause it to echo the results back to you.