SFTP Not Working With CRON


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users SFTP Not Working With CRON
# 1  
Old 01-16-2011
SFTP Not Working With CRON

Hello -
I have a production stream that is scheduled with cron to run each Monday morning. The jobs in the stream perform tasks including
FTP get, load to a DB table, and report processing.

About a month ago I was directed to begin using sftp in these jobs and since then the jobs scheduled with cron no longer work. Each fails when attempting to connect via sftp to the remote server. If I run the
job from the command line of the owning account it will work fine.

I believe that the problem basically is that the cron owner does not have the priviledges necessary to perform the sftp connect.

I have tried the following steps to get this to work:

1) Created a cron schedule file (prodid_crontab.txt) under the job owner's account (prodid).
2) Directed the cron daemon to use the prodid_crontab.txt schedule file by issuing the command:

crontab < prodid_crontab.txt

3) Tested this and verified that the cron is using prodid_crontab.txt

The job still failed to establish an sftp connection. So I tried granting execute on the prodid_crontab.txt file just to make sure, and the sftp job step continues to fail.

All replies are creatly appreciated.
Patrick
# 2  
Old 01-17-2011
maybe you start showing us how your crontab -l output looks like at the moment ?

Regards
zxmaus
# 3  
Old 01-17-2011
Did you use a passphrase when you generated the keys for the account that is running sftp?
# 4  
Old 01-17-2011
Remember, cron runs things with a very minimal PATH. You may want to use absolute paths for any executables you call, or set a better PATH yourself, or perhaps source /etc/profile
# 5  
Old 01-17-2011
Hi -

Thank you for the replies. I want to mention that I sudo'd to the job's home directory for everything that I've tried. I do not have the authority to login directly to the prodid account.

Here is my crontab schedule:
Code:
32 11 * * 1 /home/sadeadm/data/LMC/accept/WeeklyLabor/sql_loader/sftp_testing/sftp_testing.job abusmgt /appl/oracle1/product/10.2.0.4 /appl/oracle1

As it is set up, The sftp command does not currently require a passphrase. I don't have a good knowledge of how the server were modified to enable sftp.

I also tried using an absolute path (ie: crontab < /home/prodid/prodid_crontab.txt) but the sftp command is still unable to connect to the remote system when cron executes it.

Thanks,
Patrick
# 6  
Old 01-17-2011
Can we see the contents of /home/sadeadm/data/LMC/accept/WeeklyLabor/sql_loader/sftp_testing/sftp_testing.job? Also, are you asked for a password for the remote account when you run the command interactively?
# 7  
Old 01-19-2011
Sorry for the delay in my response. There was a amall typo in my last post so I'll recap where I'm at with this problem.

The account owning the sftp command is prodid. I sudo su - prodid to the prodid account to modify and execute scripts. In the directory /home/prodid I executed:

crontab < prodid_crontab.txt

And I verified that cron is using my schedule file (prodid_crontab.txt). Here is the prodid_crontab.txt file:

Code:
32 11 * * 1 /home/prodid/data/LMC/accept/WeeklyLabor/sql_loader/sftp_testing/sftp_testing.job abusmgt /appl/oracle1/product/10.2.0.4 /appl/oracle1
 
And here is the file sftp_testing.job that I want cron to execute:
 
#!/bin/sh
##########################################################################
##
## Declarations.
##
## HOMEDIR=/home/prodid/data/LMC/prod/WeeklyLabor
HOMEDIR=/home/prodid/data/LMC/accept/WeeklyLabor
DATADIR=${HOMEDIR}/sql_loader/sftp_testing/
LOGDIR=${DATADIR}/log_files
LOG=${LOGDIR}/sftp_testing.logfile
TODAY=`date "+DATE: %m/%d/%y TIME: %H:%M:%S %p"`
FILEDATE=`date "+%Y%m%d"`
DFILE=zc00799i_pch.out
##
## Process Passed-in Parameter Values
##
ORACLE_SID=$1
export ORACLE_SID
ORACLE_HOME=$2
export ORACLE_HOME
ORACLE_BASE=$3
export ORACLE_BASE
##
## Directory for sqlldr and sqlplus
##
BINDIR=${ORACLE_HOME}/bin
cd ${DATADIR}
echo SAP_NODE_FTP JOB STARTING.........
echo "SAP_NODE_FTP JOB STARTING........." > ${LOG}
if [ -f ${DFILE} ]
then
  rm ${DFILE}
fi
echo "ORACLE_SID:   " >> ${LOG}
echo ${ORACLE_SID} >> ${LOG}
echo "ORACLE_HOME:  " >> ${LOG}
echo ${ORACLE_HOME} >> ${LOG}
echo "ORACLE_BASE:  " >> ${LOG}
echo ${ORACLE_BASE} >> ${LOG}
echo " " >> ${LOG}
echo "#########" >> ${LOG}
echo "File ${DFILE} FTP Operation starting at: " >> ${LOG}
echo ${TODAY} >> ${LOG}
echo "#########" >> ${LOG}
echo " " >> ${LOG}
echo Files to be retrieved from Remote System: >> ${LOG}
echo ${DFILE} >> ${LOG}
echo Oracle Environment: >> ${LOG}
echo ${ORACLE_SID} >> ${LOG}
echo "Bin directory (BINDIR): " >> ${LOG}
echo ${BINDIR} >> ${LOG}
echo " " >> ${LOG}
##
## Connect to Source System and Retrieve PCNODE file.
HOST="sscprd.testing.com"
USER="ficoftp"
sftp ${USER}@${HOST} << EOF >> ${LOGDIR}/sftp_testing.logfile
  cd ../
  cd FTPOUT
  get ${DFILE}
  quit
EOF

echo " " >> ${LOG}
echo "#########" >> ${LOG}
echo FTP Operation Complete. File Listing: >> ${LOG}
echo "#########" >> ${LOG}
ls -lrt >> ${LOG}
echo " " >> ${LOG}
echo "###" >> ${LOG}
echo "Number of records in retrieved file: "`wc -l < ${DFILE}` >> ${LOG}
echo "###" >> ${LOG}
echo " " >> ${LOG}
echo " " >> ${LOG}
echo "#########" >> ${LOG}
TODAY=`date "+DATE: %m/%d/%y TIME: %H:%M:%S %p"`
echo ${TODAY} >> ${PAGERLOG}
echo "sftp_testing.JOB ending at: " >> ${LOG}
echo ${TODAY} >> ${LOG}
echo "#########" >> ${LOG}
cat ${LOG} > ${LOGDIR}/sftp_testing.shlog
mailx -s "sftp_testing Job: ${ORACLE_SID}" `cat ${HOMEDIR}/patrick_mail_list.txt` < ${LOGDIR}/sftp_testing.shlog
echo sftp_testing JOB COMPLETE.

Again, the problem is that the sftp command in the sftp_testing.job script is not able to connect to the remote server when the script is started by cron. If I start it from the command line of the prodid account it connects to the remote server with no trouble.

Note about the sftp command: I do not have to enter a password for sftp. The command to establish the connection with the remote server is sftp user@remote_server.

Many Thanks,
Patrick
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Mget with SFTP is not working

hi Team, I am connecting from one (A) linux server to another(C)/any linux server by sftp on A linux server: sftp userid@C password: mget is Not working fine I am using mget to pull the files. it shows mget as invalid command. But from (B) Linux server to (C) /to Any server Linux... (15 Replies)
Discussion started by: johnsnow
15 Replies

2. Shell Programming and Scripting

sftp autologin is working but ...

Dears, I am new to linux scripting and I was look for a way to auto login to a server using sftp to download a file. I found one and it is working fine. But i don't know the meaning of <<EOF in the code. Any one explain it to me: #!/bin/sh HOST=yourservername USER=yourusername ... (1 Reply)
Discussion started by: torabi
1 Replies

3. Shell Programming and Scripting

Script not working in cron but working fine manually

Help. My script is working fine when executed manually but the cron seems not to catch up the command when registered. The script is as follow: #!/bin/sh for file in file_1.txt file_2.txt file_3.txt do awk '{ print "0" }' $file > tmp.tmp mv tmp.tmp $file done And the cron... (2 Replies)
Discussion started by: jasperux
2 Replies

4. Shell Programming and Scripting

Script is not working from cron while working manually

Hello, I am facing a very strange problem when I run my script manuallu ./Fetchcode which is using to connect with MKS integrity from linux end it workks fine but when I run it from cron it doesn't work.Can someone help me 1) How could I check my script when it is running from cron like... (3 Replies)
Discussion started by: anuragpgtgerman
3 Replies

5. UNIX for Dummies Questions & Answers

Problem automating sFTP transfer using script in cron

Hi Newbie here I am having problems with automating sFTP transfers. Just to save time - SCP is not an option as sFTP is stipulated by controllers of far end server. Ineed to automate sFTP transfer of a single file, once a day to a remote server to which i have no control over. I am using:... (6 Replies)
Discussion started by: robbien
6 Replies

6. UNIX for Dummies Questions & Answers

Unable to sftp with cron (once more time...)

Hi, I have been searching for older posts and I've found many entries with identical problems, but I was not able to find the solution (or when I thought I found it, my trial didn't worked :(). Anyway, here is my question. I wrote a sftp.sh file that runs perfect from command line. It uses scp... (6 Replies)
Discussion started by: Kronos
6 Replies

7. UNIX for Dummies Questions & Answers

sftp in cron

Hi, I am running simple script to automate sftp transfer to remote box. I have setup public/private keys to have sftp connect automatically and have test script that list remote directory: #!/bin/ksh echo "OK, starting now..." sftp userid@host <<EOI cd dir ls -lt bye EOI... (2 Replies)
Discussion started by: r1omen
2 Replies

8. Solaris

SFTP not exiting when run from cron

I am using a script to transfer a file from a unix host to another unix host. The code snippet for sftp in the script is as below. sftp -oIdentityFile=$ID_FILE_NAME -oNumberOfPasswordPrompts=0 $REMOTE_USERID@$REMOTE_HOST <<EOF cd incoming put $REPORT_FILE... (2 Replies)
Discussion started by: msabhilash
2 Replies

9. Shell Programming and Scripting

SFTP not working in cron

Hi, I have a simple script that is trying to put a file that resides on a local machine to a remote machine. It runs fine manually but does not complete when scheduling to run in cron. Here is what the script looks like. Any idea what I am doing wrong here? #!/bin/ksh cd /path sftp... (4 Replies)
Discussion started by: ewilson0265
4 Replies

10. Solaris

SFTP errorcode 1 when run on cron but runs manually

I am trying to run a sript on cron to SFTP data to a company. Private and public keys are set up. When I run this manully it works fine, however it was failing when run on cron. I have narrowed down the problem - it fails at the code that says if the error code is 0 then continue . . . I... (2 Replies)
Discussion started by: Heidi.Ebbs
2 Replies
Login or Register to Ask a Question