The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Advanced & Expert Users
.
google unix.com



UNIX for Advanced & Expert Users Expert-to-Expert. Learn advanced UNIX, UNIX commands, Linux, Operating Systems, System Administration, Programming, Shell, Shell Scripts, Solaris, Linux, HP-UX, AIX, OS X, BSD.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Automated SFTP script aggar_y Shell Programming and Scripting 6 08-05-2008 03:39 PM
automated sftp script klindel Shell Programming and Scripting 2 05-13-2008 02:45 AM
Need automated shell script please uneex Shell Programming and Scripting 2 05-02-2008 09:36 AM
Need help for automated shell script uneex Shell Programming and Scripting 4 05-01-2008 01:15 PM
help for automated script splax UNIX for Advanced & Expert Users 4 12-26-2006 05:36 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 10-08-2007
gholdbhurg gholdbhurg is offline
Registered User
  
 

Join Date: Oct 2007
Posts: 26
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 [ ! -f $KEY ];then
echo "Private key not found at $KEY" >> $LOGFILE
echo "* Please create it with \"ssh-keygen -t dsa\" *" >> $LOGFILE
exit
else
echo "Transferring files.." >> $LOGFILE
echo "scp -v -i $KEY $FILES $SCP_LOGIN@$SCP_MACHINE:$SCP_PATH" >> $LOGFILE
scp -v -i $KEY $FILES $SCP_LOGIN@$SCP_MACHINE:$SCP_PATH >> $LOGFILE
echo "Copy files successful.." >> $LOGFILE
fi

My questions are below:
1. Whenever I ran this script, it no longer ask for password but it still prompts the "Are you sure you want to continue connecting (yes/no)?" question:
See details below:
-->
Putting your key on remote server
Transferring files..
The authenticity of host '10.68.169.168 (10.68.169.168)' can't be established.
RSA key fingerprint is cd:78:a1:fe:2d:8d:aa:0f:32:be:18:5b:74:0e:3a:c1.
Are you sure you want to continue connecting (yes/no)? yes
Failed to add the host to the list of known hosts (/shared/home/ngtman/.ssh/known_hosts).

Can I also automate it in a way that it always answers yes to the above question w/o me typing anymore?

2. How can i display the error messages of the scp in the $LOGFILE for cases that scp was not successful for some files?
i.e. there are space issue with the remote server, connection time out, or permission issues. I just want to see in the log what happened to
the scp so as it would also be better for the support guys to check as in case anything happens.

I tried both redirecting using >> and using the tee command but both not writing to the logfile, only displaying the status in the prompt.

Hoping to hear from you guys.

Thanks in advance.
  #2 (permalink)  
Old 06-25-2008
nareshkumar2705 nareshkumar2705 is offline
Registered User
  
 

Join Date: Jun 2008
Posts: 1
scp

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 [ ! -f $KEY ];then
echo "Private key not found at $KEY" >> $LOGFILE
echo "* Please create it with \"ssh-keygen -t dsa\" *" >> $LOGFILE
exit
else
echo "Transferring files.." >> $LOGFILE
echo "scp -v -i $KEY $FILES $SCP_LOGIN@$SCP_MACHINE:$SCP_PATH" >> $LOGFILE
scp -v -i $KEY $FILES $SCP_LOGIN@$SCP_MACHINE:$SCP_PATH >> $LOGFILE
echo "Copy files successful.." >> $LOGFILE
fi

My questions are below:
1. Whenever I ran this script, it no longer ask for password but it still prompts the "Are you sure you want to continue connecting (yes/no)?" question:
See details below:
-->
Putting your key on remote server
Transferring files..
The authenticity of host '10.68.169.168 (10.68.169.168)' can't be established.
RSA key fingerprint is cd:78:a1:fe:2d:8d:aa:0f:32:be:18:5b:74:0e:3a:c1.
Are you sure you want to continue connecting (yes/no)? yes
Failed to add the host to the list of known hosts (/shared/home/ngtman/.ssh/known_hosts).

Can I also automate it in a way that it always answers yes to the above question w/o me typing anymore?

2. How can i display the error messages of the scp in the $LOGFILE for cases that scp was not successful for some files?
i.e. there are space issue with the remote server, connection time out, or permission issues. I just want to see in the log what happened to
the scp so as it would also be better for the support guys to check as in case anything happens.

I tried both redirecting using >> and using the tee command but both not writing to the logfile, only displaying the status in the prompt.

Hoping to hear from you guys.

Thanks in advance.


Hi gholdbhurg,

I am also facing the same situation now.

So, please let me know what solution you used to resolve this problem.

Please send me the details to nareshkumar.gandham@hcl.in

Thanks inadvance for your help.
  #3 (permalink)  
Old 06-25-2008
kknigga kknigga is offline
Registered User
  
 

Join Date: Nov 2007
Posts: 18
I think the big question here is why can't ssh write to ~/.ssh/known_hosts?

If it could, it would cache that fingerprint and stop asking.
  #4 (permalink)  
Old 06-25-2008
prash184u prash184u is offline
Registered User
  
 

Join Date: Dec 2007
Posts: 23
Procedure

I've tried this and worked great without any prompts ...

it will still give you the warning message but wont ask anything ...

if you have access to both the servers and if u know the username on both the servers try this procedure

Source -- Howto Linux / UNIX setup SSH with DSA public key authentication (password less login)

(1)
System from where you will run the script

bash-3.00$ ssh-keygen -t dsa
Generating public/private dsa key pair.
Enter file in which to save the key (/home/user/.ssh/id_dsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/user/.ssh/id_dsa.
Your public key has been saved in /home/user/.ssh/id_dsa.pub.
The key fingerprint is:
somenumbers user@server


(2)


Copy id_dsa.pub to the other system at the location as

~/home/.ssh/authorized_keys
chmod 600 ~/.ssh/authorized_keys

(3)

Run this command on remote system

exec /usr/bin/ssh-agent $SHELL
Ssh-add


Then ,

you may cron the SCP script

use scp command as
"scp -o Port=22 (or wtever) source dest "
source could be /home/blah.txt
dest could be username@remote_Server:/home/asd

it worked great for me ...

Good Luck
  #5 (permalink)  
Old 06-26-2008
tekjunky tekjunky is offline
Registered User
  
 

Join Date: Sep 2002
Posts: 9
Quote:
Failed to add the host to the list of known hosts (/shared/home/ngtman/.ssh/known_hosts)
I agree with kknigga...

The thing to look at is the permissions on the .ssh directory and the known_hosts file. Try a simple test like:

(as ngtman)

echo "test" >> ~/.ssh/known_hosts

Now edit that file and see if the word "test" is at the end of the file.

If it is your permissions are fine, remove the "test" line and save the file again.

If it isn't you have a permissions issue.
  #6 (permalink)  
Old 10-27-2008
dan-e's Avatar
dan-e dan-e is offline
Registered User
  
 

Join Date: Oct 2008
Location: Brisbane, Australia
Posts: 28
Quote:
Originally Posted by tekjunky View Post

If it is your permissions are fine, remove the "test" line and save the file again.

If it isn't you have a permissions issue.
... or a disk-space or disk usage quota issue in your .ssh directory. This prevents ssh from appending onto known_hosts, and (naturally) it will fail utterly silently.

Why someone didn't build a disk-space / quota space hard error message into the kernel I have no idea. This has cost me more time than any other problem with 'nix, since diskspace problems cross into almost every functional border in unix and, well, *any* static os.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 09:40 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0