Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How to trap FTP error

Posted on 2011-09-06
8
Medium Priority
?
401 Views
Last Modified: 2013-11-29
Dear Experts,

I have the following script. It set as a cron job. It works fine if the file is present on the server, but if it is not, the script hangs.
How can I trap the failure and then exit from the script?
0
Comment
Question by:sfuk
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 15

Expert Comment

by:WalkaboutTigger
ID: 36491399
do an ls on the ftp server then perform a find or grep on "abc" or some known substring within the filename.
If no lines are returned, the file does not exist.
0
 

Author Comment

by:sfuk
ID: 36491446
Thank you, WalkaboutTigger, for your quick response.

When i open ftp process, can I do something like

echo `ls -l abc*` > abc.log
0
 

Author Comment

by:sfuk
ID: 36492515
I made the following changes/additions in my initial script and solved the problem.


#! /bin/bash

v_rundir="/home/abc"
v_ftp=`cat ftp.log | grep "not found" | wc -l`
cd $v_rundir
 
rm ftp.log

# Test to see if this process is already running...
if [ -e process.lck ] ; then   # if it is, then exit...
 exit
fi
echo $$ > process.lck     # otherwise, lock this process from duplicated execution...

#FTP Function
# Get the new pgp files...
sftp username@ftp4.server.com <<EOF >>/home/abc/ftp.log 2>&1
cd abc/Toabc
mget abc*.txt.pgp
rm abc*.txt.pgp
quit
EOF
if [ $v_ftp -ne "0" ]; then
rm process.lck
exit 1 
fi
exit

Open in new window

0
 
LVL 35

Accepted Solution

by:
Duncan Roe earned 2000 total points
ID: 36509767
Rather than run ftp with a here document, you have far more control if you drive it via expect. Picking up errors becomes almost a no-brainer. If you are interested, I can post an example or 2.
0
 
LVL 53

Expert Comment

by:Dhaest
ID: 36947343
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is the first one of a series of articles I’ll be writing to address technical issues that are always referred to as network problems. The network boundaries have changed, therefore having an understanding of how each piece in the network  puzzl…
Configuring network clients can be a chore, especially if there are a large number of them or a lot of itinerant users.  DHCP dynamically manages this process, much to the relief of users and administrators alike!
After creating this article (http://www.experts-exchange.com/articles/23699/Setup-Mikrotik-routers-with-OSPF.html), I decided to make a video (no audio) to show you how to configure the routers and run some trace routes and pings between the 7 sites…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
Suggested Courses

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question