0
votes
2answers
68 views

How do I run a command on a TTY from a SSH session?

Does anyone know of a way that I could run a command from my ssh session and have it display on tty1? It seems like I could do that like: script command >> /dev/tty1. However, if I were to do ...
1
vote
2answers
40 views

About escape with SSH pipe

I want to execute the awk command with long parameters,like this: ssh host "netstat -rn|awk 'NR!=1 && NF>=6 && $1!="Destination" {printf "%-15s %-20s\n", $1, $2}'|sort -f " but ...
1
vote
1answer
60 views

How to check for a folder inside a particular folder in shell script?

I am working on a shell script and python script as well. Python script is passing certain parameters to my shell script and then I am using those parameters in my shell script. Below is my shell ...
1
vote
1answer
49 views

How can I start tmux automatically in fish shell while connecting to remote server via ssh

I switched from bash to fish shell. I liked it and decided to use it on my servers also. How can I start tmux automatically on ssh connection? I followed this instruction for bash but fish shell is ...
2
votes
4answers
168 views

Running bash script on a remote Windows Machine

I am planning to run a bash script on a remote Windows system from my local Linux machine. For this purpose, I will have to log in to Windows machine from the local one and then execute the bash ...
0
votes
2answers
42 views

Running Commands on Remote Linux Server Using SSH

I am writing a Bash Script wherein I need to run some set of commands on a remote Linux server from my local computer using SSH. I want the results to be displayed on the terminal screen or dump the ...
3
votes
2answers
91 views

Execute bash commands over SSH while staying in interactive mode afterwards

Probably it is a weird thing I would like to achieve but: I would like to SSH to a remote host and then execute some bash commands like "alias" automatically to use them afterwards in an interactive ...
1
vote
2answers
77 views

How to find out all the files in other machines using bash shell script?

I am trying to find out which files are in machineB and which files are in machineC. And I need to run my shell script on machineA to figure out which files are in machineB and which files are in ...
1
vote
1answer
54 views

Single command to login to SSH and run program?

Is there a way to structure a single command to login via SSH to a remote server and run a program on the remote login shell? In the OpenSSH manual, it reads "If command is specified, it is executed ...
6
votes
3answers
256 views

Remote ls on multiple machines

I want to connect to multiple machines specified in a file and perform 'ls' there. That's what I've come up with: for machine in $(cat machines) do echo "Connecting to " $machine ssh $machine ...
3
votes
1answer
49 views

variable expansion within command substitution over SSH bash 4.X

I want to do this ssh ${w100user}@web100 'ls -l "$(grep "${1}" /etc/pure-ftpd/pureftpd.passwd|cut -d':' -f6)"' Which obviously performs an ssh session to server web100 as w100user and then greps ...
1
vote
1answer
58 views

service killed at ssh hangup [duplicate]

If I use ssh to run some command in background, that command gets killed as soon an ssh hangs up: ssh localhost -t "bash -c '(for i in 1 2 3 4 5; do sleep \$i;done)&'"; ps x|grep sleep This ...
3
votes
3answers
368 views

Run a parallel command while waiting for ssh

I need to ssh into a server and check for a service to see if it is up and running. What i do is to use ssh and run a command which calls that service and check the output of that command. I want to ...
1
vote
1answer
1k views

Bash script calls expect script with master SSH connection

I'm trying to write a bash script that calls an expect script to establish a master SSH connection to be used for the remaining SSH commands in the bash script. ~/.ssh/config: ControlMaster auto ...
4
votes
4answers
190 views

Continue for loop by keyboard

I have user account on a linux machine which I do not know its exact IP address. But I know a range which it is ran on one of them. I want to check which server is my desired server. There are some ...
0
votes
1answer
77 views

Process substitution over ssh with sudo in Bash shell

What is the proper way to do something like this: diff <( ssh -t myuser@hosta 'sudo httpd -M') <(httpd -M) When I want to compare the output of the 2 commands, the first on a remote host the ...
1
vote
1answer
177 views

How to export a function in bash over ssh?

I would like to write a function in bash, then export that function and execute it over ssh. Is that possible, and if yes, how? I tried #!/bin/bash function myfunc() { echo $1 } export ...
1
vote
1answer
190 views

ssh into a server using .ssh/config alias & run an alias on the server in the same time

On my laptop Inside ~/.ssh/config file I have this: Host <serverAlias> HostName 127.0.0.1 #Server IP User <username> PreferredAuthentications publickey IdentityFile ...
1
vote
1answer
26 views

ssh: define group of servers [duplicate]

I am using a script to connect to multiple servers. At the moment, I am using something like: for SERVER in server1 server2 server3 ; do ssh $SERVER "my-command" ; done I have to specify the (many) ...
4
votes
1answer
152 views

Why doesn't the process substitution <() work with ssh -F

I have some vagrant virtual machines. To log into them I issue the vagrant ssh command. I want to log into them using regular ssh command. The vagrant ssh-config outputs the suitable config file $ ...
3
votes
3answers
322 views

Correctly parse arguments in script behaving like a shell called through SSH

I have a server with a very limited used whom I want to be able to run two very specific (and custom) instructions through SSH. In order to do that, I have set the shell for that limited user to be a ...
5
votes
3answers
564 views

Bash: interactive remote prompt

I have a script which connects to a remote server and check if some package is installed: ssh root@server 'bash -s' < myscript.sh myscript.sh: OUT=`rpm -qa | grep ntpdate` if [ "$OUT" != "" ] ; ...
1
vote
1answer
287 views

ssh with sudo doesn't start services

I want to run command with sudo through ssh without disabling "requiretty" sudo option. According to /etc/sudoers: # # Disable "ssh hostname sudo <cmd>", because it will show the password in ...
3
votes
1answer
201 views

hanging ssh processes launched from a script

i am creating a few vms through a script. as a part of it, i am changing the names of the vms using ssh. for some reason when i run the below command for three vms it works and for the magic number ...
0
votes
2answers
132 views

debian prompt is broken

When I login via ssh or from the console this is what I see: Linux sensu.lbox.com 3.2.0-4-amd64 #1 SMP Debian 3.2.46-1+deb7u1 x86_64 The programs included with the Debian GNU/Linux system are free ...
3
votes
3answers
534 views

How to run script using SSH from remote computer and avoid its interruption if remote computer goes offline [duplicate]

I have a remote Linux server and I use it to run some very long tasks using SSH. It works great, but, of course, if the connection dies for some reason, the task dies. Specifically, I'm running ...
2
votes
4answers
697 views

SSH exits after quit case in bash script

So I have the following standard script: #!/bin/bash PS3='Please enter your choice: ' options=("option 1" "Option 2" "Option 3" "Quit") select opt in "${options[@]}" do ...
1
vote
1answer
91 views

Detecting SSH timeout

Is there any way I could trigger a bash script when ssh times out? I have an alias to set the tmux title when starting ssh. The alias also includes a title change after the ssh session, which works ...
2
votes
5answers
127 views

SSH Twice in bash alias/function [duplicate]

At work, we run a portal server to access all of our "real" servers. Essentially, anyone who needs to SSH into one of the "real" (web) servers would first SSH into the portal, so it looks like this: ...
1
vote
2answers
360 views

How to see all commands executed by the current user, in all sessions/screen/byobu terminals?

If there is debian box, some users have access to the root account, some of those users open an ssh connection and start executing commands, some open screen or byobu or other similar tools to execute ...
4
votes
5answers
2k views

How to securely allow scp, but not ssh

I work from a Mac Book Pro (called foo). I have a server where my customers scp large files to. (called bar). I frequently ssh into bar, and scp a file (called buzz) to my Mac. bob@foo$ ssh bar ...
5
votes
2answers
217 views

Use keyboard-interactive authentication when piping ssh output to other command

I'd like to pipe the output of ssh to a different command. For example: ssh myserver cat remote-file | diff local-file - The problem is that myserver asks for a password, but I can't enter it. (For ...
9
votes
3answers
746 views

How to SSH into a specific directory?

I frequently login to a server, then cd into a specific directory. Is it possible to simplify these two commands into one? ssh bob@foo cd /home/guest I'd like to avoid changing anything on 'foo' ...
0
votes
0answers
713 views

ssh-agent not getting set up (SSH_AUTH_SOCK, SSH_AGENT_PID env vars not set)

I set up a new user account for a friend on Kubuntu 12.04. When he uses ssh he gets this error: Could not open a connection to your authentication agent We're running ssh in some bash scripts. ...
2
votes
1answer
420 views

sudo hangs when run on remote host over ssh in a script without tty (-t)

I have an AIX 6.1 server where I need to run a remote sudo command in a bash script. Here is my bash script simplified: testSudo.sh #!/usr/bin/bash set -x sudo env I can run the sudo command ...
3
votes
2answers
435 views

SSH tunnel through middleman server - how to connect in one step (using key pair)?

My question is basically how to turn my existing two steps into one step. I have a working SSH tunnel set up between two computers using a middleman server like this: ...
2
votes
3answers
605 views

Why do 'ssh host echo $PATH' and printing the $PATH after ssh'ing into the machine give different results?

On a particular host, when I ssh into the machine and enter echo $PATH I get /home/wxy/bin64:/home/wxy/bin:/usr/kerberos/bin:/usr/local/sbin:/usr/sbin:/sbin:/usr/local/bin:/bin:/usr/bin and if I ...
10
votes
4answers
1k views

How do I trigger autocomplete without a tab key?

I'm ssh-ing to my machine using my iPhone with an app called ServerAuditior. It doesn't have tab key. See screenshot. How do I trigger autocomplete without the tab key? I don't want to type a lot of ...
9
votes
2answers
449 views

Can I unfreeze bash or vim when SSH session freezes from timeout? [duplicate]

When my SSH session times out, the whole terminal freezes. Is there any way to break out of that connection? CTRL+C doesn't cut it.
2
votes
2answers
483 views

How to automate connecting to multiple network devices, running a command and saving the output to a file?

I have to run a command on around 1000 network devices and save the output to a file. In a file I have a list of all the network device names that have to be connected to using SSH. I then have to run ...
1
vote
2answers
3k views

Colorful ssh banner

I would like to colorize my ssh banner. I know I can perform it like so: In /etc/profile I can put: echo -e "\e[1;31m Colorful text" echo -e "\e[0m Reset" But I have some ASCII art in the banner ...
3
votes
2answers
72 views

Specify script to run with SSH upon login

I would like to know if there is a way to specify what script to run (on the remote machine) at login. I'm logging into a Debian box with key-pair authentiation (no password needed). The script ...
1
vote
0answers
1k views

Using sshpass, return code (exit status) differs for reasons unknown using valid commands

There are a few things going on here but I think ultimately, either CLish or SSH is returning an exit code that is messing up my work flow. I'm attempting to connect to a remote machine (CLish shell) ...
1
vote
1answer
1k views

How to put value of echo pipe netcat commands into variable [duplicate]

I have this command succession: echo -ne "/dev/shm/test.sh" | netcat 89.196.167.2 4567 and let's say it return a string like, for example "Hello...bla". (on the 89.196.167.2 i have made a server ...
4
votes
2answers
4k views

bash shell - ssh remote script capture output and exit code?

I wish to use shell to invoke a script on a remote server. I would like to capture the output of that script (its logging messages) and the exit code it returns. If I do this: ssh user@server ...
4
votes
2answers
194 views

Is it possible to store ssh connection in bash script instead of $(ssh user@ip command) every time?

I think that the code that I already have is not very efficient as it has to connect each time to the same machine and execute a command. Code: tmp=$(ssh -nq $USER@$IP "$COMMAND" 2>> $LOG) ...
3
votes
2answers
125 views

Any ideas to simplify the awkward rsync expression below?

Here is expression: rsync -avz --progress -e "ssh -i /where/is/my/id_dsa" vivek@some.host:`ssh -i /where/is/my/id_dsa vivek@some.host "find /remote/source/dir -type f -name '*.sql' | sort -nr | head ...
5
votes
3answers
435 views

Run ssh login command without modifying remote .bashrc

We have a bunch of servers set up with set -o vi in their ~/.bashrc. It would be nice to be able to ssh into these boxes and automagically run set -o emacs as a timesave. I've seen a solution ...
0
votes
1answer
104 views

Can Bash Emacs shortcuts be enabled over SSH?

I find Bash keyboard shortcuts such as Ctrl-a (jump to start of line), Ctrl-k (cut text following caret), Ctrl-n/Ctrl-p (next/previous line in command history) immeasurably useful in day-to-day CLI ...
3
votes
3answers
3k views

Bash Auto-Completion feature for SSHing into Different Hosts

I have big list of servers which I normally ssh to all the time. Is there any way using bash or zsh so that I can keep the list of hostname and bash auto-completion goes through the file and gives me ...