Re: running a command without a prefix (119 Views)
Reply
Super Advisor
lawrenzo_1
Posts: 560
Registered: ‎06-06-2003
Message 1 of 4 (119 Views)
Accepted Solution

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
Acclaimed Contributor
James R. Ferguson
Posts: 21,184
Registered: ‎07-06-2000
Message 2 of 4 (119 Views)

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...
Acclaimed Contributor
Dennis Handly
Posts: 25,067
Registered: ‎03-06-2006
Message 3 of 4 (119 Views)

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.
Super Advisor
lawrenzo_1
Posts: 560
Registered: ‎06-06-2003
Message 4 of 4 (119 Views)

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
The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation.