UNIX Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsOperating SystemsUNIX Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now!
  #1  
Old September 22nd, 2004, 08:01 PM
AVS AVS is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Posts: 37 AVS User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 4 m 52 sec
Reputation Power: 4
trap 'exit 1' 0 not working as expected

In continuation to my earlier thread on trap, I am trying to do
# prog: doftp
trap 'exit 1' 0
ftp -in $host << EOF_MYFTP
user $user $password
cd $dest_dir
put $dest_file YOURFTP.FIL
EOF_MYFTP

In calling prog I have
if ./doftp.ksh then
xyz
fi

I find that irrespective of a error that happens during put command the if part of calling program [xyz] always executes.

I want it ti execute only if error in put command due to
> space constraint on destination
> io error
> network connectivity error
> no permissions

I tried trap 'exit 1' 1 21 22 23 24
etc but dint work

Any way?

Reply With Quote
  #2  
Old September 22nd, 2004, 08:22 PM
AVS AVS is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Posts: 37 AVS User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 4 m 52 sec
Reputation Power: 4
Just wanted to add:

I tried the above aftre revoking the write permissions on dest dir. Strngely the called prog always exits with status 1 even whwn all went right and file got ftp-ed.

Reply With Quote
  #3  
Old September 23rd, 2004, 12:41 AM
guggach guggach is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jul 2004
Location: Middle Europa
Posts: 1,083 guggach User rank is Corporal (100 - 500 Reputation Level)guggach User rank is Corporal (100 - 500 Reputation Level)guggach User rank is Corporal (100 - 500 Reputation Level)guggach User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 4 Days 19 h 49 m 57 sec
Reputation Power: 9
try: man trap

Reply With Quote
  #4  
Old September 23rd, 2004, 05:18 AM
andyb1ack andyb1ack is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2004
Posts: 60 andyb1ack User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 19 m 14 sec
Reputation Power: 4
Hi,

Just thinking of a workaround...

If you "dir" the file straight after you've "put" it then you could check to see if the file exists on the remote node...

Your code may then be something like the following (note I've not tested it!) :

Code:
#-- Function doftp
doftp()
{
ftp -in $host << EOF_MYFTP
user $user $password 
put YOURFTP.FILE $dest_dir/$dest_file
dir $dest_dir/$dest_file
bye
EOF_MYFTP
}

#-- Run ftp
doftp 1>doftp.log 2>&1

#-- Check logfile for "No such file or directory"
NUM_ERRRORS=`grep -c "No such file or directory" doftp.log`

if [[ ${NUM_ERRORS} -eq 0 ]]; then
  echo "File(s) transferred successfully"
else
  echo "Errors transferring file(s):"
  grep "No such file or directory" doftp.log |awk '{print $1}'
fi

exit ${NUM_ERRORS}


Hope this helps,
Andy

Reply With Quote
Reply

Viewing: Dev Shed ForumsOperating SystemsUNIX Help > trap 'exit 1' 0 not working as expected


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway