2
votes
2answers
53 views

Why does the while cycle skips and only reads the first line?

$ ls testscript.sh testservers.txt $ cat testservers.txt serverA IMM 10.2.3.4 USERID PASSW0RD serverB IMM 10.2.3.5 USERID PASSW0RD $ $ $ cat testscript.sh #!/bin/bash # test them.. egrep ...
1
vote
1answer
19 views

'script' session logging makes me exit twice

I'm using a solution described here to log my shell sessions, by adding this to the end of /etc/bash.bashrc: test "$(ps -ocommand= -p $PPID | awk '{print $1}')" == 'script' || (script -f ...
2
votes
1answer
57 views

Memory buffer in a bash script

I have recently finished a script that will ask for a hostname and automatically take the argument of the function and ssh into one of my work servers. Here is a copy of my script: #!/bin/bash echo ...
5
votes
1answer
68 views

Linux: $SSH_CONNECTION is set even without SSHing to the server

I have a remote server and I am writing a script in the server and want it to fire only when I SSH. I thought of using the $SSH_CONNECTION and $SSH_TTY for this purpose. I found out that when I have ...
7
votes
3answers
480 views

Run a diff between local and remote file

I'm connected on a host via ssh and I'd like to compare (let's say with diff) a certain config file against its counterpart on another host, also accessible via ssh, without having to manually ...
1
vote
2answers
62 views

Using exec in find over ssh from shell script

So, I am attempting to execute the following from within a shell script; ssh -q $CUR_HOST "cd $LOGS_DIR; echo cd $LOGS_DIR; find . -name *.log -mmin +1440 -exec gzip {} \; exit" When this runs, it ...
1
vote
5answers
99 views

How to copy a file from a remote network to the local desktop

So I used SSH to remotely login to another computer on a network. I have many files that I would like to copy over to my local desktop. I am trying to follow this How-to : However, I think one ...
2
votes
1answer
71 views

SSH Command behaves differently in Expect Script

I'm using this command on Server1 ~# ssh root@Server2 /root/.ssh/id_rsa.pub >> /root/.ssh/authorized_keys to append the contents of Server2's id_rsa.pub to the authorized_keys of Server1. It ...
3
votes
1answer
266 views

“sudo: sorry, you must have a tty to run sudo” when using sudo in a remote script

I want to run a series of sudo-elevated commands on a remote machine from an embedded script. To simplify the question, I'm just trying to run sudo id and get it to tell me that it's root. I am ...
1
vote
1answer
70 views

Autocomplete server names for SSH and SCP

I have a few servers configured in ~/.ssh/config, such as alpha and beta. How might I configure Bash such that the commands ssh al<tab> and scp file.tgz al<tab> autocomplete the names of ...
1
vote
1answer
181 views

ssh script asks for password

a little ssh issue here. I set up some keys in ssh between 2 machines and I can login via ssh without password in terminal. I am trying to write a shell script that sends commands to the remote ...
3
votes
3answers
2k views

bash: /home/user/.ssh/authorized_keys: No such file or directory

Create a ssh key: $ ssh-keygen -t rsa –P "" Moving the key to authorized key: $ cat $HOME/.ssh/id_rsa.pub >> $HOME/.ssh/authorized_keys bash: /home/user/.ssh/authorized_keys: No such file ...
3
votes
2answers
403 views

Automating backups run from a bash script in Linux the right way

I have a bash script I wrote to backup a Moodle installation. It works fine, I've tested the backups, but there's a problem with it; when I do the backups, since I have to use sudo to type the ...
1
vote
2answers
83 views

How to fix 'set -o emacs' in .bashrc not working in ssh shell

I work in an LDAP-based user and host network. My user exists on all hosts since it an LDAP user, and my user's home directory exists on all hosts as a mountpoint. I have ~/.bash_profile set up to ...
3
votes
2answers
131 views

Allow a user to run a single command as root over ssh

I have a user account that is not designed for logging in interactively, but want to allow it to run a single command (as root). Is there a better way to accomplish this (without granting more rights ...
3
votes
1answer
295 views

Unable to get the right exit code from a script

I have a script which connects to a remote server via SFTP and get some file from there. My script goes like this: /usr/bin/sftp USER@remote.server.com <<EOF lcd /dir1/dir2/dir3 cd ...
1
vote
2answers
165 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 ...
2
votes
2answers
155 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
78 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
356 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
3k 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
2k 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
472 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
109 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 ...
2
votes
1answer
857 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
316 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
188 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
131 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
549 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
2answers
4k 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
231 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
84 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
332 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
914 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
28 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
255 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
449 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
1k 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
435 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
267 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
219 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
719 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
1k 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
101 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
178 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
1k 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
4k 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
246 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
1k 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
1k 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. ...