1827809 Members
2044 Online
109969 Solutions
New Discussion

Re: 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!
Chris Fadrowski
Super Advisor

Re: script help

ssh is all set up.. still having problems getting my script to work.

it stops when asking for a password. I could put this in the file (i think) but can i just give root the ability to log in without asking for a password to run dmesg?
TwoProc
Honored Contributor

Re: script help

Chris, cool - you got ssh - that's great in and of itself.

Now go to the user's home directory on each machine and make a key...
ssh-keygen -t rsa
or
ssh-keygen -t dsa

Be agreeable and answer all the prompts with defaults - and when asked - don't put in a password.

cd .ssh

now, You'll see a file there id_rsa.pub or id_dsa.pub.

cat id_rsa.pub >> authorized_keys
or
cat id_dsa.pub >> authorized_keys

Do the same on both servers

Now on machine a, copy the id_rsa (or dsa) file from machine b into a file called machineb (it just a temporary file name - call it what u want).
then, cat machineb >> authorized_keys

chmod -R og-rwx ~/.ssh
(secure up all those new files)

do the same on machine b, appending the public key file (id_rsa.pub or id_dsa.pub) to the authorized_keys file.

Now, just ssh from one machine to the other.
ssh machineb
It will ask you to add a key re: your host name, be agreeable and let it.

Do the same from the other machine.

Now, you're done - you can ssh back and forth.

Make sure to read your man pages on ssh and review security settings, etc. for the ssh services... once you're done.

We are the people our parents warned us about --Jimmy Buffett
Ionut Grigorescu_2
Super Advisor

Re: script help

Chris,

when you create the keys let the passphrase empty, otherwise at login you'll be asked again the passphrase - you cannot run ssh from the script with non-empty passphrases. Otherwise you can add the passphrases to the ssh-agent but it will not work as cronjob (I've tried my own)

have a lot of fun...
If it weren't for STRESS I'd have no energy at all
TwoProc
Honored Contributor

Re: script help

Chris, you got a lot of help from a lot of people here - please assign points to the replies.
We are the people our parents warned us about --Jimmy Buffett
Chris Fadrowski
Super Advisor

Re: script help

I certainly will and always do, i am just trying to see what solution works the best.
TwoProc
Honored Contributor

Re: script help

OK, sorry - didn't think it was gonna happen - apologies.
We are the people our parents warned us about --Jimmy Buffett
Edward McCouch
Frequent Advisor

Re: script help

One thing that you can also do is just set up a little script on each server as a cronjob to run at 'X' time. (Cron is a nice way to make sure that no matter, jobs get run regardless of whatever emergency is occupyign your time.) You could also have a second script to run through each one and check for keywords and print a report that you can then check, or send you an email or whatever. Once you have the report sent to your email, then you can probably check it much easier then going to the server and checking, plus you can keep multiple copies for however long without too many issues.