1
vote
1answer
48 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 ...
2
votes
2answers
56 views

Call the script after disconnecting from server

I have a script I made for work that will call a function that takes an argument. I use the arguments to ssh into our servers. My question is: Is there a way to call the method so that if/when I get ...
3
votes
2answers
60 views

transfer a file to remote dir only if doesn't exist without replacing

I'm using CentOS linux. In one line cmd, that returns 0 if success, non-0 if failure, I need: Transfer a file to a remote server. Don't transfer the file if filename exists in remote server ...
1
vote
2answers
44 views

Copy ssh public key to multiple Linux hosts

I am trying to copy .ssh/id_rsa.pub from our central server to multiple servers. I have the following script which I usually use to push changes to the different servers. #!/bin/bash for ip in ...
3
votes
1answer
34 views

Restricted ssh remote execution with arguments

I need to enable remote execution of a shell script on a server, but deny all other access. The script is a toggle that accepts a single parameter (on/off/status). This comes close to answering my ...
2
votes
1answer
58 views

SSH config file + shell script help

Well, what I want to do seems a bit convoluted but its the only way I can think of to get the result I want. So here goes. I want to automate ssh to my Pi, in the following fashion: My Pi boots up ...
1
vote
1answer
52 views

Bash Script Display Remote Screen Session to User

I'm kind of new to bash scripting and I'm having trouble figuring out how to accomplish this. I'm working on a script that is designed to backup and manage a java application that runs within a ...
4
votes
1answer
95 views

Executing commands with ssh and shell script using variables on a remote machine

I'd like to execute a command and script located on a remote machine with a script on a local machine. I know it's possible to execute these kind of commands with ssh, so I made: #!/bin/bash ssh ...
1
vote
2answers
49 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 ...
3
votes
2answers
50 views

Have ssh-add be quiet if key already there

I want to put ssh-add /path/to/special_key at the top of a script. This works fine, but it always prompts for the passphrase. This is strange, and a little annoying, as it still asks for the ...
2
votes
1answer
209 views

Shellscript! Syntax error: unexpected “(”

Update: After the changes from the first answer I got some more error codes. : not found: line 23: { esxidown.sh: line 24: redir error Insufficient arguments. : not found: line 26: esxidown.sh: ...
2
votes
1answer
54 views

Problem on running Script on host after connecting

I am new to linux scripting. Please help. I searched on below a lot but was not able to find appropriate answer : I am trying to make a script which I will later schedule as cronjob, so that it keeps ...
1
vote
1answer
107 views

For loop not getting executed correctly over ssh

I have a script in which I am reading from a csv file where it contains SourceIp, DestinationIP,Source Ports, Destination Ports. First I am reading the sourceIp and trying to do ssh over it (I am ...
6
votes
3answers
303 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 ...
0
votes
0answers
48 views

Shell script use ssh forwarding to send a file to a second system

I have ssh forwarding enabled and ssh to server A. On server A I want to run a script as root and take advantage of the ssh key being forwarded for USER to send a file to system B. I'm getting a ...
-2
votes
1answer
86 views

automatic capturing top output by cronjob CENTOS 6.5 x86_64

I have this command: top -n 14400 -a -b -d 1 > /toplogfile.txt I want to make a script which is run by cron every day to capture top output, and if it is possible gzip the output file after the ...
1
vote
1answer
133 views

Execute command on remote host fails

I'm trying to execute some commands on remote host like this : ssh -t -t -l user 172.20.20.20 <<EOF pid=$(ps -ef | grep [a]pp-management | awk '{print $2}') && kill -9 $pid && ...
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" != "" ] ; ...
0
votes
3answers
606 views

Script to login to ssh twice

I need to login through ssh twice with a script and can't get it to work. This is what I have in my script file: #!/usr/bin/expect set login "user" set addr "address1" set addr2 "address2" set pw ...
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 ...
0
votes
1answer
1k views

scp stuck when trying to copy files from Linux to windows

I use the following scp syntax in order to transfer a lot of files from Linux red-hat 5 to windows machine (under Temp directory). SSH server is already installed on windows machine. I use this line ...
0
votes
1answer
261 views

Pseudo-terminal message in script

This is my script #!/bin/bash exec < filelist.txt while read updatedfile oldfile; do # echo updatedfile = "$updatedfile" #use for troubleshooting # echo oldfile = "$oldfile" #use ...
3
votes
4answers
2k views

List of servers to check for SSH availability

I have a list of IP address that I need to SSH to and log if I could get to them. I would use a Ping script, but DNS might have already reassigned the address. I do not care about the ones I can't get ...
2
votes
2answers
4k views

How to run sudo commands remotely via ssh -t?

I have a script that logs into a remote host via ssh -t and uses sudo service foo restart. The requirement is to avoid the prompt for a password on the remote host. The remote host authenticates via ...
5
votes
1answer
2k views

start autossh reverse tunnel automatically when network comes up

I connect from my home PC thru an Internet server I own to a restricted client (that I also own) using a reverse ssh tunnel. I have a script that sets up the restricted client to middleman leg of ...
1
vote
2answers
1k views

ssh to multiple hosts and run a command [duplicate]

How do I ssh into multiple hosts (e.g host1, host2, host3, etc) and cat /etc/fstab to generate report.txt?
2
votes
1answer
2k views

Ssh to a box, run a command, output data to a file, then move on to the next IP adress [duplicate]

I want to run a script from my Jump server, have it SSH to a server, then run a command (like rm <file>, top or ls -lsa) then take that output and put it in to a file on my Jump server then move ...
1
vote
0answers
477 views

Log in to multiple remote servers and execute a script [duplicate]

I want to make a script that will remote login to the multiple servers listed in a txt file like 10.3.9.6 10.3.9.7 and all servers have same username and password. and want to capture the output of ...
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
460 views

How to ssh on multiple ipaddress and get the output and error on the local *nix machine?

command="ls -lrt;uname -a;uname -o" for i in 10.38.227.229 10.38.164.103 do ssh auto21@$i "$command 2>&1" >> log #ssh -n auto21@$i "$command" 2> >> log done i am trying ...
4
votes
1answer
2k views

SSH causes while loop to stop

I have finally managed to boil down a problem I have been struggling with for a few weeks. I use SSH with "authorized keys" to run commands remotely. All is fine except when I do it in a while loop. ...
4
votes
2answers
232 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) ...
4
votes
2answers
2k views

Executing a shell script from remote server on local machine

Imagine a shell script on the remote server as #!/bin/bash rm /test.x How can I (if possible) to execute this script from my local machine to delete /test.x file on my local machine. Obviously, the ...
3
votes
3answers
131 views

SSH to two addresses, use the one that connects first

I have a home computer (let’s call it franklin because that’s what I call it) that I often ssh into from my work laptop. When I’m at home, I ssh to franklin.local, and when I’m at work or anywhere ...
5
votes
3answers
11k views

ssh input from text file

These two question is driving me crazy and I don't have good expertise of ssh. (but I suspect it is to do with redirection only) The questions are, You want to pass multiple lines of input from a ...
2
votes
4answers
1k views

Run if statement on remote machine

I'm trying to run a set of commands on a remote machine, that includes an if statement. I'm using this to shutdown a list of kvm instances. The first line should be fine, but could be prettier, rest ...
1
vote
1answer
17k views

How do I execute a remote shell script over SSH and be prompted for passwords by commands that require it in that script?

I want to do something like this ssh user@remote-domain.com ./remote_script.sh Contents of remote_script.sh #!/bin/bash hg pull This example is much simpler than what I am actually doing. I know ...
1
vote
5answers
2k views

Execute a command on multiple hosts, but only print command if it is successful?

Here's what I want to do. I want to check over 100 hosts and see if a file exists on that host. If the file does exist, then I want to print the hostname and the output of the command. In this ...
2
votes
1answer
674 views

How to script a database migration using SSH?

I am trying to create a sync.sh script that coordinates with our less-than-ideal version control for our website. This script will migrate a copy of the live database to our local development ...
6
votes
3answers
13k views

How to write a bash script, that logs onto an other machine to do stuff?

Is it possible to write a bash script, that would be started from machine A, logs in on a different machine B by ssh (both machines A and B would be Linux-Machines), copys some files on to machine B ...
1
vote
2answers
701 views

How to change user with authentication inside shell script

It is possible to change the user within a shell script by su - newuser; but what if the newuser needs authentication. How can I provide the password within the shell script? None of the users is ...
0
votes
2answers
630 views

Automated SSH Login [duplicate]

Possible Duplicate: Shell Script for logging into a ssh server Autentification on SSH connection in OneLine How could I make a SSH Login programmatically on a unix server, I don't have ...
0
votes
2answers
222 views

Autentification on SSH connection in OneLine [duplicate]

Possible Duplicate: Shell Script for logging into a ssh server I need to connect via SSH to a remote server, however I must do this with out interactive mode and with out use Public keys ...
4
votes
3answers
1k views

Keep running a script via ssh

ssh can use to run remote commands. ssh me@server.com 'long-script.sh' I run a long script that will take a lot of time, but I want to close my computer and keep running the script in the remote ...
3
votes
1answer
519 views

wait for autossh connection to complete

I'm trying to create a script that runs a few commands that take a long time to execute and require a constant connection, but autossh user@server wait $! #or wait ${!} commandA commandB doesn't ...
11
votes
4answers
14k views

How to delete a file on remote machine via SSH by using a Shell Script?

I am writing a Shell Script where I have to delete a file on a remote machine via a Shell Script. Flow manually: ssh username@domain.com .. then at domain: cd ./some/where rm some_file.war How ...
1
vote
3answers
995 views

How do i execute a remote script with 'screens'?

I need to execute a script locally. The problem is, it needs to use screen and send the ctrl d command. How would i do this? The script will be on my local windows machine. i can use winscp, putty, ...
16
votes
4answers
5k views

How can I detect if the shell is controlled from SSH?

I want to detect from a shell script (more specifically .zshrc) if it is controlled through SSH. I tried the HOST variable but it's always the name of the computer which is running the shell. Can I ...
6
votes
4answers
1k views

Why do I need to hit enter to get my shell prompt after my init.d script completes?

I had to write my own CentOS init.d script for celery because it only ships with one for Debian. You can see the script I wrote when I answered my own stack overflow question 3989656. But there's a ...