SFTP not exiting when run from cron


 
Thread Tools Search this Thread
Operating Systems Solaris SFTP not exiting when run from cron
# 1  
Old 12-02-2007
Data 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 $REPORT_TARGET_FILE_NAME
quit
EOF


When I run this script from the command prompt, it works as expected. But when I run this as a cron job, the script does not exit properly. It transfers the file as expected, but when I see the process list I can see that the script has spawned 2 other sub processes and is waiting for them to exit.

This is how the process tree looks like.


[user@host]$ ptree 10238
491 /usr/sbin/cron
10207 sh -c . /home/admin/user/.profile > /dev/null 2>&1; /user/app/scripts/sftpRepor
10238 /bin/ksh /user/app/scripts/sftpReport.sh
10243 sftp -v -oIdentityFile=/home/admin/user/.ssh/IdForHost -oNumberOfPasswordP
10244 ssh -oProtocol = 2 -s -oForwardAgent = no -oForwardX11 = no -o IdentityFile=/ho
[user@host]$



The cron entry is as below.

35 15 * * * . /home/admin/user/.profile > /dev/null 2>&1; /user/app/scripts/sftpReport.sh >> /user/log/sftpReport.sh.log 2>&1

I thought of giving the commands using a batch file i.e. by the command sftp -b batch_filename....., but unfortunately the usage information I get is as below.

bash-2.05$ sftp
usage: sftp [-1vC] [-osshopt = value] [user@]host
bash-2.05$


The version of ssh in my host is as below.

bash-2.05$ ssh -V
SSH Version Sun_SSH_1.0.1, protocol versions 1.5/2.0.



Below is the error part of verbose output of sftp when run from cronjob.
..........................
..........................
debug1: ssh-userauth2 successfull: method publickey
debug1: fd 6 setting O_NONBLOCK
debug1: fd 7 IS O_NONBLOCK
debug1: fd 8 setting O_NONBLOCK
debug1: channel 0: new [client-session]
debug1: send channel open 0
debug1: Entering interactive session.
debug1: client_init id 0 arg 0
debug1: Sending subsystem: sftp
debug1: channel 0: open confirm rwindow 0 rmax 16384
sftp > debug1: channel 0: read<=0 rfd 6 len 0
debug1: channel 0: read failed
debug1: channel 0: input open->drain
debug1: channel 0: close_read
debug1: channel 0: ibuf empty
debug1: channel 0: input drain->closed
debug1: channel 0: send eof
debug1: channel 0: rcvd eof
debug1: channel 0: output open->drain
debug1: channel 0: obuf empty
debug1: channel 0: output drain->closed
debug1: channel 0: close_write
debug1: channel 0: send close
debug1: channel_input_channel_request: channel: 0 rcvd request for exit-status reply 0
debug1: cb_fn 2b74c cb_event 91
debug1: channel 0: rcvd close
debug1: channel 0: full closed2
debug1: channel_free: channel 0: status: The following connections are open:
#0 client-session (t4 r0 i8/0 o128/0 fd -1/-1)

debug1: channel_free: channel 0: dettaching channel user





Below are some information regarding the host and package installations. Let me know if you would require any further information to analyse this problem.


[user@host]$ version
Machine hardware: sun4u
OS version: 5.9
Processor type: sparc
Hardware: SUNW,Sun-Fire-V240

The following components are installed on your system:


Sun Studio 11
Sun Studio 11 C Compiler
Sun Studio 11 C++ Compiler
Sun Studio 11 Tools.h++ 7.1
Sun Studio 11 C++ Standard 64-bit Class Library
Sun Studio 11 Fortran 95
Sun Studio 11 Performance Library
Sun Studio 11 Documentation Set

version of "/opt/SUNWspro/bin/../prod/bin/../../bin/cc": Sun C 5.8 2005/10/13
version of "/opt/SUNWspro/bin/../prod/bin/../../bin/CC": Sun C++ 5.8 2005/10/13
version of "/opt/SUNWspro/bin/../prod/bin/../../bin/f90": Sun Fortran 95 8.2 2005/10/13

[user@host]$ which version
/opt/SUNWspro/bin/version
[user@host]$ pkginfo | grep -i ssh
application SUNWsrshp NetConnect 3.X Self-Service Hardware Alarms (SSHA) Provider IM
system SUNWsshcu SSH Common, (Usr)
system SUNWsshdr SSH Server, (Root)
system SUNWsshdu SSH Server, (Usr)
system SUNWsshr SSH Client and utilities, (Root)
system SUNWsshu SSH Client and utilities, (Usr)
[user@host]$ ssh -V
SSH Version Sun_SSH_1.0.1, protocol versions 1.5/2.0.


Please help me resolve this issue.
# 2  
Old 12-02-2007
Cron runs it's commands with an extremely limited environment. Lots of the environment variables you would expect to find are actually missing. It could be that ssh is expecting something like $HOME set. I'd suggest using the BSD ps to get the full commandline from those two spawned processes to get more information.
# 3  
Old 12-02-2007
Quote:
Originally Posted by msabhilash
The cron entry is as below.

35 15 * * * . /home/admin/user/.profile > /dev/null 2>&1; /user/app/scripts/sftpReport.sh >> /user/log/sftpReport.sh.log 2>&1
I recommend not using convoluted entries in the crontab, put a simple one-liner for the shell script, then put all your stuff in one shell script where you have complete control, ie:-

(a) lets you dictate exactly what environment gets set up
(b) determine which shell will be used using "#!/bin/sh".
(c) let's you test the script in isolation
(d) means you can change the script without changing the crontab entry.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Cron job - Need to run Cron every quarter at particular time

Hi, 1) If some job supposed to run on 1st of every month at 7 AM In cron job when we have a blackout on the 1st ( i.e when 1st falls on a sunday ) how can we make the job run the next business day? 2) How can we run a job on 25th of every quarter 7 AM(jan,apr,jul,oct) And if 25th... (5 Replies)
Discussion started by: System Admin 77
5 Replies

2. Shell Programming and Scripting

Batch script to run in SFTP

Hello Guys, I am writting a script which is SFTPing from Solaris to Windows. I need to run a Batch script in SFTP session (ongoing) which will map a network drive and then transfer my files. I can run the Batch script via SSH but not via SFTP and this mapping is limited to that SSH... (4 Replies)
Discussion started by: Deei
4 Replies

3. Shell Programming and Scripting

Who -u gives different output if run from cron than if run from terminal?

If I run 'who -u' interactively or from a script invoked through bash in a tty on my Ubuntu 12LTS box I get an output like this: testuser pts/0 Dec 9 02:32 . 2163 (host.xx.yy) running the same through cron I get: testuser pts/0 2012-12-09 02:32 00:05 2163... (2 Replies)
Discussion started by: latimer
2 Replies

4. UNIX for Advanced & Expert Users

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... (12 Replies)
Discussion started by: PatrickPurfield
12 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. Shell Programming and Scripting

Script is not exiting from run mode.

Hi Folks. My script is not exiting after run though its working correctly please suggest. #!/bin/ksh trap '' HUP . /bin/functions config_env PATH=/bin:/usr/bin:/usr/local/bin:$EXEC_PATH:$ORACLE_HOME/bin MONTH=$(control_register month) YEAR=$(control_register year) DATE_NOW="Job... (1 Reply)
Discussion started by: Haque123
1 Replies

8. 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

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