0

A shell script running on a batch server will ssh (ssh -n root@prodfs1) to the file server to run another shell script, but we'd like to run subsequent shell scripts back on the original batch server. The who command does not return the name of the server that initiated the process. Is there a command that will provide the server name of the parent process? Thanks.

3
  • Are the "subsequent shell scripts" kicked off from the shell script started on the batch server? If so look at the SSH_CONNECTION and SSH_CLIENT environment variable set up by openssh. Commented Mar 15, 2021 at 3:29
  • The subsequent shell scripts are not kicked off from the initial shell script. Commented Mar 15, 2021 at 14:01
  • 1
    Can you explain the requirements a little more. You have 2 machines "batch server" and "file server". You start a program on the "batch server". One action it does is use ssh to run a second program on the "file server". You now want to run "subsequent shell scripts" (programs 3, 4 and 5 for example) on the "batch server". What is the parent of 3,4 and 5, is it program 1 (which is already running on "batch server") or program 2 (which is running on "file server")? If it is program 2, are you going to use ssh from "file" to "batch" to start programs 3,4,5? Commented Mar 15, 2021 at 14:56

1 Answer 1

0

We were able to achieve desired results using the following:

SSHSERVER=$(echo $SSH_CLIENT | cut -d " " -f1)
SSHSERVERNAME=$(host $SSHSERVER | cut -d " " -f5 | sed "s/.$//")

Thanks to icarus for pointing us in the right direction.

1
  • If you have a POSIX shell SSHSERVER=${SSH_CLIENT%% *} is more efficient. Most things that accept hostnames will also accept ip addresses. The host command may or may not get you a usable hostname, depending on if the reverse address lookup has been populated. Commented Mar 15, 2021 at 22:06

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.