Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SFTP in Batch!!! Can Anyone Help 1

Status
Not open for further replies.

ejaggers

Programmer
Feb 26, 2005
148
US
How do you use sftp in batch? It keeps prompting for password, but I need to run it in the cron.
Can Anyone Help!!!
 
Preshare the public key and use [tt]scp[/tt]. Much easier to use in a [tt]cron[/tt] job.


 
I've never used scp, can you give me a sample script?
 
Thanks KenCunningham, the scp appears to be pretty slick. However, I need to get files, not put files. Is there something similar? I have a new RHEL 5.3 box, and FTP is not working correctly. It only gets small files. I've been told our apps vendor that FTP is not running, but /usr/kerberos/bin/ftp is running. Maybe I need /usr/bin/ftp to run instead. I'm not sure how to do that.
 
Is /usr/bin in your $PATH? If so, you should be able to run it directly (assuming /usr/kerberos/bin) isn't before it in the $PATH variable.

Some days are diamonds, some days are rocks - make sure most are the former.
 
/usr/kerberos/bin is before /usr/bin. I don't know what /usr/kerberos/bin is. I tried /usr/bin/ftp to get a large file but it just sits there until you kill it. This is really my problem. sftp will get large files, but neither of the FTP's will, for some reason. They will get a small file though.
 
scp and sftp are exactly the same (run on the same protocol, port) but sftp has a cobbled together interactive command line to act similarily to ftp. ftp and sftp have nothing in common.

If sftp can get it, scp can get it.

As far as ftp sitting there, that indicates the data port of ftp being blocked. If you use a passive ftp client it will probably work. (if the file is small, I believe ftp sends it on the command port, and that is why it works).

Don't know the diff between kerberos ftp and not.

getting and putting on scp is the same:

if you have the same username on both machines, you can omit the name part:

scp USERNAME@HOSTNAME:pATH

so to get data.txt from subdir x with username john on hostname host.mydomain.com and put it in the current directory:

scp john@host.mydomain.com:x/data.txt .
 
Need help setting up ssh-keygen -t rsa:

logged on as informix
pentapp2/usr/bin>ssh-keygen -t rsa

Generating public/private rsa key pair.
Enter file in which to save the key (/home/informix/.ssh/id_rsa): Enter passphrase (empty for no passphrase): **I HIT ENTER**
Enter same passphrase again: **I HIT ENTER**
Your identification has been saved in /home/informix/.ssh/id_rsa.
Your public key has been saved in /home/informix/.ssh/id_rsa.pub.
The key fingerprint is: ***IT GAVE ME THE STUFF***

It created dir .ssh with the following:
rw------- 1 informix informix 1675 Apr 24 13:18 id_rsa
rw-r--r-- 1 informix informix 409 Apr 24 13:18 id_rsa.pub
rw-r--r-- 1 informix informix 993 Apr 15 11:58 known_hosts

I copied id_rsa.pub to unix@/usr/user/informix/.ssh

From the Linux box I did>
pentapp2/home/informix>scp informix@unixbox:/usr/users/informix/dbexport.out

BUT it prompted for pw plus it would not get the file.

informix@unixbox's password:
Permission denied, please try again.
scp: warning: Executing scp1.
scp: FATAL: Executing ssh1 in compatibility mode failed (Check that scp1 is in your PATH).
pentapp2/home/informix>
 
You're doing it backwards.

First delete the id_rsa.pub files on both machines. That doesn't get copied and will just mess things up.

Go to the machine you want to run your cron job from, I assume the linux box. Do these commands there...
Code:
# Get to the correct directory (create it if needed)
cd
cd .ssh

# Just hit return for all prompts on the following command
ssh-keygen -t rsa

# Append our public key to the other machine's authorized_keys file
# We WILL be prompted for a password on this command
cat id_rsa.pub | ssh informix@unixbox "cat - >> .ssh/authorized_keys"

# From this point on, we should be able to scp files to and from the informix account on unixbox without a password


 
Here's what I got:
Unix box:
/usr/users/informix/.ssh>ls -l
-rw-r--r-- 1 informix informix 409 Apr 24 14:34 authorized_keys
/usr/users/informix/.ssh>

Linux Box:
pentapp2/home/informix/.ssh>ls -l
-rw------- 1 informix informix 1675 Apr 24 14:28 id_rsa
-rw-r--r-- 1 informix informix 409 Apr 24 14:28 id_rsa.pub
-rw-r--r-- 1 informix informix 600 Apr 24 14:30 known_hosts

pentapp2/home/informix/.ssh>scp informix@unixbox:/dbexport.out .
informix@unix's password:
scp: warning: Executing scp1.
scp: FATAL: Executing ssh1 in compatibility mode failed (Check that scp1 is in your PATH).
pentapp2/home/informix/.ssh>

# This Step Did Create The File On Unixbox from Linux, so maybe I just don't know how to get a file from unixbox
cat id_rsa.pub | ssh informix@unixbox "cat - >> .ssh/authorized_keys"

 
Two things...

Your machine is trying to use the SSH-1 protocol. This is the older less secure version. It should be using SSH-2. This could be either a configuration problem or you have an old version of OpenSSH. Try adding "-2" to the command line. This will force it to use protocol 2 (if you have the right version).

Second thing, is your file you're trying to get really in the root directory of "unixbox"?

Code:
scp [b]-2[/b] informix@unixbox:/dbexport.out .


 
I've been out all week, but I'm back and still cannot get scp to work.

SamBones, the file I'm trying to get is: informix@unixbox /usr/users/informix/dbexport.out

And wanting it on: informix@linuxbox /home/informix/.

So from the linuxbox I did:

pentapp2/home/informix>scp -2 informix@unixboxIPaddress /usr/users/informix/dbexport.out .

cp: cannot stat `informix@ww.xx.yy.zz': No such file or directory
cp: cannot stat `/usr/users/informix/dbexport.out': No such file or directory
pentapp2/home/informix>


What am I doing wrong???


 
Taking baby steps:
1) First of all I left out a ':'
2) try putting a file 'test' first

pentapp2/home/informix>scp /home/informix/test informix@ww.xx.yy.zz:/usr/users/informix
informix@ww.xx.yy.zz's password:
scp: warning: Executing scp1.
scp: FATAL: Executing ssh1 in compatibility mode failed (Check that scp1 is in your PATH).
lost connection

pentapp2/home/informix> which scp1 ***DID NOT FIND IT***
pentapp2/home/informix> find / -name 'scp1' ***DID NOT FIND IT***
 
The command line option "-2" is to get past the whole "scp1" thing. You need to add that back to your command line.


 
SamBones, Yeah I tried that too:

pentapp2/home/informix>scp -2 test informix@ww.xx.yy.zz:/usr/users/informix
informix@ww.xx.yy.zz's password:
scp: warning: Executing scp1.
scp: FATAL: Executing ssh1 in compatibility mode failed (Check that scp1 is in your PATH).
lost connection
pentapp2/home/informix>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top