I have a text based menu running on a remote Linux host. I am using expect to ssh into this host and would like to figure out how to interact with the menus. Interaction involves arrowing up, down and using the enter and back arrow keys. For example,
Disconnect
Data Collection >
Utilities >
Save Changes
When you enter the system Disconnect is highlighted. So simply pressing enter twice you can disconnect from the system. Second enter confirms the disconnect.
The following code will ssh into my system and bring up the menu. If I remove the expect eof and try to send "\r" thinking that this would select the Disconnect menu option I get the following error: "write() failed to write anything - will sleep(1) and retry..."
#!/usr/bin/expect
set env(TERM) vt100
set password abc123
set ipaddr 162.116.11.100
set timeout -1
match_max -d 100000
spawn ssh root#$ipaddr
exp_internal 1
expect "*password:*"
send -- "$password\r"
expect "Last login: *\r"
expect eof
I have looked at the virterm and term_expect examples but cannot figure out how to tweak them to work for me. If someone can point me in the right direction I would greatly appreciate it. What I need to know is can I interact with a text based menu system and what is the correct method for doing this, examples if any exist would be great.
thanks,
-reagan
Try using the autoexpect tool to record an interactive session, and see what the codes look like.
To simplify your life, you might want to setup public key encryption so that you can ssh to the remote host without using a password. Then you can concentrate on testing your software instead of ssh. Google "ssh login without password" for more information. The instructions you will find are straight forward, so don't be afraid.
Have you tried \n\n\r?
Related
I have recently been messing around with powershell scripting to simplify my job and have had great success so far, albeit after some struggle. I have created a few scripts to open ADUC, Comp management, and a few other things in an elevated state but I have been having issues with the below script.
Base code:
$Workstation = Read-Host "Workstation\IP Address"
$Username = Read-Host "Username"
$AdminGroup = [ADSI]"WinNT://$Workstation/Administrators,group"
$User = [ADSI]"WinNT://USA/$Username,user"
$AdminGroup.Add($User.Path)
pause
If I right-click and run it as an admin it works, but as soon as I try to add anything to force it to run in an elevated state it seems like it processes, but then when I check the admin group it does not appear to have worked. I could be totally off base here with my code, so any help is appreciated, I am very new to this. I have been scouring google and other forums but haven't found anything that works. Other code I have attempted:
runas /netonly /user:USA\adm$env:USERNAME "$AdminGroup.Add($User.Path)"
The above code would be the preferred method as it would allow the user to elevate it using their admin account that auto populates so they only need to enter the password. When I do this it prompts for the password and has the correct username, the code processes and I get no errors but does not add the user to the admin group.
I have tried this as well, but no success here either.
$arg = "$AdminGroup.Add($User.Path)"
start-process powershell -Verb runas $arg
pause
I have attempted a few other things as well the past few days, but I feel like I am just running in circles at this point. The best I have gotten it is to create a shortcut to the script and set it to run as admin. However, I would like to be able to remove the portion of typing in the username into UAC and just have it request the password in the powershell window when prompted. I did attempt a search on here as well, but haven't had any success. Maybe it's the context I am using while searching for solutions? Any help/advice for a newbie is greatly appreciated!
I am using VS2019 to create SSIS projects. I have tried to update one of my current projects and I have created a new project to try and update the protection level. When trying to update the protection level from EncryptSensitiveWithUserKey to Encrypt sensitive data with password. When trying to do this it allows me to enter a password, but the OK button is disabled. I have tried all kinds of password combos to make sure they are long enough and complex enough. Any ideas how to get by this?
Thanks to vhoang for pushing me just a little further. I had tried to expand the dialog box like I have others in VS for SSIS, but that did not work. What I did do is type in the password in the password box. Then I tabbed to the next box, which is not visible and entered the password again (with faith that I was in the confirm password box). And yep the OK button became available.
I'm trying to build a small expect script to reboot my Cisco VCS devices. However once logging into the device it doesn't have any prompting characters so I'm unsure how to initialise a send request
Example Prompt:
So far I tried
expect "OK/r"
send "command"
expect "OK/r/r"
send "command"
experimented with timeout but unsure how it works.
I also tried the autoexpect tool and it showed a weird character [?1034h" at the prompt which I tried including.
Any help would be appreciated
I would think you should be able to expect the OK plus one or both of newline or carriage return. But you need backslashes for that, not forward ones. I would try "OK\r" or "OK\r\n".
Here's what you need to do: include expect_internal 1 somewhere near the top of your script, then run it again. Expect will give you a ton of information on what it is and it is not matching. That should show you what it's receiving, and you will be able to craft your expect statement accordingly.
If you're unsure, edit your question to include the debugging output and I will try to help.
I'm trying to write a GUI using Tcl/tk where the user will select different parameters and hit a 'Submit' button. When the button is pressed, the program will open an xterm window and telnet and perform configurations based on the choices made by the user. I know this should be pretty basic but I've looked everywhere and cannot find a working method. Please advise. Thanks.
I think xterm isn't needed: Expect is able to provide a program (telnet in your case) with a pseudoterminal -- one of the things xterm does for the program it's running. So just google for this combo.
I don't believe that expect can control an X app such as xterm. It can however control a text app like telnet.
You can write a shell script that launches xterm, passing the "-e" option to execute an expect script. That expect script can then launch telnet.
I don't know if this will help, but i enabled logging to a text file called test.txt on my C Drive.
Public Sub Main()
Dim rowsProcessed As Integer = 100
Dim emptyBytes(0) As Byte
Dts.Log("Testing, Test 1,2,3", rowsProcessed.ToString, emptyBytes)
Dts.TaskResult = ScriptResults.Success
End Sub
You have to go into the SSIS->Logging menu and tick checkboxes like a crazy checkbox-ticking-ninja to get this to work.
There are various checkboxes that have to be checked, and some of them only appear when you click on the script tasks, so it took me a while to figure this out:
First, enable your logging provider (that you have set up, right?) by ticking it on the Providers and Logs tab.
Then switch to the Details tab (which shows various events that you might want to log)
For the DTS.Log() method you need the ScriptTaskLogEntry event, but they only show up when you click on Script Tasks in the tree on the left.
So, click each of your Script Tasks in the tree on the left, enable it for logging, and then tick the Script Tasks event on the details tab.
Also make sure your logging provider is ticked for each script task
See also: http://msdn.microsoft.com/en-us/library/ms136131.aspx
This is an old question and #codeulike has answered it well but I would like to add a note about the logging behavior in debug mode, specially for someone new to SSIS or SSIS logging (like me) - Assuming you have all the configuration in place required for logging, if execute a selected task that you expect to log, it still will not log. Only if you execute (or debug) the entire package, then the logging will work.
If you are sure you have done configured everything correctly and still cant see your dbo.sysssislog in the database you selected, then check in the following
YourDatabase > tables > system tables
you can find your loggings there.
its my first time doing package loggings and configured everything correctly and could not see that dbo.sysssislog in the database it was supposed to do loggings and banging my head for half an hour when i realised it was in system tables of that particular database.
I realize that this question is rather old, but maybe it helps someone.
I ran into the same problem - while debugging in Visual Studio my textfile logging provider just did not write into the configured logfile.
My logfile was in the directory "project-directory/bin/development".
After changing the path to "project-directory-name"-root (eg. "/project-directory-name/test.txt" it worked.
I cannot explain this - it is just what I have observed.