Hello all, I'm stuck with a routine that is driving me crazy.
What I need to do is GET (or grep is better) the latest log file created on a specified directory stored on remote machine.
It's a classic log file, and the filename is like:
20101024_221000_10.92.10.1.log
20101024_221500_10.92.10.1.log
20101024_222000_10.92.10.1.log
And will be created every 5 minutes
So, how can I list the remote directory, then GET the latest log file to analyze it (in the log directory there are other logs but with different name, and I don't need them!!)
This will give you the name of the last remote log you can then put it into a variable and bring it to the local machine with an scp for further analysis
Code:
ssh user@remotemachine "ls -t /remote/dir/*.log | head -1"
Last edited by ctsgnb; 10-24-2010 at 06:45 PM..
Reason: typo
If you're looking at automating this process, it's worth setting up public/private ssh keys to allow password-less ssh to the user account on the remote machine.
Thanks for reply,
ssh is a good solution, but as Chubler said I need an automating process since I run it from a bash script.
I don't know how to setup public/private ssh keys (but I can google for it), the problem is that the source machine doesn't have a fixed IP (don't know if this can be a problem).
Is there any other ways to do what I need?
---------- Post updated at 02:55 AM ---------- Previous update was at 01:36 AM ----------
Well, after setting up the SSH keys IT WORKS!!! Thanks a million!!
BTW, I have now only 2 small problems...
When I use remote SSH (from Ubuntu to Read Hat) I got the following output:
Code:
lucas@client:~$ ssh lucas@10.97.1.1 "ls -t /home/lucas/log/*.log | head -1"
--- Unauthorised access prohibited ---
This is a closed-access system. If you do not have permission
to access this system, then log off now. If you remain logged on
you consent to monitoring of your actions.
/home/lucas/log/20101024_222000_10.92.10.1.log
Problem 1 (the Unauthorised access message):
Is there a way to include in the smh/ls command also a "tail -1" so to keep only the last line??
Problem 2 (file is with all path)
I already know how to extract the part with the filename, but is it possible to include that command into the ssh/ls command ??
Now, is there a way to redirect the output to a string variable?
So I can easily remove the path and keep only the filename to use it (GET it via FTP)...
I am trying to cat on a file located on remote server and assign it to remote variable.
I have both local and remote variables. Running below script from local. test.sh
J_NAME=XXX2
J_IP=XXX
ssh $J_IP "ps auxw |grep java | grep -v grep |grep $J_NAME | awk '{print ... (2 Replies)
Hi friends,
i need to prepare a script ( in perl)
i have a file called "demo.exe" in my local unix host.
i have a list of remote hosts in a file "hosts.txt"
now i need to push "demo.exe" file to all the hosts in "hosts.txt" file.
for this i need to prepare a script(in perl, but shell... (5 Replies)
Hi
I need to parse the file of same name which exist on different servers and calculate the count of string existed in both files.
Say a file abc.log exist on 2 servers.
I want to search for string "test" on both files and calculate the total count of search string's existence.
For... (6 Replies)
Hi,
I have written a script which would FTP a dump file to the FTP server and log the whole activity into a file. to confirm the success of the file copy i grep for "226 file receive OK" and then send out an email saying success. Now i want to make sure the bytes of the local file and... (4 Replies)
I m stuck with a issue.
I need to calculate the time difference between two files.. one on the local machine and one on the remote machine using a script.
Can any one suggest the way this can be achevied
Thanks,
manohar (1 Reply)
Hi,
I need to login to a remote server.
Go to a particular path.
Get the lists of files on that path.There may be n number of files.
I need to delete only those files from above created list which are 7 days older.
I have achieved above using ftp protocol, but now the constraint has... (0 Replies)
hi every one ,
here is my problem !!
i have to run my script from an account and update the result in a xml file located on a different account. i use existing ssh keys to do it remotely
for example the tags looks like this
<PropertyValueList... (1 Reply)
Dear all;
I am new to UNIX scripting and I want to download remote server's dir listing every hour, to check whether it is updating. How can I do this.
can I use ftp command to down load this dir listing.
Pls help me in this regards.
tks (1 Reply)