Sponsored Content
Top Forums Shell Programming and Scripting Running Commands on a Remote Linux Server over SSH Post 302924348 by seekryts15 on Saturday 8th of November 2014 06:30:13 AM
Old 11-08-2014
Display Running Commands on a Remote Linux Server over SSH

Hello,
I'm trying to create a ksh script to ssh to a remote server, enter the password and a couple commands. For security reasons I have changed the login, password and ip in my example.

Code:
#!/bin/ksh

ssh -t -t username@12.5.5.3 << EOF
password
cd bin
pwd
EOF

When I run it. It stalls at the password prompt and it will only continue when I manually enter it. I see the errors are produced due it entering the info too quickly. Is there a way for it to accept the password via script and then wait a certain amount of time before executing the commands? Also need it to exit the remote server when it completes. Any help is much appreciated, thanks.


Example results:
Code:
# /home/test/testscript.ksh
username@12.5.5.3's password:      <----STALLS HERE. ONLY PROCEEDS WHEN I ENTER THE PASSWORD MANUALLY.
password
cd bin
pwd
[username@remoteserver ~]$ password
[1] 27729
-bash: pas: command not found
-bash: sword: command not found
[1]+  Exit 127                pas
[username@remoteserver ~]$ cd bin
[username@remoteserver bin]$ pwd
/home/user/bin
[username@remoteserver bin]$       <----STOPS AND STILL ON REMOTE SERVER.

 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

mac 10.4>terminal>linux remote server>ssh login accepted>session closed-why?

mac 10.4>terminal>linux remote server>ssh login accepted>session closed-why? AHHHH!! I have been connecting to the server with the line: ssh userid@website.com The remote server accepts my password; logs me in with ssh; posts a lovely welcome message AND closes the session. Is this a "term... (0 Replies)
Discussion started by: xprankard
0 Replies

2. Shell Programming and Scripting

Can BASH execute commands on a remote server when the commands are embedded in shell

I want to log into a remote server transfer over a new config and then backup the existing config, replace with the new config. I am not sure if I can do this with BASH scripting. I have set up password less login by adding my public key to authorized_keys file, it works. I am a little... (1 Reply)
Discussion started by: bash_in_my_head
1 Replies

3. Shell Programming and Scripting

remote ssh commands help

I have a script that I'm trying to use that will check for files on a remote machine and if there is files copy the files, modify the perm on the copied files, and then delete the files off of the remote server. Right now I need to get the correct syntax so the the remote commands still interpret... (4 Replies)
Discussion started by: jcalisi
4 Replies

4. Shell Programming and Scripting

Problem running ssh from remote server

So I have a script which performs some basic commands on another server via ssh. It works great, no issues at all. Let's call this "Script A" BUT, this working script is to be executed remotely from a different UNIX script on another server, also by ssh. Let's call this "Script B". When... (1 Reply)
Discussion started by: newerakb
1 Replies

5. Shell Programming and Scripting

Running a function on a remote server via SSH in a script

I'm working on a script (mostly for practice) to simplify a task I have to do every now and then. I have a cluster with 6 servers on it, each server has a directory with a set of files called *.pid and *.mpid. Each file contains the pid of a process that may or may not be running on that server.... (3 Replies)
Discussion started by: DeCoTwc
3 Replies

6. Shell Programming and Scripting

executing commands in remote server using ssh

I have some commands which need to be executed in remote machine. I have Linux Server from where I need to connect to Solaris server using ssh and then declare some variable over there and run some commands. I don't want to call a script which is present in Solaris server from Linux server... (7 Replies)
Discussion started by: maitree
7 Replies

7. UNIX for Dummies Questions & Answers

Running commands on remote machines

so i want to monitor a variety of things on hundreds of servers. the old process was to have an agent running on each one of these servers. but now i'm looking to see if its possible to have agentless monitoring. the only other straight forward option other than having an agent on the hosts, is... (2 Replies)
Discussion started by: SkySmart
2 Replies

8. Shell Programming and Scripting

Remote ssh commands

ssh XXXXX@XXXXX'. $HOME/.profile 2>/dev/null;cd $COMMON_TOP/admin/scripts/$CONTEXT_NAME; adcmctl.sh start "apps${AppsPass}" || cd $ADMIN_SCRIPTS_HOME; adcmctl.sh start "apps${AppsPass}"' As per our business requirement we should be able to execute the above two commands seprated with or ( || )... (4 Replies)
Discussion started by: Y.balakrishna
4 Replies

9. Shell Programming and Scripting

How to run commands on remote server using ssh password less authentication?

Hi, I need to run a script located in a directory on remote server by using ssh authentication from my local unix server. Can anyone help me in this. I have tried the below command. It worked for echo command but when i tried to open a file using cat command it is showing "cat: cannot open... (6 Replies)
Discussion started by: ssk250
6 Replies

10. Shell Programming and Scripting

Ssh - running commands on remote server

Hi, I am trying to run commands on a list of servers that I can ssh to and just want to know if there is a 'cleaner' way of doing this. At the moment, I am doing as below. Is there a way that I can escape the double quote differently? If a use a single quote to enclose the commands that I... (1 Reply)
Discussion started by: newbie_01
1 Replies
KNIFE-SSH(1)							    Chef Manual 						      KNIFE-SSH(1)

NAME
knife-ssh - Run a command or interactive session on multiple remote hosts SYNOPSIS
knife ssh QUERY COMMAND (options) -a, --attribute ATTR The attribute to use for opening the connection - default is fqdn -C, --concurrency NUM The number of concurrent connections -m, --manual-list QUERY is a space separated list of servers -P, --ssh-password PASSWORD The ssh password -x, --ssh-user USERNAME The ssh username -i, --identity-file IDENTITY_FILE The SSH identity file used for authentication -p, --ssh-port PORT The ssh port --[no-]host-key-verify Verify host key, enabled by default. DESCRIPTION
The ssh sub-command opens an ssh session to each of the nodes in the search results of the QUERY. This sub-command requires that the net-ssh-multi and highline Ruby libraries are installed. On Debian systems, these are the libnet-ssh-multi-ruby and libhighline-ruby pack- ages. They can also be installed as RubyGems (net-ssh-multi and highline, respectively). TERMINAL MULTIPLEXING AND TERMINAL TAB SUPPORT
knife ssh integrates with several terminal multiplexer programs to provide a more convenient means of managing multiple ssh sessions. When the COMMAND option matches one of these, knife ssh will create multiple interactive ssh sessions running locally in the terminal multi- plexer instead of invoking the command on the remote host. The available multiplexers are: interactive A built-in multiplexer. interactive supports running commands on a subset of the connected hosts in parallel screen(1) Runs ssh interactively inside screen. ~/.screenrc will be sourced if it exists. tmux(1) Runs ssh interactively inside tmux. macterm (Mac OS X only) Opens a Terminal.app window and creates a tab for each ssh session. You must install the rb-appscript gem before you can use this option. SEE ALSO
knife-search(1) AUTHOR
Chef was written by Adam Jacob adam@opscode.com with many contributions from the community. DOCUMENTATION
This manual page was written by Joshua Timberman joshua@opscode.com. Permission is granted to copy, distribute and / or modify this docu- ment under the terms of the Apache 2.0 License. CHEF
Knife is distributed with Chef. http://wiki.opscode.com/display/chef/Home Chef 10.12.0 June 2012 KNIFE-SSH(1)
All times are GMT -4. The time now is 11:59 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy