Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place! |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
|
07-17-2012, 12:20 PM
|
#1
|
LQ Newbie
Registered: Aug 2011
Posts: 3
Rep:
|
Multiple Compress / SCP Pull Shell Script
Hey Guys,
I've come here to ask for some guidance regarding a shell script ( I am very new to this )
I would like to create the following:
A Script that runs on a "logger" box.
This script does the following:
It logs into multiple servers (about 5-6 may have to add more in the future)
and does the following:
It would log into these boxes and change to a certain directory which contain jboss logs; these logs would need to be compressed .tar.gz with a date appending to them so basically .log >> 20120716-log.tar.gz and then the logs would need to be shot across from that server to the "logger" box to a certain directory depending on the server name
so for example
Logger Box does this for SISP1 > the log is made than shot to Logger box under /archives/sisp1/
I would need this to happen for the 4 others (sisp1,2,3,4,5) to the appropriate directory on the logger box.
---
I know I need to set up keys/ known host, but cant really visualize the rest of the script.
could someone give me an example script or something I could look at for location..
All of the actual log files on the remote boxes (sisp1,2,3,4) are all in the same destination on each box.
Please let me know if I could provide any further details.
Regards
|
|
|
07-17-2012, 01:13 PM
|
#3
|
LQ Newbie
Registered: Aug 2011
Posts: 3
Original Poster
Rep:
|
Thanks Kustom,
Those tools seem nice; but I have to do this with only shell scripting. its a part of the assignment for me.
|
|
|
07-17-2012, 01:22 PM
|
#4
|
LQ Guru
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,573
|
The basic approach is to set up passwordless login via SSH keys. Then your script should be straight forward. One SSH command to create the tarball, one SCP command to copy it locally. Where are you running into problems?
|
|
|
07-17-2012, 01:58 PM
|
#5
|
Senior Member
Registered: Mar 2012
Distribution: Red Hat
Posts: 1,604
|
Ok ,well you should first tell your teacher that using the right tool for the job is, in my opinion, the #1 rule to live by as a system admin.
Since, you have to use a script you can do a cron with ssh/tar as suicidaleggroll suggested. Commandlinefu.com has some examples you can reference, a few are below to help get you in the right direction.
Keep in mind though that we aren't going to write it for you, let us know what you have done, where you are having issues and, if you can, provide some of your code so we can give you some pointers.
ssh user@host "tar -zcf - /path/to/dir" > dir.tar.gz # Would create a tarball remotely
ssh 127.0.0.1 'tar zxvf files.tar.gz -C ~/test/' # would extract a tarball remotely
|
|
|
07-17-2012, 02:35 PM
|
#6
|
LQ Newbie
Registered: Aug 2011
Posts: 3
Original Poster
Rep:
|
I've been using the following:
#!/bin/sh
#
TARGET_SERVER=sisp01.xxx.xxx.net
TARGET_DIR=/opt/hermes/heremesdata/jboss/bin/logs
# Check to see if we are being called by 'deployer'
if [ `/usr/ucb/whoami` != "deployer" ]; then
echo "$0: You must be deployer to run this script" >&2
exit 128
fi
# Check correct number or arguments have been passed
if [ $# -lt 1 ]; then
echo "$0: No filename argument" >&2
exit 129
fi
# Check if passed argument is actually a file
if [ ! -f $1 ]; then
echo "$0: Argument passed is not a file" >&2
exit 130
fi
# Transfer file
TARGET=$TARGET_SERVER:$TARGET_DIR
/opt/ssh/bin/scp -P 65134 -q $1 $TARGET
RET=$?
# Check return code
if [ $RET -ne 0 ]; then
echo "$0: scp to $TARGET failed with return code $RET" >&2;
exit $RET
fi
# Remove file
/bin/rm -f $1
exit 0
|
|
|
07-17-2012, 03:28 PM
|
#7
|
Senior Member
Registered: Mar 2012
Distribution: Red Hat
Posts: 1,604
|
So where are you having issues at exactly? It looks like it should work without issue, although I havent attempted to run it so I may be overlooking something.
Also, to help us better read your code and prevent any malformation of the code please use the [ CODE] and [ /CODE] tags. Minus the space
|
|
|
All times are GMT -5. The time now is 12:44 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|