Sponsored Content
Top Forums Shell Programming and Scripting shell script to copy files frm a linux machine to a windows machine using SCP Post 302540499 by ironmonkey555 on Thursday 21st of July 2011 12:56:39 AM
Old 07-21-2011
MySQL

The explanation you provided still seems unclear to me... but I assume that the file with unique name is generated by other application everyday, so you won't be requiring script to generate filename, but you only require a script to extract the name of latest file and scp it to windows machine....
The script I've provided you earlier, if you look carefully provides you latest file in that directory, however if you want some specific files only to be found in the result set, you can have 'grep' after 'ls -lgt', like

Code:
file_name=ls -lgt | grep regex | head -2 | awk '{print $7}'
$scp $file_name /windows/machine/path

To run this script daily you can put this script in cron schedule, I hope you are aware of it nicely!

Smilie




Quote:
Originally Posted by nithin6034
I need a script for this. Let me clear the things in detail.

I have a linux machine, where the file gets changing everyday (new files will be updated everyday). I want to copy the most latest file to the windows server.

I can use scp for this.

scp -r [/path/filename] [login name@ip address] : .

Here the filename gets changing everyday and I want to copy the files to a specific folder in Windows. How to do this using a script which automatically does this on a daily basis???

Seek ur help to solve this..

Last edited by Franklin52; 07-21-2011 at 03:53 AM.. Reason: Please use code tags for code and data samples, thank you
 

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

how can i copy data in LINUX Machine to windows XP

Can anyone tell me how can i copy data in LINUX Machine to windows XP Thanks, Sandeep (2 Replies)
Discussion started by: bsandeep_80
2 Replies

2. UNIX for Dummies Questions & Answers

Copy file from Remote Unix box to windows machine

Hi I need to copy a file from the remote unix server to windows machine. I read lot of thrad but didn't worked out. Requesting all to please help. (2 Replies)
Discussion started by: sameerspice
2 Replies

3. Solaris

Best possible communication mechanism between a Solaris machine and a windows machine

hi, I have some windows client machines which require a signal to be sent by a Solaris machine( SunOS 5.6) when ever a particular event occurs on that Solaris machine. What are possible communication mechanisms by which i can do this. the constraints are > the windows machines have to... (7 Replies)
Discussion started by: Krsh
7 Replies

4. Shell Programming and Scripting

SSH into a linux machine from a windows machine

I basically want to login into different linux machines( on the same network) from a windows machine. I know i can use ssh <machine name>. But i want to automate this process. I dont want to enter the username and password. Is there any way to do it. Can i make some sort of a batch script for it. (4 Replies)
Discussion started by: lassimanji
4 Replies

5. Red Hat

To find the LATEST file from a dir on REMOTE machine and SCP to local machine?

Hi All, URGENT - Please help me form a scipt for this: I need the LATEST file from a dir on REMOTE machine to be SCP'd to a dir on local machine. (and I need to execute this from local server) I know that the below cmd is used to find the LATEST file from a dir. But this command is not... (3 Replies)
Discussion started by: me_ub
3 Replies

6. UNIX for Dummies Questions & Answers

Cross complie linux make files onto a windows 7 machine using PGI Cygwin

Hello, I am very unfamiliar with linux/unix (don't even know the difference), but am trying to get some linux software to run on my Windows machine for my research. I have the makefiles for the software, and it is designed to be compiled in the PGI complier, which I also have. When i... (6 Replies)
Discussion started by: roba87
6 Replies

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

8. Shell Programming and Scripting

Running remote system shell script and c binary file from windows machine using java

Hi, I have an shell script program in a remote linux machine which will do some specific monitoring functionality. Also, have some C executables in that machine. From a windows machine, I want to run the shell script program (If possible using java). I tried with SSH for this. but, in... (1 Reply)
Discussion started by: ram.sj
1 Replies

9. Solaris

how to execute shell script present in unix machine remotely from windows

how to execute shell script present in unix machine remotely from windows? I having a shell script in my unix machine, need to execute the script remotely from my windows machine using Visual Basic or VBA macros. Thanks In Advance. --Suresh (1 Reply)
Discussion started by: sureshmani
1 Replies

10. UNIX for Dummies Questions & Answers

Copy files from Linux server local windows machine using a shell script

Hello, I need to create a shell script which will copy files - which are created on particular date and starting with particular name - to local windows XP machine. Is this possible.? Currently it is being done manually using winscp (1 Reply)
Discussion started by: NarayanaPrakash
1 Replies
Expect(3pm)						User Contributed Perl Documentation					       Expect(3pm)

NAME
Net::SCP::Expect - Wrapper for scp that allows passwords via Expect. SYNOPSIS
Example 1 - uses login method, longhand scp: my $scpe = Net::SCP::Expect->new; $scpe->login('user name', 'password'); $scpe->scp('file','host:/some/dir'); Example 2 - uses constructor, shorthand scp: my $scpe = Net::SCP::Expect->new(host=>'host', user=>'user', password=>'xxxx'); $scpe->scp('file','/some/dir'); # 'file' copied to 'host' at '/some/dir' Example 3 - copying from remote machine to local host my $scpe = Net::SCP::Expect->new(user=>'user',password=>'xxxx'); $scpe->scp('host:/some/dir/filename','newfilename'); Example 4 - uses login method, longhand scp, IPv6 compatible: my $scpe = Net::SCP::Expect->new; $scpe->login('user name', 'password'); $scpe->scp('file','[ipv6-host]:/some/dir'); # <-- Important: scp() with explicit IPv6 host in to or from address must use square brackets See the scp() method for more information on valid syntax. PREREQUISITES
Expect 1.14. May work with earlier versions, but was tested with 1.14 (and now 1.15) only. Term::ReadPassword 0.01 is required if you want to execute the interactive test script. DESCRIPTION
This module is simply a wrapper around the scp call. The primary difference between this module and Net::SCP is that you may send a password programmatically, instead of being forced to deal with interactive sessions. USAGE
Net::SCP::Expect->new(option=>val, ...) Creates a new object and optionally takes a series of options (see "OPTIONS" below). All "OBJECT METHODS" apply to this constructor. OBJECT METHODS
auto_yes Set this to 1 if you want to automatically pass a 'yes' string to any yes or no questions that you may encounter before actually being asked for a password, e.g. "Are you sure you want to continue connecting (yes/no)?" for first time connections, etc. error_handler(sub ref) This sets up an error handler to catch any problems with a call to 'scp()'. If you do not define an error handler, then a simple 'croak()' call will occur, with the last line sent to the terminal added as part of the error message. The method will immediately return with a void value after your error handler has been called. host(host) Sets the host for the current object login(login, password) If the login and password are not passed as options to the constructor, they must be passed with this method (or set individually - see 'user' and 'password' methods). If they were already set, this method will overwrite them with the new values. Password will not be changed if only one argument is passed (user). password(password) Sets the password for the current user, or the passphrase for the identify file if identity_file option is specified in the constructor user(user) Sets the user for the current object scp() Copies the file from source to destination. If no host is specified, you will be using 'scp' as an expensive form of 'cp'. There are several valid ways to use this method Local to Remote scp(source, user@host:destination); scp(source, user@[ipv6-host]:destination); # Same as previous, with IPv6 host scp(source, host:destination); # User already defined scp(source, [ipv6-host]:destination); # Same as previous, with IPv6 host scp(source, :destination); # User and host already defined scp(source, destination); # Same as previous scp(source); # Same as previous; destination will use base name of source Remote to Local scp(user@host:source, destination); scp(user@[ipv6-host]:source, destination); # Same as previous, with IPv6 host scp(host:source, destination); scp([ipv6-host]:source, destination); # Same as previous, with IPv6 host scp(:source, destination); OPTIONS
auto_quote - Auto-encapsulate all option values and scp from/to arguments in single-quotes to insure that special characters, such as spaces in file names, do not cause inadvertant shell exceptions. Default is enabled. Note: Be aware that this feature may break backward compatibility with scripts that manually quoted input arguments to work around unquoted argument limitations in 0.12 or earlier of this module; in such cases, try disabling it or update your script to take advantage of the auto_quote feature. auto_yes - Set this to 1 if you want to automatically pass a 'yes' string to any yes or no questions that you may encounter before actually being asked for a password, e.g. "Are you sure you want to continue connecting (yes/no)?" for first time connections, etc. cipher - Selects the cipher to use for encrypting the data transfer. compress - Compression enable. Passes the -C flag to ssh(1) to enable compression. force_ipv4 - Forces scp to use IPv4 addresses only. force_ipv6 - Forces scp to use IPv6 addresses only. host - Specify the host name. This is now useful for both local-to-remote and remote-to-local transfers. For IPv6 addresses, either regular or square-bracket encapsulated host are allowed (since command-line scp normally expects IPv6 addresses to be encapsulated in square brackets). identity_file - Specify the identify file to use. no_check - Set this to 1 if you want to turn off error checking. Use this if you're absolutely positive you won't encounter any errors and you want to speed up your scp calls - up to 2 seconds per call (based on the defaults). option - Specify options from the config file. This is the equivalent of -o. password - The password for the given login. If not specified, then identity_file must be specified or an error will occur on login. If both identity_file and password are specified, the password will be treated as the passphrase for the identity file. port - Use the specified port. preserve - Preserves modification times, access times, and modes from the original file. protocol - Specify the ssh protocol to use for scp. The default is undef, which simply means scp will use whatever it normally would use. recursive - Set to 1 if you want to recursively copy entire directories. scp_path - The path for the scp binary to use, i.e.: /usr/bin/scp, defaults to use the first scp on your $PATH variable. subsystem - Specify a subsystem to invoke on the remote system. This option is only valid with ssh2 and openssh afaik. terminator - Set the string terminator that is attached to the end of the password. The default is a newline. timeout - Sets the timeout value for your scp operation. The default is 10 seconds. timeout_auto - Sets the timeout for the 'auto_yes' option. I separated this from the standard timeout because generally you won't need nearly as much time as you would for a standard timeout, otherwise your script will drag considerably. The default is 1 second (which should be plenty). timeout_err - Sets the timeout for the additional error checking that the module does. Because errors come back almost instantaneously, I thought it best to make this a separate option for the same reasons as the 'timeout_auto' option above. The default is 'undef'. Setting it to any integer value means that your program will exit after that many seconds *whether or not the operation has completed*. Caveat programmor. user - The login name you wish to use. verbose - Set to 1 if you want verbose output sent to STDOUT. Note that this disables some error checking (ala no_check) because the verbose output could otherwise be picked up by expect itself. NOTES
The -q option (disable progress meter) is automatically passed to scp. The -B option may NOT be set. If you don't plan to send passwords or use identity files (with passphrases), consider using Net::SCP instead. In the event a new version of Net::SSH::Perl is released that supports scp, I recommend using that instead. Why? First, it should be a more secure way to perform scp. Second, this module is not the fastest, even with error checking turned off. Both reasons have to do with TTY interaction. Also, please see the Net::SFTP module from Dave Rolsky. If this suits your needs, use it instead. FUTURE PLANS
There are a few options I haven't implemented. If you *really* want to see them added, let me know and I'll see what I can do. Add exception handling tests to the interactive test suite. KNOWN ISSUES
At least one user has reported warnings related to POD parsing with Perl 5.00503. These can be safely ignored. They do not appear in Perl 5.6 or later. Probably not thread safe. See RT bug #7567 from Adam Ruck. THANKS
Thanks to Roland Giersig (and Austin Schutz) for the Expect module. Very handy. Thanks also go out to all those who have submitted bug reports and/or patches. See the CHANGES file for specifics. LICENSE
Net::SCP::Expect is licensed under the same terms as Perl itself. COPYRIGHT
2005-2008 Eric Rybski <rybskej@yahoo.com>, 2003-2004 Daniel J. Berger. CURRENT AUTHOR AND MAINTAINER
Eric Rybski <rybskej@yahoo.com>. Please send all module inquries to me. ORIGINAL AUTHOR
Daniel Berger djberg96 at yahoo dot com imperator on IRC SEE ALSO
Net::SCP, Net::SFTP, Net::SSH::Perl, Net::SSH2 perl v5.10.0 2009-02-06 Expect(3pm)
All times are GMT -4. The time now is 09:16 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy