how to pass the argument as function in server2 from grid server

Viewed 18

I have a grid server. From that I need to connect to two other servers. From the grid server, I am able to pass the command in server1 and after checking the status, the next code should have to perform operation on server2 from the grid server.

Below are the conditions of my code:

  1. After reading the input (Enter the Username:) if service status is working fine in server1 then it should need to provide status as given user is contract User to grid server.
  2. After exit from server 1 once it provided status to grid then it should need to pass the arguments to server2 from grid. I don't want to perform any operation with the sshpass command. Through a function I would like to pass the codes to server2 from grid server .

The script is stored in grid server.

Code:

#!/bin/bash
USER=$1
echo "Checking for user type"
read -r "Enter the Username: " USER
ssh server1 /opt/ldap/bin/ldapfind --user "$USER" | grep "/usr/sr"
status=$?
if [ $status -eq 0 ]; then
    echo "Given user is contract User"
    else
    echo "Given user is employee"
    exit 0
    fi
    
    ssh server2 
    uid_vaule=$(getent passwd "$USER" | cut -d : -f 3)
    gid_vaule=$(getent passwd "$USER" | cut -d : -f 4)
    getent_status=$?
    if [ $getent_status -eq 0 ]; then
    echo "Do you want to enter homepath , please type here "
    read -r "$home_path"
    if [ -z "$home_path" ]; then
        available_path=( \
        "/home01" \
        "/home02" \
        "/home03" \
        "/home04" \
        "/home05" \
        )
        home_path=${available_path[ $(( RANDOM % ${#available_path[@]} )) ] }
    else
        echo "Setting homepath to $home_path"
    fi
    
 fi
0 Answers
Related