Sponsored Content
Operating Systems Linux Red Hat To find the LATEST file from a dir on REMOTE machine and SCP to local machine? Post 302330000 by me_ub on Tuesday 30th of June 2009 05:28:43 AM
Old 06-30-2009
MySQL

Thanks Yogesh; but no luck on this as well.

In precise, I have :

On SERVER1

dir1 contains:
file1
file2
file3 --> latest one

On SERVER2, I need to execute a script that fetchs file3 into dir2.

Thanks.

---------- Post updated at 02:58 PM ---------- Previous update was at 11:53 AM ----------

Yippiee!
After spending so much time doing R&D on this, I finally got an answer for myself! Hope this helps others as well.


On SERVER2, save this as a script and execute:

Code:
latest_file=`ssh IP_ADDR_OF_SERVER1 find /dir1 -type f -mtime -1 -name "file*"`
echo Staring SCP of $latest_file from SERVER1 to SERVER2...
/usr/bin/scp user@IP_ADDR_OF_SERVER1:$latest_file /dir2
echo SCP Completed.


Enjoy.

-UB
 

10 More Discussions You Might Find Interesting

1. Solaris

[FTP]opying of file from remote to local machine

Hi All, i wannna copy a file from the remote machine to my local machine using FTP protocol. i have made a connection to the remote machine , then i used the "get" cmd to copy the remote file as below :-> ftp> get (remote-file) /home/aruba/opmtools/was50/Was5Install.doc (local-file)... (1 Reply)
Discussion started by: sonbag_pspl
1 Replies

2. Shell Programming and Scripting

check web server running on local and on remote machine

Hi , How to check whether web server is running from remote machine How to check whether web server is running on web server itself Can any one help me soon (1 Reply)
Discussion started by: satheeshkr_cse
1 Replies

3. Shell Programming and Scripting

Define local variable on remote machine ?

Hello, I'm executing many commands using ssh and I want to define local vars on remote machine to ease my work: ssh remote1 <<-heredoc1 cmd1 cmd2 ... heredoc1 This one obviously defines variable on local machine: ssh remote1 "x=10" This one returns: ssh remote1 "'x=10'" bash: x=10:... (1 Reply)
Discussion started by: vilius
1 Replies

4. Shell Programming and Scripting

Using local variable on a remote machine

Hi, I'm writing a korn shell script where the user enters a variable and I have to create a directory remotely which contains the name of that variable. Example. print 'Please enter variable:' read variable ssh user@host 'mkdir before_$variable;' Thank you. (4 Replies)
Discussion started by: jangozo
4 Replies

5. Shell Programming and Scripting

shell script to copy files frm a linux machine to a windows machine using SCP

I need a shell script to copy files frm a linux machine to a windows machine using SCP. The files keeps changing day-to-day. I have to copy the latest file to the windows machine frm the linux machine. for example :In Linux, On July 20, the file name will be 20.txt and it should be copied to... (3 Replies)
Discussion started by: nithin6034
3 Replies

6. Shell Programming and Scripting

How to transfer files from unix machine to local machine using shell script?

Hi All.. Am new to Unix!! Am creating a shell script in which a scenario is like i have transfer the output file from unix machine (Server) to local directory (Windows xp). And also i have to transfer the input file from the local directory to Unix machine (Server) Any help from you... (1 Reply)
Discussion started by: vidhyaS
1 Replies

7. UNIX for Advanced & Expert Users

FTP While transfering files to local machine to remote machine

Hi Am using unix Ksh Am getting the problem while transferring zero size files through the script . When i transfer zero size files from local machine to remote machine manually i can able to do it . My question its beause of zero size files am not able to transfer through script ? or its... (2 Replies)
Discussion started by: Venkatesh1
2 Replies

8. Red Hat

iptables applied in local machine, can't ssh remote machine after chain changed to DROP

I want to SSH to 192.168.1.15 Server from my machine, my ip was 192.168.1.99 Source Destination was UP, with IP 192.168.1.15. This is LAN Network there are 30 Machine's Connected to the network and working fine, I'm Playing around the local machine's because I need to apply the same rules in... (2 Replies)
Discussion started by: babinlonston
2 Replies

9. Shell Programming and Scripting

Help with fetching the data from remote machine from my jumpbox(local machine)

Team, Presently i am running a script from my local box(i.e jumpbox) to all the remote machines.Basically fetching basic queries like pwd,mkdir,touch etc and i am able to successfully fetch it from my local machine.But when i want to check certain database related queries like the dbstat... (20 Replies)
Discussion started by: whizkidash
20 Replies

10. Shell Programming and Scripting

How can I execute local script on remote machine and include arguments?

I have a script in local server cd /home/dell/work/BOP/testdir ./processchk po (here processchk is a script & po is passed as an argument) Now I want to execute this script from remote server ssh $username@$hostname "cd /home/dell/work/BOP/testdir; ./processchk po" But Its getting error... (9 Replies)
Discussion started by: manohar2013
9 Replies
diff(1) 							   User Commands							   diff(1)

NAME
diff - compare two files SYNOPSIS
diff [-bitw] [-c | -e | -f | -h | -n | -u] file1 file2 diff [-bitw] [-C number | -U number] file1 file2 diff [-bitw] [-D string] file1 file2 diff [-bitw] [-c | -e | -f | -h | -n | -u] [-l] [-r] [-s] [-S name] directory1 directory2 DESCRIPTION
The diff utility will compare the contents of file1 and file2 and write to standard output a list of changes necessary to convert file1 into file2. This list should be minimal. Except in rare circumstances, diff finds a smallest sufficient set of file differences. No output will be produced if the files are identical. The normal output contains lines of these forms: n1 a n3,n4 n1,n2 d n3 n1,n2 c n3,n4 where n1 and n2 represent lines file1 and n3 and n4 represent lines in file2 These lines resemble ed(1) commands to convert file1 to file2. By exchanging a for d and reading backward, file2 can be converted to file1. As in ed, identical pairs, where n1=n2 or n3=n4, are abbrevi- ated as a single number. Following each of these lines come all the lines that are affected in the first file flagged by `<', then all the lines that are affected in the second file flagged by `>'. OPTIONS
The following options are supported: -b Ignores trailing blanks (spaces and tabs) and treats other strings of blanks as equivalent. -i Ignores the case of letters. For example, `A' will compare equal to `a'. -t Expands <TAB> characters in output lines. Normal or -c output adds character(s) to the front of each line that may adversely affect the indentation of the original source lines and make the output lines difficult to interpret. This option will preserve the original source's indentation. -w Ignores all blanks (<SPACE> and <TAB> characters) and treats all other strings of blanks as equivalent. For example, `if ( a == b )' will compare equal to `if(a==b)'. The following options are mutually exclusive: -c Produces a listing of differences with three lines of context. With this option, output format is modified slightly. That is, output begins with identification of the files involved and their creation dates, then each change is separated by a line with a dozen *'s. The lines removed from file1 are marked with '--'. The lines added to file2 are marked '+'. Lines that are changed from one file to the other are marked in both files with '!'. -C number Produces a listing of differences identical to that produced by -c with number lines of context. -D string Creates a merged version of file1 and file2 with C preprocessor controls included so that a compilation of the result with- out defining string is equivalent to compiling file1, while defining string will yield file2. -e Produces a script of only a, c, and d commands for the editor ed, which will recreate file2 from file1. In connection with the -e option, the following shell program may help maintain multiple versions of a file. Only an ancestral file ($1) and a chain of version-to-version ed scripts ($2,$3,...) made by diff need be on hand. A ``latest version'' appears on the stan- dard output. (shift; cat $*; echo '1,$p') | ed - $1 -f Produces a similar script, not useful with ed, in the opposite order. -h Does a fast, half-hearted job. It works only when changed stretches are short and well separated, but does work on files of unlimited length. Options -c, -C, -D, -e, -f, and -n are unavailable with -h. diff does not descend into directories with this option. -n Produces a script similar to -e, but in the opposite order and with a count of changed lines on each insert or delete com- mand. -u Produces a listing of differences with three lines of context. The output is similar to that of the -c option, except that the context is "unified". Removed and changed lines in file1 are marked by a '-' while lines added or changed in file2 are marked by a '+'. Both versions of changed lines appear in the output, while added, removed, and context lines appear only once. The identification of file1 and file2 is different, with "---" and "+++" being printed where "***" and "---" would appear with the -c option. Each change is separated by a line of the form @@ -n1,n2 +n3,n4 @@ -U number Produces a listing of differences identical to that produced by -u with number lines of context. The following options are used for comparing directories: -l Produces output in long format. Before the diff, each text file is piped through pr(1) to paginate it. Other differences are remembered and summarized after all text file differences are reported. -r Applies diff recursively to common subdirectories encountered. -s Reports files that are identical. These identical files would not otherwise be mentioned. -S name Starts a directory diff in the middle, beginning with the file name. OPERANDS
The following operands are supported: file1 A path name of a file or directory to be compared. If either file1 or file2 is -, the standard input will be used in its file2 place. directory1 A path name of a directory to be compared. directory2 If only one of file1 and file2 is a directory, diff will be applied to the non-directory file and the file contained in the directory file with a filename that is the same as the last component of the non-directory file. USAGE
See largefile(5) for the description of the behavior of diff when encountering files greater than or equal to 2 Gbyte ( 2**31 bytes). EXAMPLES
Example 1: Typical output of the diff command In the following command, dir1 is a directory containing a directory named x, dir2 is a directory containing a directory named x, dir1/x and dir2/x both contain files named date.out, and dir2/x contains a file named y: example% diff -r dir1 dir2 Common subdirectories: dir1/x and dir2/x Only in dir2/x: y diff -r dir1/x/date.out dir2/x/date.out 1c1 < Mon Jul 2 13:12:16 PDT 1990 --- > Tue Jun 19 21:41:39 PDT 1990 ENVIRONMENT VARIABLES
See environ(5) for descriptions of the following environment variables that affect the execution of diff: LANG, LC_ALL, LC_CTYPE, LC_MES- SAGES, LC_TIME, and NLSPATH. TZ Determines the locale for affecting the timezone used for calculating file timestamps written with the -C and -c options. EXIT STATUS
The following exit values are returned: 0 No differences were found. 1 Differences were found. >1 An error occurred. FILES
/tmp/d????? temporary file used for comparison /usr/lib/diffh executable file for -h option ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWesu | +-----------------------------+-----------------------------+ |CSI |Enabled | +-----------------------------+-----------------------------+ |Interface Stability |Standard | +-----------------------------+-----------------------------+ SEE ALSO
bdiff(1), cmp(1), comm(1), dircmp(1), ed(1), pr(1), sdiff( 1), attributes(5), environ(5), largefile(5), standards(5) NOTES
Editing scripts produced under the -e or -f options are naive about creating lines consisting of a single period (.). Missing NEWLINE at end of file indicates that the last line of the file in question did not have a NEWLINE. If the lines are different, they will be flagged and output, although the output will seem to indicate they are the same. SunOS 5.10 22 Sep 2004 diff(1)
All times are GMT -4. The time now is 03:36 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy