1832780 Members
3110 Online
110045 Solutions
New Discussion

Re: scripting help

 
SOLVED
Go to solution
fg_1
Trusted Contributor

scripting help

Hello all: I have a scripting question for all to chew on:

I am trying to figure out how to take a script and make it peruse the syslog file and dmesg file plus other error logs for errors and put them into a single file, (THIS PART OF THE TASK IS NOT TOO DIFFICULT), The 2nd part of the equation is to take each of these files and FTP them from each system to one central system so that I can then combine all of the files into one single file to be emailed daily as a system error message file for all systems. I was wondering how to work the FTP from one system coding this part of it is driving me nuts. I was wondering if anyone might have some code that does FTP from each system and brings it back to one central point, i figure that I have to factor in being able to code the root password or equivelent password to be able to allow FTP to log in to the system. Just for information, ALL systems in our domain have the ability to FTP to each other. So if someone has an idea please let me know. Thanks in advance.
6 REPLIES 6
Bill Hassell
Honored Contributor
Solution

Re: scripting help

Here's a hint on searching for useful messages in syslog, dmesg, etc:

grep -i -e warn -e err -e fail -e serious /var/adm/syslog/syslog.log

For batch FTP, use the 'here' document technique:

#!/usr/bin/sh
set -u
export PATH=/usr/bin
DEST=12.34.56.78
USER=ftpuser
PW=somepassword
LOCALCD=/var/temp/special
REMOTECD=/var/temp/collector
MYFILE=
ftp -n -v $DEST << EOF
user $USER $PW
binary
lcd $LOCALCD
cd $REMOTECD
put $MYFILE
chmod 600 $MYFILE

EOF

root password? Totally unnecassary and a big security risk. Send and receive your logfiles as an ordinary user (ie, ftpuser for instance). This script must be 700 permission so no one except ftpuser can read or write it.


Bill Hassell, sysadmin
MAD_2
Super Advisor

Re: scripting help

Bill, I am sorry but I don't understand when you say the "'here' document technique" What do you mean with that?
Contrary to popular belief, Unix is user friendly. It's just very particular about who it makes friends with
Peter Kloetgen
Esteemed Contributor

Re: scripting help

Hi Mynor,

the here- technique means, he uses a different EOF ("End of file") than the default. Let's explain with the mail- command:

normally:
mail user@host (return)
text (return)
text (return)
ctrl-d

the ctrl-d combinations is the signal for the mail-command that his input is now over. Here- technique would be:

mail user@host << EOF (return)
text (return)
text (return)
EOF

<< ----> tells your command, not to use the normal end of file- combination. (configurable over stty-command)
EOF ----> tells the command, for what to look instead. Here you can also write something else, but you have to take care, that your EOF- marker is a single word at the beginning of a line to get it work.


Allways stay on the bright side of life!

Peter
I'm learning here as well as helping
Justo Exposito
Esteemed Contributor

Re: scripting help

Hi Frank,

Do you know the file .netrc?
Please read man netrc.

Hope this helps,

Justo.
Help is a Beatiful word
Graham Cameron_1
Honored Contributor

Re: scripting help

Frank

You can do all you want and lots more besides by using big brother. http://www.bb4.com/

And if you want to know about "here documents", try

http://www.tldp.org/LDP/abs/html/here-docs.html

or HPs own shell users guide at

http://docs.hp.com/hpux/onlinedocs/B2355-90046/B2355-90046.html

Graham
Computers make it easier to do a lot of things, but most of the things they make it easier to do don't need to be done.
Steve Steel
Honored Contributor

Re: scripting help

Hi

You can use tail -f

tail -f /var/adm/syslog/syslog.log |remsh topaz "cat - > /tmp/xantia 2>&1"&

This reads my syslog as it is filled up and writes a copy on machine topaz in /tmp/machine


Like this you can filter

tail -f /var/adm/syslog/syslog.log|while read line
do
echo $line|grep -i error
echo $line|grep -i warning
done|remsh topaz "cat - > /tmp/xantia 2>&1"

process stays open but avoids all the ftp opens and closes

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