Operating System - HP-UX
1837650 Members
2876 Online
110117 Solutions
New Discussion

any insight into SCP question??

 
SOLVED
Go to solution
rmueller58
Valued Contributor

any insight into SCP question??

All,

I have an expect script that I have that uses
scp to move files from one server to another, it is a transactional thing that I put in cron to run every 15 minutes.. I am getting a message in the mailbox:

CRONTAB LINE:
1,14,30,45 * * * * /usr/local/bin/apphire.sh

MAIL MESSAGE:
spawn /usr/local/bin/scp /tmp/*apphire.txt root@205.202.254.91:/tmp
Executing ssh2 failed. Command:' ssh2 -l root -x -a -o passwordprompt %U@%H's password: -o nodelay yes -o authenticationnotify yes -s sftp' System error message:
'No such file or directory'
send: spawn id exp3 not open
while executing
"send "PASSWORD\r""
(file "/usr/local/bin/appput.exp" line 4)

I can run it manually without error.

APPPUT.EXP
# cat appput.exp
###############################################
#!/usr/local/bin/expect
spawn /usr/local/bin/scp /tmp/*apphire.txt user@:/tmp
expect "user@'s password:"
send "PASSWORD\r"
expect "debug: uninitializing event loop"
send "\r"
###############################################
THIS IS THE SCRIPT THAT INITIATES THE PROCESS
NOTE /usr/local/bin/appput.exp Initiate at the end of the script..
APPHIRE.SH
###############################################
# cat apphire.sh
#!/bin/sh
for dst in `cat /pei/peitools/bin/distid.txt`
do
echo $dst
export D="$dst"
export INFORMIXSERVER=pei

sed s/DIST/"$D"/g /usr/local/bin/apphire.template > /tmp/"$D"apphire.sql
sudo -u support /usr/informix/bin/isql "$D"plus < /tmp/"$D"apphire.sql
done
/usr/local/bin/appput.exp



How would I assure myself the file transfer is completing correctly? Again I can run the file manually and get the following output:

# apphire.sh
arl

0 row(s) unloaded.


blr

0 row(s) unloaded.


con

0 row(s) unloaded.


elk

0 row(s) unloaded.


esu

0 row(s) unloaded.


ftc

0 row(s) unloaded.


grt

0 row(s) unloaded.


mps

12 row(s) unloaded.

plk

0 row(s) unloaded.

plv

61 row(s) unloaded.

raa

0 row(s) unloaded.

raf

0 row(s) unloaded.

ral

0 row(s) unloaded.

val

0 row(s) unloaded.

wat

0 row(s) unloaded.

wsf

0 row(s) unloaded.

wst

0 row(s) unloaded.

spawn /usr/local/bin/scp /tmp/*apphire.txt user@:/tmp
user@'s password:
arlapphire.txt | 0B | 0.0 kB/s | TOC: 00:00:01 | 100%
blrapphire.txt | 0B | 0.0 kB/s | TOC: 00:00:01 | 100%
conapphire.txt | 0B | 0.0 kB/s | TOC: 00:00:01 | 100%
elkapphire.txt | 0B | 0.0 kB/s | TOC: 00:00:01 | 100%
esuapphire.txt | 0B | 0.0 kB/s | TOC: 00:00:01 | 100%
ftcapphire.txt | 0B | 0.0 kB/s | TOC: 00:00:01 | 100%
grtapphire.txt | 0B | 0.0 kB/s | TOC: 00:00:01 | 100%
mpsapphire.txt | 336B | 0.3 kB/s | TOC: 00:00:01 | 100%
plkapphire.txt | 0B | 0.0 kB/s | TOC: 00:00:01 | 100%
plvapphire.txt | 1.4kB | 1.4 kB/s | TOC: 00:00:01 | 100%
raaapphire.txt | 0B | 0.0 kB/s | TOC: 00:00:01 | 100%
rafapphire.txt | 0B | 0.0 kB/s | TOC: 00:00:01 | 100%
ralapphire.txt | 0B | 0.0 kB/s | TOC: 00:00:01 | 100%
valapphire.txt | 0B | 0.0 kB/s | TOC: 00:00:01 | 100%
watapphire.txt | 0B | 0.0 kB/s | TOC: 00:00:01 | 100%
wsfapphire.txt | 0B | 0.0 kB/s | TOC: 00:00:01 | 100%
wstapphire.txt | 0B | 0.0 kB/s | TOC: 00:00:01 | 100%
send: spawn id exp4 not open
while executing
"send "\r"
"
(file "/usr/local/bin/appput.exp" line 6)

Any insights appreciated..

Rex Mueller - Educational Service Unit #3
21 REPLIES 21
Arunvijai_4
Honored Contributor
Solution

Re: any insight into SCP question??

Hi Rex,

Two things,

You can't set any ENV variables inside cron. I think, you have some ENV that causes the execution success when you run from Shell. Check that out.

Also, make sure you use SecureShell from HP which can be downloaded from,

http://h20293.www2.hp.com/portal/swdepot/displayProductInfo.do?productNumber=T1471AA

-Arun
"A ship in the harbor is safe, but that is not what ships are built for"
rmueller58
Valued Contributor

Re: any insight into SCP question??

I have the full path in the scripts that are running..

running SSH Secure Shell 2.3.0 (non-commercial version) on hppa2.0w-hp-hpux11.00


Arunvijai_4
Honored Contributor

Re: any insight into SCP question??

Hi Rex,

Full path is alright, how abt the ENV variables ? Did you check your shell for any special variables ?

-Arun
"A ship in the harbor is safe, but that is not what ships are built for"
rmueller58
Valued Contributor

Re: any insight into SCP question??

I should be able to define the ENV from within the running script?

Arunvijai_4
Honored Contributor

Re: any insight into SCP question??

Hi Rex,

Yes, you can do it within any script, but when it runs from cron, it wont take any of these ENV variables.

-Arun
"A ship in the harbor is safe, but that is not what ships are built for"
rmueller58
Valued Contributor

Re: any insight into SCP question??

I don't think the problem is with an environmental variable. As it passes correctly..

the mail message is different today.. Not sure what changed. but I don't get the same error ..
I need to look closer at it.
Doug O'Leary
Honored Contributor

Re: any insight into SCP question??

Hey;

It seems the OP already understand this, but just to make sure it's clear: You certainly can (and usually must) set environment variables in scripts run via cron. The scripts run via cron start out with a very limited envrionment; however, there is absolutely nothing preventing the script author from updating that environment from within the script.

How do you think Oracle scripts work from cron without that ability?

Doug

------
Senior UNIX Admin
O'Leary Computers Inc
linkedin: http://www.linkedin.com/dkoleary
Resume: http://www.olearycomputers.com/resume.html
blubrick
Occasional Advisor

Re: any insight into SCP question??

Rex,

I think you might want to fully path the "sudo" command in apphire.sh

cron runs its jobs with not only a very limited environment, but also with a very limited $PATH (something like /bin:/usr/bin IIRC - man crontab for details)

I can't tell, but I am assuming that your /tmp/"$D"apphire.sql scripts create /tmp/"$D"apphire.txt

If your apphire.sh script can't find sudo, it won't create /tmp/"$D"apphire.txt which looks to be the file that your "expect" script cannot find.

Good luck.

P.S. Have you looked into keybased authentication for the SCP transfers? That could radically simplify the script and allow you to remove the reliance on a hard-coded password. Just a thought.


Growing old is unavoidable, growing up is optional.
rmueller58
Valued Contributor

Re: any insight into SCP question??

blubrick,

I used an expect script but if I could figure out how to make the key/auth stuff work in the hand shake I agree it would eliminate the expect portion of the script.

Any insights appreciated on how to do that,

the primary "Source" is HP/UX 11.0 running
SSH Secure Shell 2.3.0 (non-commercial version) on hppa2.0w-hp-hpux11.00

The primary "Target" is Fedora FC4
OpenSSH_4.0p1, OpenSSL 0.9.7f 22 Mar 2005

I am open to suggestions on this..
Arunvijai_4
Honored Contributor

Re: any insight into SCP question??

Hi Rex,

What does the mail message say? Can you run SSH server in debug mode and verify what goes wrong ?

-Arun
"A ship in the harbor is safe, but that is not what ships are built for"
rmueller58
Valued Contributor

Re: any insight into SCP question??

Arun,

Sometimes it indicates it can't connect.. I know the connection exists..

Oops. Just thought of something, my backup timing. I just changed the cron job to remove any potential problems with conflicting with the Backup.

Rex
Arunvijai_4
Honored Contributor

Re: any insight into SCP question??

Hi Rex,

You said, I know the connection exists.. .. How did you make sure the connection exists? Also, did you run the SSH server in debug mode to make sure it connected.

What does your # crontab -l say ?

-Arun
"A ship in the harbor is safe, but that is not what ships are built for"
rmueller58
Valued Contributor

Re: any insight into SCP question??

I am going to watch it for 24 hours now I changed crontab

I would like to eliminate the expect script and use SSH auth/key exchange.. Just need to figure out how.
blubrick
Occasional Advisor

Re: any insight into SCP question??

Rex,

Try this site - http://mikeage.net/content/tips/linux/sshkeys.php

I'm not just brushing you off with an RTFM, the above site describes far better than I can, exactly how to set up key-based authentication for both Secure Shell SSH and OpenSSH.

Enjoy
Growing old is unavoidable, growing up is optional.
Muthukumar_5
Honored Contributor

Re: any insight into SCP question??

scp the best way is to use key sharing between machine. Check the return value of command like,

scp remotemachine:/location /source
echo $?

it gives successful of scp command.

--
Muthu
Easy to suggest when don't know about the problem!
Muthukumar_5
Honored Contributor

Re: any insight into SCP question??

when you are playing with cron tab the try to get log files as,

1,14,30,45 * * * * /usr/local/bin/apphire.sh 1>>/tmp/test.log 2>>/tmp/test.err

where,

you can output messages to /tmp/test.log and error to /tmp/test.err file.

Keep track on cron.log also.

--
Muthu
Easy to suggest when don't know about the problem!
Arunvijai_4
Honored Contributor

Re: any insight into SCP question??

Hi Rex,

Any updates on this ?

-Arun
"A ship in the harbor is safe, but that is not what ships are built for"
rmueller58
Valued Contributor

Re: any insight into SCP question??

Arun and blubrick,

I am looking into the key exchange process closer, I've got meetings all morning..

SOURCE:Current SSH on HP side
ssh: SSH Secure Shell 2.3.0 (non-commercial version) on hppa2.0w-hp-hpux11.00


DESTINATION: Current SSH on Linux Side
OpenSSH_4.0p1, OpenSSL 0.9.7f 22 Mar 2005

From Blubricks post I should be able to do the exchange via


1. Create SSH Keys ssh-keygen -t dsa mikeage.net
2. Tell SSH2 who it is (don't ask) echo "idkey id_dsa_1024_a" >> .ssh2/identification mikeage.net
3. Set permissions chmod 600 .ssh2/idkey id_dsa_1024_a.pub .ssh2/identification mikeage.net
4. Copy the public key to the OpenSSH machine scp .ssh/id_dsa_1024_a.pub breeze: mikeage.net
5. Convert the public key, and add it ssh-keygen -i -f id_dsa_1024_a.pub >> .ssh/authorized_keys2 breeze




Not sure, but I think I will have to update SSH on the HP/UX side, kind of leary about doing that as it appears I will have to do some additional patchs..

I will update issue Thursday AM.


Arunvijai_4
Honored Contributor

Re: any insight into SCP question??

Hi Rex,

Latest version of Secure shell from HP is, 4.20. You can download and install from,

http://h20293.www2.hp.com/portal/swdepot/displayProductInfo.do?productNumber=T1471AA

-Arun
"A ship in the harbor is safe, but that is not what ships are built for"
rmueller58
Valued Contributor

Re: any insight into SCP question??

Thanks Arun,

I had found it.. I am looking at the prequisites..
rmueller58
Valued Contributor

Re: any insight into SCP question??

Had to back burner this issue because of other duties.. Will get back to it again