Remsh on HP-UX hosts in for loop help

Soldato
Joined
1 Oct 2006
Posts
14,550
Hello,

I've got a bunch of ancient HP-UX boxes that I can't put SSH on, so I've got to use rsh. Long and the short of it, we've got a specific app that is connection sensitive and susceptible to network glitches - if the network drops for a split second then the user gets kicked out and a ghost session remains. So every now and then, we get a request to clear the sessions across 20 odd servers. When this happens for multiple users, it can be a very time consuming process.

So, started thinking about ways round this but ran into a bit of stick with the cronky HP-UX limitations. So, I've got a list of hosts in a text file which I'm calling in a script then running this command:

for host in `cat /tmp/hosts.txt`
do
echo $host
rsh $host ps -ef | grep 1.0.0.1 | grep -v | awk '{print $2}' | xargs kill -9
done

Now the "ps -ef | grep 1.0.0.1 | grep -v | awk '{print $2}' | xargs kill -9" bit works perfectly when executed on host, but when you rsh it the "xargs kill -9" portion of the command tries to run on the host you're rsh-ing from. Bummer.

I've been reading around, and it says to dump the command you want executed remotely into "" "" because of funkyness in HP-UX. Doesn't seem to work though as it then looks for a command called "xargs kill -9" - Failboat.

So, anyone have an idea of the syntax needed to make this work?

The dirty cheat way I used to night was to create a small shell script of the command needed and rcp it out to every host, then for loop the host list as above and run the script. :rolleyes:

Cheers in advance
:D
 
Customer boxes with stringent requirements and CM processes, they're pretty important monitoring boxes that need to be up 24/7/365. So they get a little jumpy when we mention any kind of work other than day-to-day.

I know, it would make more sense to have a preventative maintenance push on them - but they're that stubborn about it and we have tried in the past :(
 
I'm assuming that your source box you are running from is Linux not HPUX as otherwise you'd be using remsh not rsh. Have you tried putting " around the command to be run, (or possibly ` (I can't check as all systems here are locked down so don't have the services available to remsh or rsh)
 
I'm running it from a Solaris 9 box. Have tried various combinations of " " around different parts of the command but they all end in invalid strings being passed to kill (it quotes the syntax 20 odd times as it runs), or it tries to source the entire string as a standalone command which it fails to do.

Sometimes I wish they would just let us bring this boxes up to spec instead of working around these limitations, I mean they've trusted us enough for years to support and keep running - why not make changes?? :confused: meh!
 
Hmmm Solaris is not an OS I know a great deal about, (I deal with HPUX, Linux and a bit of AIX), and I'm not in the office so I can't talk to the people that do. Looking at the rsh man page have you tried the -n switch as the Notes section of the man page I was looking at implied that it was needed if you were using the pipe character remotely with rsh.

Personally I'd probably create a little script on each box and then call that.

[Edit: as you say the command works if you run it locally I assume that the | grep -v | is a typo on here as on the 11i box here that just gives a syntax error and needs a | grep -v grep | ]
 
Last edited:
Yep, tried -n too. The rcp script idea was the dirty work around, but it made me feel cheap and used lol.

I'll keep plugging away, cheers anyway!
 
Had a word with one of the Solaris guys ... he suggests enclosing the whole command in single quotes and escape the single quotes in the awk command, i.e.

rsh $host 'ps -ef | grep 1.0.0.1 | grep -v grep | awk -F" " \'{print $2}\' | xargs kill -9'

(alternatively he to says call scripts in the HPUX boxes :))
 
Just saw you edit about my typo - yep, it was supposed to be "grep -v grep".

Alrighty, I'll give that a crack. Thanks for checking up on that one for me, much appreciated. :D
 
Back
Top Bottom