3

My issue is following: I've got my library (let's call it qa-baslib.sh) with various util functions, that I'm including it test scripts, we're developing.

Now, other developer created bash script library to support SSH connection to various servers (let's call it global_ssh). It looks something like:

global_ssh:

#!/bin/bash

global_ssh(){

   # Doing some ssh stuff
}

I'm sourcing that global-ssh file like that:

qa-baslib.sh

#!/bin/bash

 . /<path-to>/qa-util-scripts/global_ssh

function some_util_function() {
   server=$1
   command=$2

   # Here i'm calling global_ssh function
   timeout -s 9 30 global_ssh $sever $command
}

But when I finally executing the function, by sourcing it from command line, I got error:

]# . /<path-to>/qa-bashlib.sh
]# some_util_function $server $command
]# timeout: failed to run command `global_ssh': No such file or directory

What's wrong and is there any solution?

Thanks

Samuel
  • 3,631
  • 5
  • 37
  • 71
  • Is the shebang in script #1 a typo or the cause? – frlan Dec 13 '15 at 08:52
  • @frlan Sorry, fixed :) – Samuel Dec 13 '15 at 08:58
  • 1
    Are you sure that your system's `timeout` can run a shell function? (What does `type timeout` print?) **Edited to add:** See http://stackoverflow.com/questions/9954794/execute-function-with-timeout. – ruakh Dec 13 '15 at 09:05
  • @ruakh `/sbin/timeout`. Thanks man, it the exact point! previously there was just `ssh` so `timeout -s 9 30 ssh` was valid, but when I replaced `ssh` by function I should've remove the timeout as well :) – Samuel Dec 13 '15 at 09:13

1 Answers1

1

As @ruakh mentioned, timeout can't run with bash function as an argument.

Full answer: execute function with timeout

Community
  • 1
  • 1
Samuel
  • 3,631
  • 5
  • 37
  • 71