Automated SCP script passing password to preserve source file timestamp


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users Automated SCP script passing password to preserve source file timestamp
# 1  
Old 07-25-2010
Question Automated SCP script passing password to preserve source file timestamp

Hi

My requirement is i want to copy files from remote server to the local server and also i need to preserve the timestamp of the remote file.

By using scp -p , it is working fine in the interactive call but it is not preserving he file timestamp when i use it in the non interactive scp call that is using shell script.

Also, i need to password for scp and for that reason i'm using except.

Interactive Call
Code:
scp -p remote_server:file local_directory  #This is working fine

Non Interactive call through shell script ( This copies the file from the remote server but doesn't preserve the timestamp.

Code:
#!/bin/ksh
#!/usr/bin
#!/usr/bin/expect --
expect -f -<<EOF
spawn -noecho scp -p remote_server:file local_directory
expect "Password:"
send "$$$$$$$"
expect "\n"
EOF

I don't understand why the "-p" option ignored in the non interactive call.

Please help

Last edited by Scott; 08-02-2010 at 02:05 PM.. Reason: Added code tags
# 2  
Old 07-25-2010
Ugh...

That you're having to shoehorn a stored plaintext password into scp's otherwise secure authentication system with expect is a subtle hint, writ in mile-high flashing neon letters: You're not supposed to do this. It's designed to stop you doing this for security reasons, use pre-shared keys instead -- it's what they're there for. There's instructions for it plastered all over the internet. They do exactly what you want except they don't have the security problems of storing a plaintext password, and don't have the poor reliability and extra wait and extra software requirements of an interactive input manually brute-forced with expect.

Testing it here, copying from a remote host with scp -p does indeed preserve the timestamp, and without a password given pre-shared keys, and definitely non-interactively, deprived of any sort of terminal. I'd expect it to be an expect weirdness, or perhaps an odd version of ssh.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Preserve destination timestamp while copying

Hi Guys, I am trying to copy a file from source to destination, I need to preseve timestamp of destination cd desitnation ll file.txt Aug 17 17:22 file.txt cp -p source/file.txt destination/ I need to preseve same timestamp after copying cd desitnation ll file.txt Aug 17... (9 Replies)
Discussion started by: rohit_shinez
9 Replies

2. Shell Programming and Scripting

SFTP or scp with password in a batch script without using SSH keys and expect script

Dear All, I have a requirement where I have to SFTP or SCP a file in a batch script. Unfortunately, the destination server setup is such that it doesn't allow for shell command line login. So, I am not able to set up SSH keys. My source server is having issues with Expect. So, unable to use... (5 Replies)
Discussion started by: ss112233
5 Replies

3. Shell Programming and Scripting

Script should wait for password while doing scp

Hi team, need help on this :- trying to scp a file from A ( it could any server among hundreds not one) server to B server ( fixed ) . The script runs in a third server CFGEngine server. a. we dont use static password ( its pin + rsa token) so , "here documents" kind of thing is not... (3 Replies)
Discussion started by: gauravsharma29
3 Replies

4. Shell Programming and Scripting

Automated FTP without plaintext user/password in script

hi , i am a still beginner in unix and specially in ftp i've written this script but my admin asked me that he don't want to see in my ftp neither user neither password , so i've created .netrc file where in it i've put machine name , user and pass but still included in my script , so if someone... (19 Replies)
Discussion started by: semaan
19 Replies

5. Shell Programming and Scripting

Automated SCP from a job?

Hi all - I have a script which runs on the OS level, but refuses to run as a cron or as an Oracle job. The Script is pretty straight forward: #!/bin/bash username="MyUsername" host="Remote.server" path="Remote.directory/files/*.*" password="MyPassword" expect -c " spawn /usr/bin/scp... (3 Replies)
Discussion started by: danimaltex
3 Replies

6. UNIX for Advanced & Expert Users

How to copy a file from remote server and preserve timestamp

Hi How to copy a file from remote server and preserve timestamp. Please not, i have to pass username and password to connect to the remote server in the shell script. Can this be achieved with simple ftp ? are there any options in ftp ? Thanks (4 Replies)
Discussion started by: skumar75
4 Replies

7. Shell Programming and Scripting

Passing Password into scp Command

Hi Everyone, I'm trying to run scp as a one-line command, as of right now, it prompts me for the user's password to the remote machine. Does anyone know if there is an option to pass the password parameter into the scp command on the same line so it doesn't prompt me? Thanks! (1 Reply)
Discussion started by: twhitmarsh
1 Replies

8. Shell Programming and Scripting

preserve timestamp of symlinks using rsync

Hi, In my shell programming, When i copy sym links from one server to another server using rsync it does not preserve time stamp . it showing current time after copying in destination server.the command i used is rsync -vaR -- How can i preserve sym links time stamp using rsync. Thanx (1 Reply)
Discussion started by: KiranKumarKarre
1 Replies

9. UNIX for Advanced & Expert Users

scp automated script

Hi Unix gurus, I am trying to create a script to automate the copying of files daily from one server to another using the scp command. --> #!/bin/ksh KEY="$HOME/.ssh/SSHKEY" if ;then echo "Private key not found at $KEY" >> $LOGFILE echo "* Please create it with \"ssh-keygen -t dsa\" *"... (5 Replies)
Discussion started by: gholdbhurg
5 Replies

10. UNIX for Dummies Questions & Answers

ftp copy: preserve source file date stamp

Is there any way to preserve a file's create/mod date stamp when it is "put" via ftp (or even using Fetch) to a Win2K server and a SunOS 5.8 server? For example, if I copy a file with a create/mod date of "01/15/2005 3:36 PM" to my Win2K or SunOS ftp server, the date stamp will change to the... (5 Replies)
Discussion started by: cassj
5 Replies
Login or Register to Ask a Question