Operating System - HP-UX
1752664 Members
5718 Online
108788 Solutions
New Discussion юеВ

Re: running a command without a prefix

 
SOLVED
Go to solution
lawrenzo_1
Super Advisor

running a command without a prefix

Hello all,

I have created a script that runs several functions to gather system information on a remote host ....

I have to program the script to check for local host or remote host and if the server is a remote server then a prefix (ssh command) variable is set:

for SERVER_NAME in ${SERVER_LIST}
do

if [[ "${SERVER_NAME}" = "${HOSTNAME}" ]]
then

export PREFIX=""
echo " - Generating report for : ${SERVER_NAME}"
generate_report > ${REPORT_DIR}/${SERVER_NAME}.html
else

export PREFIX="ssh -l ${USER} ${SERVER_NAME}"

echo "\n - Testing connectivity to server: ${SERVER_NAME}"

if ping -c 1 -w 1 ${SERVER_NAME} >/dev/null 2>&1
then
echo " - ping test ok for server : ${SERVER_NAME}"

${PREFIX} 'echo' >/dev/null 2>&1

if [ "$?" -eq "0" ]
then
echo " - rsh test ok for sever : ${SERVER_NAME}"
echo " - Generating report for : ${SERVER_NAME}"
generate_report > ${REPORT_DIR}/${SERVER_NAME}.html
else
echo " - ERROR: Unable to ssh to : ${SERVER_NAME}"
fi
else
echo " - ERROR: Unable to ping : ${SERVER_NAME}"
fi
fi
done




the issue I have is when the script is run on the local host the ${PREFIX} variable is causing me issues:

${PREFIX} 'if [ -f /usr/bin/lparstat ]
then
LANG=C uname -Ls | read junk partition_number partition_name
echo "Partition Number : ${partition_number}"
echo "Partition Name : ${partition_name}"
fi'

its obvious that there is a problem running the commands with the '<script>'

is there anyway around this otherwise I will have to create another script to be run if the server is the local host.

Thanks in advance and I hope this isnt too confusing.

NB the example about is one of many functions run in the script.

Chris.
hello
3 REPLIES 3
James R. Ferguson
Acclaimed Contributor
Solution

Re: running a command without a prefix

Hi Chris:

If you are running on a local server, make the PREFIX variable value 'eval':

# PREFIX=eval

Regards!

...JRF...
Dennis Handly
Acclaimed Contributor

Re: running a command without a prefix

>the issue I have is when the script is run on the local host the ${PREFIX} variable is causing me issues:

Why run on the "local" host? You can ssh back to yourself and treat every system equally.
lawrenzo_1
Super Advisor

Re: running a command without a prefix

eval works for me - thanks James.

also thanks for the advise dennis as I thought it would be more logical to run commands locally on the local server.

Chris.
hello