The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Operating Systems > SUN Solaris
.
google unix.com



SUN Solaris The Solaris Operating System, usually known simply as Solaris, is a free Unix-based operating system introduced by Sun Microsystems .

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
exiting from script arghya_owen Shell Programming and Scripting 1 06-02-2008 07:36 AM
SFTP not working in cron ewilson0265 Shell Programming and Scripting 4 12-02-2007 11:29 AM
SFTP errorcode 1 when run on cron but runs manually Heidi.Ebbs SUN Solaris 2 08-08-2007 01:16 PM
Script Not Exiting??? lesstjm Shell Programming and Scripting 1 07-11-2007 12:58 PM
exiting in c ruffenator High Level Programming 3 04-28-2002 03:31 AM

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 12-02-2007
msabhilash msabhilash is offline
Registered User
  
 

Join Date: Dec 2007
Posts: 2
Unhappy 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 (permalink)  
Old 12-02-2007
Smiling Dragon's Avatar
Smiling Dragon Smiling Dragon is offline Forum Advisor  
Disorganised User
  
 

Join Date: Nov 2007
Location: New Zealand
Posts: 922
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 (permalink)  
Old 12-02-2007
porter porter is offline Forum Advisor  
Registered User
  
 

Join Date: Jan 2007
Posts: 2,965
Quote:
Originally Posted by msabhilash View Post
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.
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 05:02 AM.


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