I'm writing a bash script and I have a function that gets 3 arguments, a hostname, a command, and a file, it should excute the command on that hostname and redirect the output to the filename. This is the fucntion:
execmd ()
{
P_SERV="$1"
P_CMD="$2"
P_OUT="$3"
X_SERV=`hostname`
if [ "$P_SERV" = "$X_SERV" ] ; then
$P_CMD >> $P_OUT
else
ssh $P_SERV $P_CMD >> $P_OUT
fi
}
When I execute:
execmd venus "cat /proc/meminfo" /tmp/meminfo
I get the error
cat /proc/meminfo: no such file or directory
any idea why its not working? same behavior either if call it with local hostname or remote hostname.