Jump to content
7 minutes ago, Joveice said:

Hello, is there any way for me to populate bash-completion with a list of server names, so when I want to ssh I can just write parts of it and tab the rest? The list I got is quite large.

Not to my knowledge, if it was me I'd write a script with the list in it so when you run it will ask which server to connect to but I don't consider myself a Linux expert so I'd recommend you wait for someone more experienced than me to chime in.

Main Rig:-

Ryzen 7 3800X | Asus ROG Strix X570-F Gaming | 16GB Team Group Dark Pro 3600Mhz | Corsair MP600 1TB PCIe Gen 4 | Sapphire 5700 XT Pulse | Corsair H115i Platinum | WD Black 1TB | WD Green 4TB | EVGA SuperNOVA G3 650W | Asus TUF GT501 | Samsung C27HG70 1440p 144hz HDR FreeSync 2 | Ubuntu 20.04.2 LTS |

 

Server:-

Intel NUC running Server 2019 + Synology DSM218+ with 2 x 4TB Toshiba NAS Ready HDDs (RAID0)

Link to post
Share on other sites

1 minute ago, Master Disaster said:

Not to my knowledge, if it was me I'd write a script with the list in it so when you run it will ask which server to connect to but I don't consider myself a Linux expert so I'd recommend you wait for someone more experienced than me to chime in.

I mean, I could ask everyone around me (at work) but they all are doing stuff, I'm just doing small tasks and tweaks with a bit of free time to learn on my own. I guess I could also just script it to open a ssh connection to all the servers, then it would populate that packages. (Probably not all at once heh :P)

Back-end developer, electronics "hacker"

Link to post
Share on other sites

7 hours ago, Joveice said:

Hello, is there any way for me to populate bash-completion with a list of server names, so when I want to ssh I can just write parts of it and tab the rest? The list I got is quite large.

You could make a load of bash scripts that execute the ssh command to the specific server, and put them in /usr/local/bin/ if all users should have access to the commands or in $HOME/bin/ if you only want you to have access to them.

 

If you want to use $HOME/bin then it may require creation and adding to the path:

 

# mkdir ${HOME}/bin
# echo 'export PATH="${PATH}:${HOME}/bin"' >> ${HOME}/.bashrc
# now relog so $PATH is updated
# now create a script in ${HOME}/bin and make it executable
  

 

That way you don't need to type the path to the script, you can just run it as

ssh_test.sh

and it will work with auto-completion from any location in the FS as the scripts are in your $PATH.

AMD Ryzen 7800 X3D, MSI B650 Project Zero, Antec C5, Gigabyte RTX 4080 Super Aero

 

Nikon D500 | Nikon 300mm f/4 PF  | Nikon 200-500 f/5.6 | Nikon 50mm f/1.8 | Tamron 70-210 f/4 VCII | Sigma 10-20 f/3.5 | Nikon 17-55 f/2.8 | Tamron 90mm F2.8 SP Di VC USD Macro | Neewer 750II

Link to post
Share on other sites

2 hours ago, Fetzie said:

You could make a load of bash scripts that execute the ssh command to the specific server, and put them in /usr/local/bin/ if all users should have access to the commands or in $HOME/bin/ if you only want you to have access to them.

 

If you want to use $HOME/bin then it may require creation and adding to the path:

 


# mkdir ${HOME}/bin
# echo 'export PATH="${PATH}:${HOME}/bin"' >> ${HOME}/.bashrc
# now relog so $PATH is updated
# now create a script in ${HOME}/bin and make it executable
  

 

That way you don't need to type the path to the script, you can just run it as


ssh_test.sh

and it will work with auto-completion from any location in the FS as the scripts are in your $PATH.

Yea, but I'm already using the package bash-completion, I just wanted to know if I could populate it with data

Back-end developer, electronics "hacker"

Link to post
Share on other sites

3 hours ago, Fetzie said:

You could make a load of bash scripts that execute the ssh command to the specific server, and put them in /usr/local/bin/ if all users should have access to the commands or in $HOME/bin/ if you only want you to have access to them.

 

If you want to use $HOME/bin then it may require creation and adding to the path:

 


# mkdir ${HOME}/bin
# echo 'export PATH="${PATH}:${HOME}/bin"' >> ${HOME}/.bashrc
# now relog so $PATH is updated
# now create a script in ${HOME}/bin and make it executable
  

 

That way you don't need to type the path to the script, you can just run it as


ssh_test.sh

and it will work with auto-completion from any location in the FS as the scripts are in your $PATH.

This is a good idea, but it's much better to use an alias in /home/yourname/.bashrc:

alias myserver="ssh username@address"

This accomplishes a few things:

1) the alias will autocomplete in the shell

2) you aren't touching system directories

3) it's faster than creating a bunch of .sh files and making them executable

Don't ask to ask, just ask... please 🤨

sudo chmod -R 000 /*

Link to post
Share on other sites

i believe there is a way to define your own bash completion scripts. look up bash_completion.d. There is also a way to specify server connection settings in an ssh config file so you just need to type "ssh something" and it will pull all the settings out of the config and auto connect.

Link to post
Share on other sites

1 hour ago, Sauron said:

This is a good idea, but it's much better to use an alias in /home/yourname/.bashrc:


alias myserver="ssh username@address"

This accomplishes a few things:

1) the alias will autocomplete in the shell

2) you aren't touching system directories

3) it's faster than creating a bunch of .sh files and making them executable

Case 1: fair enough :)

Although for case 2, the directory /usr/local/bin/ exists for precisely this purpose and for case 3 I'd script the script creation (no way in hell I'm typing out dozens of almost identical things) :)

25 minutes ago, Fleetscut said:

i believe there is a way to define your own bash completion scripts. look up bash_completion.d. There is also a way to specify server connection settings in an ssh config file so you just need to type "ssh something" and it will pull all the settings out of the config and auto connect.

You can define aliases in $HOME/.bash_aliases (use a loop to save some time by reading the server names from a file :)).

 

#!/bin/bash

while read foo; do
	bar ${foo};
done < servers.txt

 

AMD Ryzen 7800 X3D, MSI B650 Project Zero, Antec C5, Gigabyte RTX 4080 Super Aero

 

Nikon D500 | Nikon 300mm f/4 PF  | Nikon 200-500 f/5.6 | Nikon 50mm f/1.8 | Tamron 70-210 f/4 VCII | Sigma 10-20 f/3.5 | Nikon 17-55 f/2.8 | Tamron 90mm F2.8 SP Di VC USD Macro | Neewer 750II

Link to post
Share on other sites

1 hour ago, Fetzie said:

Although for case 2, the directory /usr/local/bin/ exists for precisely this purpose and for case 3 I'd script the script creation (no way in hell I'm typing out dozens of almost identical things) :)

That's true, personally I find aliases to be less "messy" but I suppose shell scripts work too. There is another small advantage to aliases though - it's (slightly) easier to migrate a single .bashrc file than a bunch of .sh files from /usr/local/bin.

Don't ask to ask, just ask... please 🤨

sudo chmod -R 000 /*

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×