Loop until it finds a string - loops

I need to write a script that will configure some network devices.
It logs in to the device through ssh, then it lists all available ports and devices connected to them. In order to properly configure the device I need to click space (space = show next page) until I find a new device connected to one of the ports. The best way to find it would be to search for the "NEW" string on each page. Unfortunately I don't know how to write such a loop.

To make an expect script detect a prompt to “press Space for more”, you need to use something like this:
expect {
"Press space for more..." {
send " "
exp_continue; # <<< Magic! Keep this expect going!
}
"theRealDataEnd!" {
# this can be empty
}
}

Related

Dronekit Example Follow Me Python Script not working

I try to run an example script from dronekit. the code is looks like this :
import gps
import socket
import time
from droneapi.lib import VehicleMode, Location
def followme():
"""
followme - A DroneAPI example
This is a somewhat more 'meaty' example on how to use the DroneAPI. It uses the
python gps package to read positions from the GPS attached to your laptop an
every two seconds it sends a new goto command to the vehicle.
To use this example:
* Run mavproxy.py with the correct options to connect to your vehicle
* module load api
* api start <path-to-follow_me.py>
When you want to stop follow-me, either change vehicle modes from your RC
transmitter or type "api stop".
"""
try:
# First get an instance of the API endpoint (the connect via web case will be similar)
api = local_connect()
# Now get our vehicle (we assume the user is trying to control the first vehicle attached to the GCS)
v = api.get_vehicles()[0]
# Don't let the user try to fly while the board is still booting
if v.mode.name == "INITIALISING":
print "Vehicle still booting, try again later"
return
cmds = v.commands
is_guided = False # Have we sent at least one destination point?
# Use the python gps package to access the laptop GPS
gpsd = gps.gps(mode=gps.WATCH_ENABLE)
while not api.exit:
# This is necessary to read the GPS state from the laptop
gpsd.next()
if is_guided and v.mode.name != "GUIDED":
print "User has changed flight modes - aborting follow-me"
break
# Once we have a valid location (see gpsd documentation) we can start moving our vehicle around
if (gpsd.valid & gps.LATLON_SET) != 0:
altitude = 30 # in meters
dest = Location(gpsd.fix.latitude, gpsd.fix.longitude, altitude, is_relative=True)
print "Going to: %s" % dest
# A better implementation would only send new waypoints if the position had changed significantly
cmds.goto(dest)
is_guided = True
v.flush()
# Send a new target every two seconds
# For a complete implementation of follow me you'd want adjust this delay
time.sleep(2)
except socket.error:
print "Error: gpsd service does not seem to be running, plug in USB GPS or run run-fake-gps.sh"
followme()
I try to run it in my Raspberry with Raspbian OS, but i got an error message like this :
Error : gpsd service does not seem to be running, plug in USB GPS or run run-fake-gps.sh
I get a feeling that my raspberry is needed a gps kind of device to be attached before i can run this script, but i dont really know.
Please kindly tell me whats wrong with it..
the full path of instruction i got from here :
http://python.dronekit.io/1.5.0/examples/follow_me.html
As the example says:
[This example] will use a USB GPS attached to your laptop to have the vehicle follow you as you walk around a field.
Without a GPS device, the code doesn't know where you are so it would not be possible to implement any sort of "following" behavior. Before running the example, you would need to:
Acquire some sort of GPS device (I use one of these, but there are lots of alternatives).
Configure gpsd on your laptop to interface with the GPS device.

How to capture keyboard in linux kernel module?

I am trying to write a Linux kernel module to work similar to a 'MouseKeys' application - to grab certain keys and then output mouse events. I'm currently struggling trying to grab input in such a way that I can discard or passthrough keys based on some internal state of my module - what I want is something like:
int keyboard_callback(event) {
if (active) {
processKey(event); // this would output mouse events
return BLOCK_KEY_EVENT; // input is not visible to any applications
}
// input would be processed downstream as normal
return PASSTHROUGH_KEY_EVENT;
}
....
register_input_handler(keyboard_callback);

Sending AT Commands via LabWindows code to SPBT2632C2A

I am trying to make a LabWindows/CVI program that talks with SPBT2632C2A Bluetooth chip. I am using a st eval spbt3atv3 dongle. I am trying to push a button and send a command to chip, but chip do not answer to me. I know my LabWindows program can receive messages from dongle, because every time I press reset button on dongle it shows me the boot up message. As I searched I need to add \n\r to end of my string, but it still didn't work. Chip does not send even error message.
CODE
int CVICALLBACK rasti (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{
switch (event)
{
case EVENT_COMMIT:
sprintf(discovery,"AT+AB discovery\n\r");
if(ComWrt (4,discovery, 18)!= 18){
SetCtrlVal (panelHandle, PANEL_TEXTBOX, "Nesekmingas duomenu siuntimas");
//Unsuccessful sending data
}
else {
SetCtrlVal (panelHandle, PANEL_TEXTBOX, discovery);
}
break;
}
return 0;
}
It's event called by button. It appends my discovery string to text box. So I think it's sending data correctly to serial port. But I think my string is wrong so I don't get the answer from chip.
Any ideas how to solve this to get responses from chip?
Make sure to call OpenComConfig with the correct parameters before invoking ComWrt. You can look for the correct port settings in the Hyperterminal (since you mentioned it communicates correctly with the device).
Refer to NI's documentation for more on this.
Also, trying different types of line termination characters might help (try using \r\n, \n or \r).

Bro: Disable ALL log generation

I created a bro script, with the objective of extract all files for all posible protocols from a pcap file. But I dont want to write all logs. Bro create a log file for each protocol. Example: 'http.log', 'smtp.log', etc. Even a 'weird.log' is generated. My pcap files are large (20gb), so, each log file contains over 30mb of information. This log generation reduce the performance of the file extraction.
I can disable the 'conn.log' with the line Log::disable_stream(Conn::LOG) but, what about all protocol logging??
This is my script
#load base/files/extract
event bro_init()
{
Log::disable_stream(Conn::LOG);
}
event file_sniff(f: fa_file, meta: fa_metadata)
{
local ext = "";
if ( meta?$mime_type )
ext = split_string(meta$mime_type, /\//)[1];
local fname = fmt("%s-%s.%s", f$source, f$id, ext);
Files::add_analyzer(f, Files::ANALYZER_EXTRACT, [$extract_filename=fname]);
}
You can use the none writer like this:
bro -r packets.pcap Log::default_writer=Log::WRITER_NONE
I'm not totally convinced that writing these logs is harming your performance in any real way though. Typically, writing the files to disk is what causes the biggest overhead.
Here's a way to turn off whatever logging's been turned on (prior to bro_init), without having to know which stream IDs are relevant:
event bro_init()
{
# We don't want any output other than from this script.
for (id in Log::active_streams)
Log::disable_stream(id);
}
This construct makes me twitch a little about modifying a table while iterating over it, but it seems to work and I can't actually find any way to peek at one key from a table without doing an iteration. I suppose one could write
event bro_init()
{
while (|Log::active_streams|) {
for (id in Log::active_streams) {
Log::disable_stream(id);
break;
}
}
}
but that's hideous and I'm not going to use it unless I discover that I have to.
I achieved this with this line of code in main.bro:
Log::remove_filter(Conn::LOG, "default");

How to schedule SSIS import when the data source is daily excel sheet in email?

Hi I have a specific question regarding scheduling SSIS import:
I have a data source which will send me scheduled excel sheet to my email inbox on daily basis. The expectation is to find a solution which will take this daily excel sheet email into SSIS and schedule importing into SQL on its own.
Is it possible at all? If anyone could provide some useful links or where shall I start to look into, it will be much appreciated.
Thank you
Sense there was no answer to the mail client yet I am just going to throw this out there.
This will work on Gmail and is configured for such.
First thing first you have to make sure that you enable POP (this will allow the process to read your inbox). It is suggested that you select "enable pop from now on" as it will only allow the viewing of items from that point forward.
Once you have done that you need to get the Nuget package for OpenPOP.net
now the fun part. Please keep in mind this is not proper coding practice and you are responsible for the addition of necessary security precautions and error handling. This is purely a proof of concept.
using OpenPop.Pop3;
using OpenPop.Mime;
using OpenPop.Mime.Header;
// create the client to be used
Pop3Client client = new Pop3Client();
// connect to the client via host server port and use ssl bool
client.Connect("pop.gmail.com", 995, true);
// log into the specific account to read
client.Authenticate("username", "password");
// generate count of emails in the inbox
int msgcount = client.GetMessageCount();
//loop thru available message numbers via message count
//incremented at the end of the while loop
while (msgcount > 0)
{
// gets the message header info to, from and subject ect.
MessageHeader header = client.GetMessageHeaders(msgcount);
//read the subject line
string subject = header.Subject;
//compare subject to identify the correct email
if (subject.ToLower() == "subject to match")
{
// gets message info based on message number from msgcount
var message = client.GetMessage(msgcount);
// creates list of the attachments available in the message
List<MessagePart> attachments = message.FindAllAttachments();
//loops thru attachments
foreach (var file in attachments)
{
//assigns filename as string for stream
string filename = file.FileName;
//create a stream to download the file
var stream = new FileStream(#"destination path" + filename,FileMode.Create,FileAccess.ReadWrite);
// downloads file
file.Save(stream);
// closes stream to protect system and hung files
stream.Close();
}
// optional and must be configured to be allowed in your
// email client.
client.DeleteMessage(msgcount);
}
// increment message number
msgcount--;
}
// this is extremely important if deleting or manipulating files in inbox
//the above deletemessage command only marked the message to be deleted.
// you must commit the change to have it take effect.
// this command commits the changes you have made.
// this also closes your client connection so that no connections are left open.
client.Dispose();
This can be added to a script task in your import and you can then download the excel file and import it as you normally would if you would have manually pulled the file and placed it on a hard disk or network drive.

Resources