Home > database >  How to Pass multiple functions defined in local server to remote server using ssh and typeset
How to Pass multiple functions defined in local server to remote server using ssh and typeset

Time:12-01

I want to pass multiple fuctions which are defined in local server(myscript.sh) to remote server using ssh and typeset, I know how to pass a single fuction using typeset, I was wondering if we can pass multiple fuctions definitions using ssh and typeset.

getIPAddress()
        {       
                ip_address=$(hostname -i)
                echo $ip_address
        } 
getMachineHostName()
        {
                machine_name=$(hostname -s)
                echo $machine_name
                echo "The IP is" $(getIPAddress)
                
        } 
#This only passes the getMachineHostName fuction but not the getIPAddress fuction to ssh
ssh user@remote "$(typeset -f getMachineHostName); getMachineHostName"

CodePudding user response:

You put only the definition of one function in the string sent to the remote host. Why do you think the other function would magically appear as well?

You need to define all functions before you can use them:

ssh user@remote "$(typeset -f getMachineHostName); $(typeset -f getIPAddress); getMachineHostName"
  • Related