Operating System - HP-UX
1753925 Members
9562 Online
108810 Solutions
New Discussion юеВ

Re: Best Practice local or remote script running

 
SOLVED
Go to solution
Scott Frye_1
Super Advisor

Best Practice local or remote script running

Thanks to many of you, I have compiled a script that does several system checks and writes out to an html file. We will be using this on our portal to see system staus at a glance.

My question is, now that I have this script what is the best way to check each server. Our thoughts are it would be nice to have it live on one server and run the commands remotely for each server (I don't know how to do this yet). The other option is to put the script on each server and run it via a cron. I'm looking for best practice and gotchas from anyone already doing this.

If we determine remote commands are the way to go, I may ask for help with that as well.

Thanks for all the great input here.

Scott
7 REPLIES 7
Pete Randall
Outstanding Contributor
Solution

Re: Best Practice local or remote script running

Scott,

Running your script from a central server is relatively easy - you just use remsh. However, this involves opening up the "r" services via /etc/hosts.equiv and/or root's ~/.rhosts. This is generally considered a security risk since passwords are transmitted in clear case. If you're securely locked away behind a firewall, the risk is minimal and this is a very convenient mechanism.


Pete

Pete
Sundar_7
Honored Contributor

Re: Best Practice local or remote script running

Scott,

If you have scripts run through cron, you need to have a mechanism of fetching the output from the script. Again this needs some kind of remote access (automated ftp or rcp or scp).

Do you have SSH installed in the systems ?

If you need to execute the script remotely for each server, again you need to enable remote access for the server from the machine you are planning to kick off these scripts from.

There is an alternative to this, called Service Control Manager.

http://software.hp.com/portal/swdepot/displayProductInfo.do?productNumber=B8339BA3.0

A free software that can be downloaded from the above URL.

The software effectively allows you to manage multiple HP-UX servers from a single point. Review the above URL and see if that can help you.

--Sundar.
Learn What to do ,How to do and more importantly When to do ?
Simon Hargrave
Honored Contributor

Re: Best Practice local or remote script running

You can use remsh or ssh for running a local script remotely. ssh is better, use with blank passphrases to enable non-interactive scripts.

You can then do something like: -

for HOST in server1 server2 server3
do
cat script.sh | ssh $HOST sh
done

This lets you feed a whole script to an "sh" on many machines.
Scott Frye_1
Super Advisor

Re: Best Practice local or remote script running

Just so I understand correctly. I have a script called cg.sh. This script does things like bdf, and swapinf -tm ... All I have to do is set up a script called runcg.sh that has the lines above in it and run 'runcg.sh' in a cron and it will pick up all servers?
Pete Randall
Outstanding Contributor

Re: Best Practice local or remote script running

Scott,

No, cron only runs on your local server. However, you can tell cron to run a script which uses remsh or ssh to contact the other servers.


Pete

Pete
Sundar_7
Honored Contributor

Re: Best Practice local or remote script running

Scott,

a better approach would be to list the host names in a file and use it in the script

# vi hosts.list
host1
host2
host3
..
#

# vi RUN-REMOTE.sh
for HOST in $(cat hosts.list)
do
ping $HOST -n 1 >/dev/null 2>&1
[[ $? -ne 0 ]] && echo "Cannot ping $HOST" && continue
remsh $HOST date >/dev/null 2>&1
[[ $? -ne 0 ]] && echo "Remote execution denied for this host on $HOST" && continue
cat YOUR-SCRIPT.sh | ssh $HOST sh >> $HOST.out
done
#

The above script will work provided you have SSH installed and have password-less authentication for the host or root.

Sundar

Learn What to do ,How to do and more importantly When to do ?
Muthukumar_5
Honored Contributor

Re: Best Practice local or remote script running

If you want to know the results / informations and store it as a database on one server then use remote scripting.

It may be the execution from local server machine or executing the script located on remote server.

Automation can be done with cron effectively.
Try to debug the script effectively with set -x it won't make any problem on the execution over crontab jobs.

And more use separate file to make as an environment to this script.

Example:

test.data

# SERVERNAME details using hostname
export SERVER="test huge find"

It will be used to manage scripts easily without looking into the shell script files.

Remote scripting / execution can be done using r* commands / ssh* commands / (ftp too :) )


r* commands are easy to do. Check the return type and process id return from there so that we can control. And more execute them as in background so that you can automate it in parallel mode.


Suppose to know about the vmstat informations then,

--- test.data --

# remote hostnames
export SERVER="test find"


----- test.ksh ---
#!/usr/bin/ksh
set -x

vmstat=`which vmstat`
remsh=`which remsh`

remote()
{
set -A IP $SERVER
index=0
while [[ $index -lt ${#IP[*]} ]]
do
$remsh ${IP[$index]} -l root -n "$vmstat" > /tmp/information.${IP[$index]} &

sleep 1
PID[$index]=$!

let index=index+1
done

# Process completion check
# Check the process id availability usign the process id on PID array

You can simulate more.

HTH.
+Muthu+
Easy to suggest when don't know about the problem!