Operating System - HP-UX
1826567 Members
3711 Online
109695 Solutions
New Discussion

About a script to login using remsh and take uptime etc

 
sanwin
Frequent Advisor

About a script to login using remsh and take uptime etc

Hi,
I am trying a script which will do the following:

remsh hostname and redirect the output to a log file.
uptime and redirect to log file
and exit

then try the same for the next host.

But i could not give exit in the script itself. it is asking interactively.

How can i automate exit in the script itself.

Please help.

remsh > tempp.log



It needs manual intervention to get "exit".
But i need to automate it. Please help.
regards,
sanwin.
12 REPLIES 12
James R. Ferguson
Acclaimed Contributor

Re: About a script to login using remsh and take uptime etc

Hi Sanwin:

for HOST in host1 host2 host3
do
remsh ${HOST} -n uname -a
done > /var/tmp/myhostlog

See the manpages for 'remsh' for more information. Using a secure shell is also safer.

Regards!

...JRF...
sanwin
Frequent Advisor

Re: About a script to login using remsh and take uptime etc

Hi James,
I have to get the console output in a log. I mean i need to log the remsh output in a log file.

remsh -n will not show the console login details of the host.

Hope you are getting the point.

it is something like
i do remsh hostname
and do uptime cmd and do exit

and copy the terminal output to a log file.


regards,
sanwin.
Ivan Krastev
Honored Contributor

Re: About a script to login using remsh and take uptime etc

If you want hostname and uptime details use:

ssh hostname "uname -a; uptime" >> uptime.log


You can test it with:

#ssh localhost "uname -a; uptime"

until you get desired results.


regards,
ivan
Dennis Handly
Acclaimed Contributor

Re: About a script to login using remsh and take uptime etc

>remsh -n will not show the console login details of the host.

That's correct, you just get the output of that command. No need to give "exit".
Suraj K Sankari
Honored Contributor

Re: About a script to login using remsh and take uptime etc

Hi,

We are using this script to check the uptime

host=`ssh testbox hostname`
upt=`ssh testbox uptime |awk {'print $3" "$4" "$5'}|sed -e 's/,//' -e 's/,//'`
echo Hostname :$host Uptime : $upt

suraj
Peter Nikitka
Honored Contributor

Re: About a script to login using remsh and take uptime etc

Hi,

just for your interest:
The commands 'rup' and 'ruptime' provide such remote information, if the corresponding daemons are running.
Look at the man pages.

mfG Peter
The Universe is a pretty big place, it's bigger than anything anyone has ever dreamed of before. So if it's just us, seems like an awful waste of space, right? Jodie Foster in "Contact"
Fredrik.eriksson
Valued Contributor

Re: About a script to login using remsh and take uptime etc

What kind of information from the login do you want? It's always possible to replicate it by running commands.

But I'm guessing it's something like this you want?

#!/bin/bash
host=$@
# Commands seperated by a ;
commands="uptime;uname -a"
logfile="/path/to/logfile"
for thishost in $host; do
IFS=";"
for cmd in $commands; do
run="remsh $thishost -n \"$cmd\""
echo "$run" >> $logfile
$run >> $logfile
done
IFS=" "
done
sanwin
Frequent Advisor

Re: About a script to login using remsh and take uptime etc

Hi All,
thanks for your reply.

The requirement is something like:

it needs to log all the things that are seen when we do either remsh or ssh.

I need the warning and shell prompt to be logged and then the execution of the commands and their output to be logged.

please let me know if any help.

regards,
sanwin
Fredrik.eriksson
Valued Contributor

Re: About a script to login using remsh and take uptime etc

Well if you use ssh (haven't really used remsh, but I'm guessing it's doing the same) to start a remote command you are basically telling ssh to start these as your shell.
When you execute the login it will just return the output from your "shell".
Unless (maybe, not entirely sure this is possible.) you execute some kind of script locally on the machine I can't see that you can get an "interactive look" from the procedure.

Probably someone with abit more knowledge about interactive shell handling can tell you some more about the possibilities :)

Best regards
Fredrik Eriksson
Dennis Handly
Acclaimed Contributor

Re: About a script to login using remsh and take uptime etc

>it needs to log all the things that are seen when we do either remsh or ssh.
>I need the warning and shell prompt to be logged

Since these don't show up with remsh or ssh when you do a single command, you can't very well log them.

Using a here document with ssh will show the banner and prompt. But remsh just gives: Closed connection.
sanwin
Frequent Advisor

Re: About a script to login using remsh and take uptime etc

Hi Dennis,
I really did get what you are trying to say " using document here with ssh"

Could not get the point.
Is there any option available in ssh to fill the requirement.

Dennis Handly
Acclaimed Contributor

Re: About a script to login using remsh and take uptime etc

>I really did get what you are trying to say "using document here with ssh"

I said "Using a here document":
ssh machine <echo hi guy
EOF

http://en.wikipedia.org/wiki/Heredoc