send spawn id exp4 not open error in expect - tcl

My ultimate goal is to do telnet to a router and interact with it. The following expect script does not help me at all. The router does not have any user id or pasword. it is automatic login.
Expect file code.
set iptotelnet "10.x.x.x"
spawn telnet $iptotelnet
sleep 10
expect ">" #this is because initially the prompt will be >
sleep 10
send "enable\r" # this should change the prompt from > to #
sleep 10
expect "#"
sleep 10
interact
sleep 10
exit
However, I get the following error.
send: spawn id exp4 not open
while executing
send "enable\r".
This is not just with telnet, i get the same error with any other command also.
please help me.

Your script has no major issues with it, not that would cause spawn to fail like that. (The comments you have would cause problems, but are trivially fixable by using ;# instead of #.) Therefore your problem lies elsewhere (well, with very high probability).
I see that you are trying to control telnet with Expect on Windows. Alas, telnet is a special case that can't be controlled this way — Expect on Windows uses the system debugging facilities to intercept terminal output, but this doesn't work for executables that have special system permissions set, and telnet is one of the programs for which this is true — so you need another approach. The simplest is to get plink.exe (which is really PuTTY for terminals/automation) and to use that (in “telnet” mode) instead of telnet.

Probably you can't use # comments in send command line.
Try same but without comment in send string.

It happens to me too. And it has been resolved.
I try to automatically telnet a server in the Cygwin on Windows.
But the Microsoft telnet installed in Windows won't work in a Cygwin shell
If you got the response below, this is the source of your problems type:
$ which telnet
/cygdrive/c/WINDOWS/system32/telnet
There are two solutions:
1. For Cygwin x86, just simply install the package "inetutil" which includes telnet command.
2. For Cygwin x86_64, currently(2013-09-09) the "inetutil" hasn't been port to 64bit, so I use the plink.exe which is part of PuTTy instead

Related

libvirt qemu hook is not running

I am following what's suggested in this article to change the iptables rules in order to allow incoming connections. For some reason, the qemu hooks does not run. I simply tried to write into a file with echo 'some output' > someweirdfilename before making any vm name checks to run the actual script itself to later check the existence of the file. It looks like the hook is not executed at all. Made sure that libvirtd.service is restarted, so is guest and eventually tried the complete reboot. All resulted in the same. Running libvirt 7.6.0 on a fedora 35. Does anyone have any suggestions for troubleshooting?

minicom throwing an error minicom: cannot open /dev/modem: No such file or directory

I have tried to connect my Jetson Nano with TTL UART cable using minicom. When I typed
sudo minicom
It showed an error
minicom throwing an error minicom: cannot open /dev/modem: No such file or directory
Later I tried with
sudo minicom -s
It worked
sudo is always a way...
What minicom tells you with this message that it has tried to open a interface called /dev/modem. It is telling you, that it can't be opened due to insufficient permissions.
On my system /dev/modem does not even exist! Anyhow, minicom expects in it's settings the /dev/modem as default. That's why it's trying to connect to that.
So, the solution is minicom -s, where you actually enter the settings of minicom. Her you'll find the the settings to properly configure your board. If you run this with sudo, you are able to also save your settings, if you want to. You might want to change those settings to e.g. /dev/ttyUSB0 or something.

How do I get xdebug/step-debugging working with ddev?

I've been working with ddev on my Drupal projects, and now want to use xdebug so I have step-debugging with PhpStorm (or really any IDE would be fine). But I can't seem to get it to stop on breakpoints. I tried to follow the instructions in ddev docs but that doesn't do get me going, and I don't know what to do next. I did:
Set the 172.28.99.99 IP address as discussed there
Enabled xdebug using config.yaml xdebug_enabled: true and ddev start (and checked with phpinfo to see that xdebug was enabled.)
Put PHPStorm in "listen for debug connections" mode
Debugging xdebug in any setup can be a little trouble, but here are the steps to take:
First, reread the docs. You may want to read the troubleshooting docs rather than this issue, since they're maintained more often.
Make sure xdebug has been enabled; it's disabled by default for performance reasons. Most people use ddev xdebug on to enable it when they want it, and ddev xdebug off when they're done with it, but it can also be enabled in .ddev/config.yaml.
Don't assume that some obscure piece of code is being executed and put a breakpoint there. Start by putting a breakpoint at the first executable line in your index.php. Oh-so-many times people think it should be stopping, but their code is not being executed.
ddev ssh into the web container. Can you ping host.docker.internal (and get responses)? If you can't, you might have an over-aggressive firewall.
In PHPStorm, disable the "listen for connections" button so it won't listen. Or just exit PHPStorm.
ddev ssh: Can telnet host.docker.internal 9003 connect? If it does, you have something else running on port 9003, probably php-fpm. Use lsof -i :9003 -sTCP:LISTEN to find out what is there and stop it, or change the xdebug port and configure PHPStorm to use the new one . Don't continue until your telnet command does not connect.
Now click the listen button on PHPStorm to start it listening for connections.
ddev ssh and try the telnet host.docker.internal 9003 again. It should connect. If not, maybe PHPStorm is not listening, or not configured to listen on port 9003?
Check to make sure that Xdebug is enabled. You can use php -i | grep grep Xdebug inside the container, or use any other technique you want that gives the output of phpinfo(), including Drupal's admin/reports/status/php. You should see with Xdebug v2.9.6, Copyright (c) 2002-2020 and php -i | grep "xdebug.remote_enable" should give you xdebug.remote_enable: On.
Set a breakpoint in the first relevant line of the index.php of your project and then visit the site with a browser. It should stop there.
A note from #heddn: If you want to have xdebug running only for fpm, phpenmod -s fpm xdebug for example, instead of running enable_xdebug.
A note from #mfrieling: If you use a browser extension like XDebug Helper which sets an IDE key, that must be the same as on the server. Since DDEV 1.10.0 "there's a real user created for you inside the web and db containers, with your username and userid" which is also used as IDE key by default. The used IDE key must be the same on the server, the browser extension/cookie sent and PHPStorm. You can change the IDE key in DDEV by creating a file .ddev/php/xdebug.ini with the following two lines (replace PHPSTORM with the value you want use:
[XDebug]
xdebug.idekey = PHPSTORM
Your followups are welcome here!
Thanks, had the same problem and adding the file .ddev/docker-compose.xdebug.yaml fixed the issue.
However, I am running on a Mac / OSX and found these additional steps worked to discover the IP address of the internal host from inside the container:
1.) Log into the web continaner ddev ssh
2.) Run ping docker.for.mac.localhost
3.) Set the returned IP address for host.docker.internal in the above yaml file.
4.) Remove and start the DDEV.
Also worth mentioning validating xdebug in PHPStorm is useful to check the config.
Careful with Macs, as they may have php-fpm running. If it's the case PHP Storm won't find the connection (as it's already taken by php-fpm).
To see if it's the case run:
lsof -i :9000 -sTCP:LISTEN
if it returns something like php-fpm, then you have this issue
Try closing it (see PHP-FPM can't be closed ).
Running it once you have fixed it (potentially restarted your mac) you should see something like this:
➜ solrpoc lsof -i :9000 -sTCP:LISTEN
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
phpstorm 512 alejandro.moreno 490u IPv6 0xaf3eef0f3233a83 0t0 TCP *:cslistener (LISTEN)

InstallShield 2014, Custom Actions and executing sql files into MySQL

I am building an installer for our product which works well. I've managed to build custom actions to install our services including a MySQL server.
The problem I have is executing a sql file to build the schema structures.
I have a custom action which uses mysql.exe and the command line arguments:
--port=### --user=### --password=### < "[INSTALLDIR]db\EmptyStruct.sql"
It tries to execute this ok but the cmd window which pops up, during the install, just runs through the mysql.exe command line options, which says to me that the command line it gets passed is not correct. However if I run the command manually after the install, it works perfectly.
Does anyone has any ideas please.
I'm making a few assumptions here:
You have a Windows Installer exe custom action that specifies mysql.exe and a command line as you showed
You are expecting the contents of [INSTALLDIR]db\EmptyStruct.sql to be redirected to mysql.exe's standard input
This will not happen. Behind the scenes, Windows Installer's exe custom action support uses the CreateProcess API and this API will interpret command lines literally. However the redirect < needs special handling to actually perform redirection.
To get that behavior, you must use a layer of indirection. For example, you could run cmd.exe as the exe, and give it a command line that will make it interpret and run the command line mysql.exe --port= ... < "[INSTALLDIR]...". However, if you didn't already have a command prompt showing, this would cause one to show up. If you want to avoid that, you could write a custom wrapper that performs the redirection for you, either as a C++ DLL or, say, InstallScript action.
Alternately, if there is a parameter that tells mysql.exe to run a script from a file, you could pass that instead of using redirection. I wasn't able to find evidence of such a parameter in a quick web search.
Thanks for your comments Michael and I used cmd.exe /k AddStruct.bat to accomplish the task!

Unix SSH without password

Hey all I'm completely new to Unix and I need to write up a "shell script" (?) to connect to another terminal and run a few SQL queries. How on earth do I do this? I've been browsing a few answers from this and other boards and if I have found my answer I don't understand it.
I am able to manually connect, enter password, etc, but I need to automate the process. I don't have access to Perl (as a few answers have suggested) and I am unable to edit the etc/shadow file. So I assume this has to be done strictly through Unix itself. This is what I am currently using:
X=`vUser='USER-NAME'
vPass='PASSWORD'
vTable='TABLENAME'
vHOST='HOST-NAME'
vPORT=4443
ssh root#vHost
expect {
"root#the-host password:"{
send -s "'vPass'\r"
}
}
SQL_Query='select * from vTable limit 10'
mysql -p$vPASS -D$vTable -u$vUser P$vPort<<EOF
$SQL_Query
EOF`
echo $X>Output.dat
Please explain all answers in full. I'm trying to learn.
Might not be a 100% relevant but I had to do the same on Linux.
First off you want to make a new user account on the other server that has SSH access and generate an SSH keypair, even if you're going to do this as root, keypairs are far superior over standard passwords because they're stronger, and they allow you to log in automatically over SSH.
There's no real way of automating the password entry process (at least, not on Linux), hence the reason SSH keys are required to do this.
You can basically send a chain of commands as a parameter to the SSH tool.
Like so,
ssh user#host "ls; cat *; yes;"
Hope that helped.
Try this:
Copy your SSH public key to your clipboard (output of cat ~/.ssh/id_rsa.pub). If you don't have an SSH key pair then generate it with this tutorial.
Paste your public key to your server's ~/.ssh/authorized_keys file. If it doesn't have one, create it with nano ~/.ssh/authorized_keys and paste it there.
In your computer, you can run the script in the server with the following command:
ssh user#server_ip 'bash -s' < local_script.sh
Or if you have a single command to run then this will do:
ssh user#server_ip "echo Test | tee output.log"
If you don't like SSH asking you for the password all the time, use ssh-agent
For SQL-specific scripts, you can put all your SQL commands in a single file, say query.sql. You should copy query.sql to your server (scp query.sql user#server_ip:~/) and then run
ssh user#server_ip "mysql -uyourusername -pyourpassword < query.sql | tee output.log"
The output will be saved in output.log. Check this answer too.
There is a Linux command ssh-copy-id will do this for you, it is also available to Mac as a homebrew formula.