|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
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
|
|||
|
|||
|
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? |
|
#2
|
|||
|
|||
|
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. |
|
#3
|
|||
|
|||
|
try: man trap
|
|
#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 |
![]() |
| Viewing: Dev Shed Forums > Operating Systems > UNIX Help > trap 'exit 1' 0 not working as expected |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|