#Linux SSH setting up environment on login

1 messages · Page 1 of 1 (latest)

spark spindle
#

Hi,

This is probably kinda off-topic but I'm still trying..

Some of my team members uses MobaXterm on Windows to connect to the cluster. MobaXTerm has a great feature to send commands (macro) after being connected to the cluster for example to set rows 0.
However I couldn't reproduce that with openssh on Linux as RemoteCommand executes rows 0 perfectly but kills the session after (I guess on linux distributions they append bash to spawn the shell after remote commands are executed).

Has anybody ever found a way for that to work ?

Regards,

ornate verge
#

RemoteCommand just executes that command and then quits. it is by design. I have no idea if openssh can send macros tbh

#

it's like doing ssh user@host cat /etc/fstab -> it only executes one command

spark spindle
ornate verge
#

I mean, you could always run MobaXTerm under Wine on Linux 🤪

spark spindle
ornate verge
#

it comes with games? maaaaybe I should take a look at it after all 🤪

junior void
#

Re: scripting/macro support for a ssh client

I'm not completely sure what you are trying to accomplish but a fairly standard scripting mechanism for things like this is "expect". To install it:

Code:

sudo apt-get install expect

Then, check the man page to see if it might suit your needs:

Code:

man expect

You can find lots of useful examples via google on how to use it for various things.
#

Kinda hacky but it might work. Or you could even write a bash script maybe to send a SSH command before giving you the prompt somehow.

spark spindle
ornate verge
#

yeah, expect obviously works. It has worked since, dunno, 1990 at least? Is it still written in Tcl/Tk? 😄

spark spindle
#

hopefully it was on a test svm

spark spindle
#
#!/usr/bin/expect

# Define the variables
set timeout -1
set host [lindex $argv 0];
set user "<user>"

# Catch password
stty -echo
send_user -- "Password for $user@$host: "
expect_user -re "(.*)\n"
send_user "\n"
stty echo
set password $expect_out(1,string)

set timestamp [timestamp -format %Y-%m-%d_%H:%M]
set logfile $env(HOME)/logs/session_$timestamp.log
log_file -a $logfile

# Start the SSH session
spawn ssh $user@$host
expect "Access restricted to authorized users"

# Handle the password prompt
stty -echo
expect {
    "assword:" {
        send "$password\r"
    }
}

# Send the commands you want to execute
expect ">"
send "rows 0\r"
send "set diag -confirmations off\r"

# Keep the shell open
interact

this works perfectly

languid topaz
#

sweet. you could modify that to allow ONTAP to "script". Through in an extra prompt and then add

send "system script start -file $script"

(script terminates when you logout, of course you may want to timestamp it or something in case of same name, like $script-$timestamp.log)

ornate verge
#

-confirmations off 😄

spark spindle
#

one to expect {y:n} and one to send y\r

spark spindle
ornate verge
spark spindle
#

oh isn't it only for the set diag ?

ornate verge
#

no it's for the whole session

spark spindle
#

ouch ok

#

didn't know

#

will switch back to the two lines

ornate verge
#

you can add set -conf on at the end I guess

spark spindle
#

oh

#

well better use the other method to be sure

#

in case one command didn't pass somehow

languid topaz
#

You can then upload the resulting script files to a ftp or http server

spark spindle
languid topaz
#

yep. you sure do. it saves it on the host your are ssh-ing from. On the NetApp, other can view, review and save someplace else for later. The both get the job done. It is just a matter of where you want it and I suspect a lot of people did not know you could use the script command on the ONTAP CLI.

spark spindle
#

alright I didn't know about that, i'll take a look as I'm curious

#

thanks !

shut cypress
#

if using putty, can setup automatic logs by using &H_&Y_&M_&D.log as Log file name, click on Session in left pane, and save the Default Config.

I use MTPutty, so easy to track down what I did, when.

spark spindle
#

idk if i'd use putty or mobaxterm if I was on windows, maybe mobaxterm cuz I find it easier to launch sessions etc.. Putty you always have to restart it

#

MTPutty idk about it

#

"multi-tabbed putty", ooh

languid topaz
#

I use a Mac, I have a Windows VM specifically so I can use MobaXterm (among other things). I absolutely save every single session and love the ability to configure many things at the same time! (i.e initial switch config, do in parallel, Nexus switches with vPCs->again in parallel, or re-init-ing 8 NetApp controllers at the sme time....in parallel!)

spark spindle
#

lets say I need to configure the same thing on many devices at once, I've developed smth for it
well you could use ansible but I find ansible horrible to config. As you always have to search on google cuz things are tricky

#
# file vol_show.py
def run(ctx):
    output = ctx.conn.send_command("volume show").split("\n")

    for line in output:
        print(line)

that's an example script and then i'd have to do : python netscript.py run scripts/vol_show.py -g netapp_clusters
where netapp_clusters is a group defined in an inventory.yml file

#

best example is when u have a site with many switches and you have to configure smth in all of them at once. but works fine with ontap !

shut cypress
#

never tried mobaxterm, does it have tabs? 😁

languid topaz
#

oh yes it does

#

been a paid user for a few years now. also has a builtin http and ssh/scp/tftp/vnc and more servers! and it works with X

hardy matrix
#

MobaXTerm is pretty good, but I preferred RoyalTS back when I was allowed to use it (8 or more years ago). So, I don't know how they compare now.

spark spindle
#

never heard of it

lone linden
#

I use mRemoteNG for the most part. RoyalTS we stopped using a couple of years ago but was nice as well.
couple of people I work with have Moba and like it