1

I'm connecting to a device via screen that requires that I enter some credentials (username and password). It's getting annoying to do that on every entry, so I'd like to alias a command to do that for me:

This alias in ~/.bash_aliases is insufficient:

alias devlogin="sudo screen /dev/ttyACM0 9600 && '\rmyusername' && \rmypassword"
1

Does it have to be screen? Another option is to instead use expect or similar to open the device, issue whatever commands are necessary, and then turn things over to the user. This has the advantage of keeping the password out of the command line (where it is often visible across the system):

#!/usr/bin/env expect

# open up serial and configure
set fh [open /dev/ttyACM0 {RDWR NOCTTY NONBLOCK}]
fconfigure $fh -mode 9600,n,8,1

# link above up with expect
spawn -noecho -open $fh
send -- "\rmyuser"
send -- "\rHunter2"

# over to the user now
interact
0

Using stuff with the right syntax seems to work:

alias evdlogin="sudo screen /dev/ttyACM0 9600 -X stuff $'\rmyusername\rmypassword'"

Note that it's generally bad practice to hard-code a password in plain text, but since this is a development environment...

http://aperiodic.net/screen/quick_reference

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.