Operating System - HP-UX
1833800 Members
2506 Online
110063 Solutions
New Discussion

Hoe to run execute a script from one trusted server to all servers

 
SOLVED
Go to solution
jaivinder
Frequent Advisor

Hoe to run execute a script from one trusted server to all servers

Hi Gurus,

I our datacenter we are having lot of servers.I need to fetch some information from all the servers, we are having one server from which we can login without passwd. I need to execute the script from this box in other Solaris and HPUX boxes. Can you please tell me the steps to execute this script and get it mailed to my email id.

Thanks in advance.
13 REPLIES 13

Re: Hoe to run execute a script from one trusted server to all servers

Looking at the contents of that script it would make no sense to run it on a Solaris system as there's just too much HP-UX specific stuff in there...

Any configuration you introduce that means all your systems trust just one server can be a major security issue - is that something you really want to do? Assuming it is, you'll find plenty of data on the forums for setting up ssh without requiring password access, just search for ssh

Here's one recent example:

http://forums11.itrc.hp.com/service/forums/questionanswer.do?threadId=1223480

HTH

Duncan

I am an HPE Employee
Accept or Kudo
jaivinder
Frequent Advisor

Re: Hoe to run execute a script from one trusted server to all servers

The script which i had attached is for HPUX only.I had set up the password less ssh in my environment. Now i want to run this script from one server from which I had setup the ssh. How can I execute this script using ssh.I can run some command using ssh
#ssh goldman bdf

This gives me the output. But tell me the way to run the script using ssh. And get the output file emaild to my email id.

Thanks.
Dennis Handly
Acclaimed Contributor

Re: Hoe to run execute a script from one trusted server to all servers

>I can run some command using ssh
#ssh goldman bdf
>But tell me the way to run the script using ssh. And get the output file emailed to my email id.

Basically you redirect the output then mail it:
ssh goldman bdf > log.out 2>&1
mailx -s "output of script" abc@def.com < log.out
jaivinder
Frequent Advisor

Re: Hoe to run execute a script from one trusted server to all servers

Hi Dennis,

I want to execute the script located on the server from which i am doing ssh to the other host.For example
My script hpux.script is located in the server A at /tmp/hpux.sh location. Now i want to execute this script on server B.
Please tell me the way to execute this script remotely. If i put this script in Server B and then i run the following command:
#ssh goodman /tmp/hpux.sh
Then I am able to get the output. But I do not want to put this file in server B. Please tell me the way to run this script from server A without putting it in server B.

Thanks.
Patrick Wallek
Honored Contributor

Re: Hoe to run execute a script from one trusted server to all servers

You can't easily run the script on ServerB without actually putting the script on ServerB.

Steven Schweda
Honored Contributor

Re: Hoe to run execute a script from one trusted server to all servers

> You can't easily run the script on ServerB
> without actually putting the script on
> ServerB.

NFS?

It would be more reliable to run a local
script than a remote script, but file sharing
is pretty common these days, isn't it?
jaivinder
Frequent Advisor

Re: Hoe to run execute a script from one trusted server to all servers

So what I should do no to run this script. I don't want to put it on NFS. Is there any way to run this script from server A without putting it on Server B.

Steven Schweda
Honored Contributor

Re: Hoe to run execute a script from one trusted server to all servers

Do I understand you correctly? You want to
run a script on server B, but you don't want
server B to have any local or remote access
to the script?

Were you expecting server B to use telepathy?

Do you have any actual reasons for imposing
these apparently senseless constraints on the
solution to your problem, or is this a game?
Solution

Re: Hoe to run execute a script from one trusted server to all servers

OK, are we over-complicating this... if you have passwordless ssh configured, then you also have scp configured too, so you should be able to run:

scp /tmp/hpux.sh goldman:/tmp
ssh goldman /tmp/hpux.sh >> /myoutput.txt

etc...

HTH

Duncan

I am an HPE Employee
Accept or Kudo
Steven Schweda
Honored Contributor

Re: Hoe to run execute a script from one trusted server to all servers

> scp /tmp/hpux.sh goldman:/tmp

Wouldn't that put the script on the
destination server, where we've been told it
can't be?
Dennis Handly
Acclaimed Contributor

Re: Hoe to run execute a script from one trusted server to all servers

>My script hpux.script is located in the server A at /tmp/hpux.sh location. Now I want to execute this script on server B.

You are asking for no end of problems if your script is complicated and you'll need to justify to us why you want to do such a thing.

>If I put this script in Server B and then I run the following command:
#ssh goodman /tmp/hpux.sh
>Then I am able to get the output.

Right, this is the way everyone would expect to do this.

>Please tell me the way to run this script from server A without putting it in server B.

If you insist, you'll need to change just about every line in your script to use:
ssh goodman -c "command; command"

You might get away with using a here document:
ssh goodman <command
command
EOF
Suraj K Sankari
Honored Contributor

Re: Hoe to run execute a script from one trusted server to all servers

Hi jaivinder,
For run the script into every server 1st you need to add all server names into one file suppose file name is /tmp/srvlist in this file just add all the server name like
server1
server2
server3
save the file and come out

now open other file like /tmp/main.sh
for i in `cat /tmp/srvlist`
do
ssh $i /home/yourscript.sh
done
save the file main.sh

before run main.sh ensure that you have copied yourscript.sh into /home in those 3 server
now run the script ./tmp/main.sh
enjoy

Suraj
OldSchool
Honored Contributor

Re: Hoe to run execute a script from one trusted server to all servers

"before run main.sh ensure that you have copied yourscript.sh into /home in those 3 server"

which is what he DOESN'T want to do.

since you've got passwordless login, the following will work, but you will get the login messages in your log:

=================================
File svr.list:
s1
s2
s3

=================================
Script1, on local machine only:

for svr_name in `cat svr.list`
do
/Script2 2> /dev/null >> /path-to-local-log
done

=================================
Script2, on local machine only:

ssh $svr_name <echo
echo
echo "This hp-ux Box"
echo
echo
PATH=/usr/sbin:/bin:/sbin:/usr/bin
uname -a
bdf
cat /etc/fstab
ifconfig lan0
ifconfig lan1
ifconfig lan2
ifconfig lan3
uptime
/opt/ignite/bin/print_manifest
netstat -rn
cat /stand/system
ls -ld /etc/hostna*
cat /etc/hosts
echo
echo
echo
echo
echo "#########################################"
echo "# Script Finished #"
echo "#########################################"
EOF
====================================================

Note the location of the log is determined when "Script2" is run. You will get the various login messages in the file...How you deal with that is up to you.