1755633 Members
3282 Online
108836 Solutions
New Discussion юеВ

script help

 
SOLVED
Go to solution
Chris Fadrowski
Super Advisor

script help

I am not very good at scripting and am looking for suggestions to accomplish something.

I would like to create a script that i can run from one HPUX server that will run "dmesg", output this and then telnet to another server and run "dmesg" etc... then put it to a file that i can print or look at.. by doing this, i will be able to run once and review nightly.

my question is, how do i, in a script log into another server, run the command, then log into another etc.... is this possible?
16 REPLIES 16
TwoProc
Honored Contributor
Solution

Re: script help

First off, you need to set up a method to communicate. I recommend you install and configure ssh.
Now, after this , you can run a command like ...

for i in servera serverb serverc serverd
do
echo -------------------
echo Server $i
echo -------------------
ssh $i "/usr/sbin/dmesg"
echo --------------------
done >> dmesg_log_file

This will contact each server run dmesg on each and put the results in "dmesg_log_file".
Quite simple really - once you've got ssh working and configured.
We are the people our parents warned us about --Jimmy Buffett
Steve Steel
Honored Contributor

Re: script help

Hi


see man remsh

Run a remote shell and command

see also
www.shelldorado.com for learning

ex
hostname;remsh topaz -n pwd

xserv3
/usershome/steves

Local hostname then login dir on other machine topaz

Steve Steel
If you want truly to understand something, try to change it. (Kurt Lewin)
Peter Godron
Honored Contributor

Re: script help

Chris,
alternative to Chris's ssh is using remsh (which will need files seting up on each server) or expect (downloadable, but you can then mimic telnet sessions).
Regards
Chris Fadrowski
Super Advisor

Re: script help

where you have echo ----------


what do you mean? echo what in this space..?




sorry, i am really bad at scripting. it's quite new to me.
Rick Garland
Honored Contributor

Re: script help

The 'echo ----------' is telling the output to put the '-------------'.

echo just that, 'print what I am putting here.'
This print can be on screen or to a file or to error.

I would suggest you go with ssh instead of remsh. Once you have it setup on systems you can avoid ever using the remsh/telnet/ftp commands again - these are all substituted in ssh.

Kent Ostby
Honored Contributor

Re: script help

Another option would simply be to run dmesg via cron and have each system email you the output.

"Well, actually, she is a rocket scientist" -- Steve Martin in "Roxanne"
Geoff Wild
Honored Contributor

Re: script help

The real question is:
What data do you want to gather?

dmesg is overwritten with time...so eventually - the data that you are looking for will be gone - until you reboot...

Better to get dat via an utility - like /opt/ignite/bin/print_manifest

or cfg2html or sysinfo301

Rgds...Geoff
Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.
Biswajit Tripathy
Honored Contributor

Re: script help

"dmesg" uses a circular buffer of fixed size. So when
the buffer is full, it overwrites the earliest log. So a
better solution would be start a cron job that will run
once in every (say) 60 minutes and append it in a
file. The cron job should email this file once every
day.

Make sure that the cron job runs
# dmesg -

(dmesg with a dash as an argument). This will print
out only incremental dmesg logs.

- Biswajit
:-)
Jim Butler
Valued Contributor

Re: script help

Create a common nfs mountpoint to one central log location (That will centralize your logging)

Then use the syslogd utility, which is already running to log the messages that you want to that common log area.

All you will need to do is add a line to your /etc/syslog.conf file to log these messages to the log file

Sample line from syslog.conf

*.crit /nfsmountpoint/logs/syslog.glogal.crit
*.info;*.alert /nfsmountpoint/logs/syslog.general

restart syslogd by

/sbin/init.d/syslogd stop
/sbin/init.d/syslogd start

good luck
Man The Bilge Pumps!