LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 05-09-2007, 04:52 PM   #1
lothario
Member
 
Registered: Apr 2004
Posts: 340

Rep: Reputation: 30
tail over scp


Once in a while I log into an application server and check the log for certain entries:
Code:
tail -n 100 /var/log/messages   |   grep -v Apattern    |   grep -v Bpattern
Now I have 3 similar application servers and I need to do the same thing on each server.
But rather than manually log into each of them one-by-one, I would like to copy
the last 100 lines of the respective server's /var/log/messages file to my
system and then do tail.

I only have ssh/scp access.

Questions:

1. Is scp the way to go? Are there any other options?

2. How can I script this so that my ids and passwords are not visible?

Eventually, I would like to then run this script via cron.
 
Old 05-09-2007, 06:08 PM   #2
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
Quote:
Originally Posted by lothario
1. Is scp the way to go? Are there any other options?

2. How can I script this so that my ids and passwords are not visible?
1.) I don't think so, The ssh command can run a program. You could use the same command and redirect the output to a file. Then the next line could use the scp command to download that file.
Code:
ssh user@appserver1 tail -n 100 /var/log/messages |grep -v Apattern | grep -v Bpattern >/tmp/messagetail-$(date +'%m%d%y')
scp user@appserver1:/tmp/messagetail-$(date +'%m%d%y') <target dir>/
This needs testing. An alternative is to have this oneliner on the server and run the script in the ssh command.

2.) You can configure sshd_conf so that you use the ssh/authorized_keys to authenticate. Another way would be to use ssh-agent. You would need to start the agent manually once, so it might not be ideal for a cron job, however this method is the most secure, because if someone gains access to your account, they would be able to copy your keys and then have access to the application servers. For this you would need to generate keys with an ssh passphrase as well. This is more secure because someone gaining access to your keys would still need to guess a long passphrase.
http://www.snailbook.com/faq/no-passphrase.auto.html
I don't think you can hide your username from 'ps'. You could have your username read in by running a private script that a normal user can't read. ( ssh may replace the username part of the /proc/<pid>/cmd with xxx's. )

Because /var/log/messages is a root readable file, and you want to run this as a cron script, it looks like this would mean that the app servers will need to allow ssh root logins. You will have to decide if the convenience of a cron job outways the additional risk to the server.
You could have a sudoers line (on each server) which would allow you to run that exact command (and only that command) as root without a password. Then you could login as a normal user, and use sudo instead of su'ing to root to run the tail command on /var/log/messages.

Last edited by jschiwal; 05-09-2007 at 06:28 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
scp does not work and gives the following error message: scp: FATAL: Executing ssh1 i akay Linux - Networking 16 09-28-2008 11:41 PM
tail +40 /etc/FILENAME newbie_mel Linux - Software 1 03-20-2006 06:25 AM
scp/ssh tail(multiple file) remote copy tpreitano Linux - General 1 08-22-2005 02:17 PM
How to see that is the HDD doing EXACTLY like tail johnnydangerous Linux - Software 2 03-17-2005 02:52 PM
tail -f dcoder Programming 8 09-01-2003 08:41 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 12:12 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration