My university has quite a lot files (like past papers etc) which I need to be on the uni network to access them. I ssh, using port forwarding, into the network and set my browser (Firefox) to go through that port. I know it would be quite easy to write something in most languages that would enter the command into a terminal, but which language/method could I use to make this happen? I expect some sort of scripting language could but I really know nothing about them, but I'd be willing to learn one just to have a little fun with this.
I'm using a cygwin terminal on Windows 7, if that will make a difference.
To neaten up my question: Which language would be best to acheive the above effect? Not necessarily the best, just possible and relatively simple to learn. I used the word best so I suppose I'll put a subjective tag.
EDIT:
Just in case anyway wants to do this precise thing, I'll show my solution. I ended up using a batch file because a few things made the bash more difficult. Anyway, in order to SSH into the network and open a new firefox window with the proxy changed, I just have to open this batch file and enter my password.
cd C:/cygwin/bin
ssh -fND 9001 username#your.website.here
cd "C:/Program Files/Mozilla Firefox"
firefox -no-remote -P SSH_profile
Save as .bat
In order for this to work you need to set up a profile with name SSH_profile (or whatever) and set the connection settings to go through port 9001. The script will open use the ssh command in /cygwin/bin and enter in the information. You enter your password and then it goes to your firefox directory, uses those arguments which opens a separate profile with the connection settings changed (means you can view unaccessible files in one window and anything else you don't want to be on your uni network in another. Just close the windows when you are done.
Quite a specific case but I thought I'd share my answer in the hope of helping someone, some day.
Since you are using cygwin, write a bash shell script.. If you don't want to rely on bash, powershell would be what you want, although you could probably get it working using a batch file.
This is exactly the kind of thing shell scripting is for.
Edit
You can change the firefox settings on the command line by passing the -override flag. This will let you have special settings for the invoked process.
Related
I split my terminal so I have two prompts open (specifically kitty) I resize one of them so one is large where I use my file browser (ranger) and run commands in the smaller one.
My goal is to have the working directory in sync between these two splits, that is, if I change directory in one of them, the other also changes directory.
I asked on IRC and they said that the two shells are completely independent processes and that I would have to write a complicated program to get this to work.
Could someone outline what I would need to learn to make a program like this?
You would probably need something to interact with an inter-process call, that sent a message from your active prompt to the passive so passive knows to change its working directory.
Further more, you need to go deep into shell source code and find out how to make a change in working directory.
I've been looking for at way to copy from vim to my system clipboard. I've read through the question "How to copy to clipboard in vim" and from that I can see that i'll have to compile Vim with +clipboard.
This is not an option for me, when working on a remote server, so for now, I'll have to switch to the mouse, to make the selection to make my system regard the selection a selection. Simply doing a visual select through Vim does not work.
So my question is this;
Is it possible to make my system see the selection made by Vim (e.g. using viw) as something that can be copied to the clipboard using a cmd-c?
I'm using Mac OS High Sierra, running iTerm 2.
I have a car without wheels, can it drive anyway?
Well, the answer is no, unless you strap some sort of wheels or similar to it.
xclip may be a solution (:'<,'>w !xclip -i) but if you can install stuff, it would be easier to install a proper version of vim.
The idea of using xclip will only work if you're on a local machine.
If you're on a remote server and use xclip, it will copy the text to the remote clipboard, making it unavailable locally.
There are ways around this, and you can adapt them from this post, which can be summed up in either:
Use and ANSI escape sequence
OR
Setup communication with the server and an SSH tunnel (yes, not complicated but quite involved)
The first way is actually quite easy, because you just need to enable access to the clipboard from the terminal in the general preferences of iTerm, and then if you do
printf "\033]52;c;$(printf "%s" "YOUR_CLIPBOARD" | base64)\a"
then the text YOUR_CLIPBOARD will be copied in your local clipboard, even if you're on a remote server.
All you have to do is put that printf in a shell script that take what you want as input and map whatever shortcut you want to running the script with the selection as a parameter.
My question is very simple.
How does OSX understands that this special process needs to make output to special terminal? Can we change it?
For example, is it possible to run process via ssh connection (without GUI) and make some system call, and this process will start using OSx GUI
I don't really understand your question, but I suspect you maybe have a look at the "expect" tool, which allows you to start some connection and then let the user continue after you have established the connection. Try:
man expect
in a terminal window.
I have used an script in past that enabled me to connect me to multiple unix machines, much like using a tab. Its just that I forgot the name of the script. Anyone know about it?
I suspect you're referring to GNU screen, which is a terminal multiplexer that allows you to have multiple virtual terminal windows in a single normal terminal window (ala PuTTY). I'd suggest tmux as a better alternative, but they're essentially the same. There are other solutions that will allow you to do tabs in the terminal client, but that depends on your OS (I'm assuming you're on Windows), and you'd have to initiate each connection individually. screen/tmux is the way to go most of the time.
How can I have another Terminal open when I am at my server by ssh?
I do not want to type my password twice to get another terminal for my server.
Perhaps, Bash has buffers similarly as Vim.
Check out GNU screen. It's kind of arcane and awkward to use, but does what you're looking for, and it's probably also installed on your server.
You can also forward X11 and run multiple xterm instances, but that's a pain.
Your best bet, though, is your proverbial "type my password every time" solution: you should set up SSH keys so you don't need to type your password every time and then just use multiple connections in Terminal tabs.
You can use something like GNU Screen.
The Bash shell has a feature called Job Control that allows you to run and manage multiple processes. You can read about it here: http://commandlinemac.blogspot.com/2008/12/bash-job-control-fg-bg-jobs-and-ctrl-z.html
GNU Screen
BTW. If you don't like typing passwords, try PK auth.
How it's done with PuTTy.
It's possible to use screen to open other terminals without needing to authenticate again.
Screen can also detach so that you can leave terminal open after logging out and re-attach them later. I use this on my home server for keeping rtorrent open.