Remote file list


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Remote file list
# 1  
Old 10-24-2010
Remote file list

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!!)

Thanks!
# 2  
Old 10-24-2010
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
This User Gave Thanks to ctsgnb For This Post:
# 3  
Old 10-24-2010
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.
# 4  
Old 10-25-2010
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!! Smilie

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 ??

Thanks for your precious help!
# 5  
Old 10-25-2010
maybe try
Code:
ssh user@remotemachine "ls -t /remote/dir/*.log | head -1" 2>/dev/null

?
This User Gave Thanks to ctsgnb For This Post:
# 6  
Old 10-25-2010
Code:
2>/dev/null

Works!
I shown the following output:
Code:
/home/lucas/log/20101024_222000_10.92.10.1.log

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)...
# 7  
Old 10-25-2010
Code:
VAR=$(ssh user@remotemachine "ls -t /remote/dir/*.log | head -1" 2>/dev/null )

or
Code:
VAR=`ssh user@remotemachine "ls -t /remote/dir/*.log | head -1" 2>/dev/null`

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Unable to ssh and list files in local directory from remote.

#!/bin/bash script_work_dir="/home/websys/TEST_dpi_42_file_trnsfer_engine/PORT22/script_work_area" script_config_dir="/home/websys/TEST_dpi_42_file_trnsfer_engine/PORT22/script_config" dpi_sourceServerList=$script_config_dir"/dpi_sourceServerList" dpi_srvr_42="rtm@1.1.1.1"... (8 Replies)
Discussion started by: sadique.manzar
8 Replies

2. Shell Programming and Scripting

How to store remote variable from remote cat file ??

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)
Discussion started by: oraclermanpt
2 Replies

3. Shell Programming and Scripting

Copy a file from local host to a list of remote hosts --- perl script

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)
Discussion started by: siva kumar
5 Replies

4. Shell Programming and Scripting

Is it possible to create 10GB file in Linux and transferring the file to other remote server

Hi folks, Is it possible to create 10GB file in linux and transferring the file to other remote server? Regards, J (3 Replies)
Discussion started by: scriptscript
3 Replies

5. Shell Programming and Scripting

Parse file from remote server to calculate count of string existence in that file

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)
Discussion started by: poweroflinux
6 Replies

6. Shell Programming and Scripting

file size comparision local file and remote file

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)
Discussion started by: dba.admin2008
4 Replies

7. Shell Programming and Scripting

Calculate the time difference between a local file and a remote file.

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)
Discussion started by: meetmano143
1 Replies

8. AIX

Get the list, filter and delete the files on remote server

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)
Discussion started by: mail_amitnagpal
0 Replies

9. Shell Programming and Scripting

serach and replace file name in the path in a remote xml file

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)
Discussion started by: kiranreddy1215
1 Replies

10. Shell Programming and Scripting

To get the dir list of a remote server

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)
Discussion started by: HMS.Chandrasiri
1 Replies
Login or Register to Ask a Question