The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
awk not working in script doitnow Shell Programming and Scripting 3 08-28-2008 06:36 AM
why the below script is not working ., konankir Shell Programming and Scripting 14 03-27-2008 04:32 PM
bdf script not working !! kpatel786 Shell Programming and Scripting 3 11-16-2007 11:10 AM
Pls. Help my script not working as it should cocoabeauty1 Shell Programming and Scripting 1 07-28-2007 05:11 PM
FTP script not working rookie250 Shell Programming and Scripting 2 12-19-2006 02:49 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 12-23-2008
Nishchal_Nagre Nishchal_Nagre is offline
Registered User
  
 

Join Date: Dec 2008
Posts: 2
Script not working.

Hi,

I am a DBA, worked on Windows platforms for past 6 years, and now shifted in environment where HP UX is OS environment.

I have task to complete which involves Unix script to be prepared. This script should FTP the file to the destination server and if this FTP fails, then it should write in syslog file. For the same purpose, I have prepared following script.

#!/usr/bin/sh
# testftp : Script to transfer file from SAP to wowftp server
#-------------------------------------------------------------------

# Timestamp
echo ------------------------------------ >> /interface/logs/alhftplog.txt
echo `date` Start of FTP to WOW FTP >> /interface/logs/alhftplog.txt
echo ----------------------------------- >> /interface/logs/alhftplog.txt


# FTP

ftp -vn HOST NAME 2> /interface/logs/ftpfailedlog.log <<END_SCRIPT >> /interface/logs/ftplog.txt
quote USER USER NAME
quote PASS USER PASSWORD
ascii
prompt off
lcd /interface/outbound
cd /test
mput FILE PATTERN*
bye
END_SCRIPT

# End of FTP

EXITSTATUS=$?
if [ $EXITSTATUS != "0" ]
then
logger -p local6.info -t XXTIV9999E9 "FTP to Host Failed"
else
echo `date` "FTP Successful" >> /interface/logs/ftplog.txt
fi


I am able execute above-mentioned screen and not experiencing any error. However, when I check in the system log file, no error message is being recorded.

To test this problem, I have executed “logger” command from OS prompt and I have found that error is being written in the syslog file.

Please help me to resolve this problem.

Thanks,

Best regards,

Nishchal Nagre.
  #2 (permalink)  
Old 12-23-2008
pludi's Avatar
pludi pludi is offline Forum Staff  
Moderator
  
 

Join Date: Dec 2008
Location: .at
Posts: 1,839
  1. Please use the code environment around your script for readability
  2. Quote:
    Originally Posted by Nishchal_Nagre View Post
    I am able execute above-mentioned screen and not experiencing any error. However, when I check in the system log file, no error message is being recorded.
    So your problem is....?
  #3 (permalink)  
Old 12-23-2008
Nishchal_Nagre Nishchal_Nagre is offline
Registered User
  
 

Join Date: Dec 2008
Posts: 2
Hi,

My problem is, below given part of my script is not working. After execution of the script it has not spitting any error.

EXITSTATUS=$?
if [ $EXITSTATUS != "0" ]
then
logger -p local6.info -t XXTIV9999E9 "FTP to Host Failed"
else
echo `date` "FTP Successful" >> /interface/logs/ftplog.txt
fi

Thanks,

Best regards,

Nishchal Nagre.
  #4 (permalink)  
Old 12-24-2008
pludi's Avatar
pludi pludi is offline Forum Staff  
Moderator
  
 

Join Date: Dec 2008
Location: .at
Posts: 1,839
Ok, I'm going to assume that you mean that the FTP transfer failed, but you didn't get an error message.

Try changing the lines
Code:
EXITSTATUS=$?
if [ $EXITSTATUS != "0" ]
to
Code:
if [ $? != 0 ]
or even
Code:
if [ ! $? ]
  #5 (permalink)  
Old 12-24-2008
BubbaJoe's Avatar
BubbaJoe BubbaJoe is offline
Registered User
  
 

Join Date: Oct 2008
Location: St Louis
Posts: 153
ftp will not throw an error if it connects and runs commands then exits ok. You will need to capture the error from ftp itself. So you need to look at the stderr from you ftp command and see if the error on file transfer failed.Do you get anything in /interface/logs/ftpfailedlog.log?
  #6 (permalink)  
Old 01-05-2009
karver karver is offline
Registered User
  
 

Join Date: Dec 2008
Posts: 7
I want to accomplish the same thing as Nischal, if anybody can shed light as to what's wrong with my script, I would appreciate it

Here is what i want to do, ftp a file to a server then if there are any errors, an email shall be sent to my account stating that the ftp process failed. However as BubbaJoe mentioned, eventhough I get an ftp error, the return code is still zero (upon checking with $?). I need to be able to capture the error code since this will be the basis for my if statement and for the script that will run after the ftp. Initially I tried this (which didn't work):
Code:
ftp -nv server.com<<-EOF
user USER Password                          
prompt
ascii
put testfile /export/dir/test/testfileftp               
bye
EOF

#Check if FTP is successful or not
ERRCD=$?
if [ $ERRCD -ne 0] then
echo "The FTP process failed" | mailx -s "The FTP process failed with error code $ERRCD on $(date '+%m-%d:%H:%M')" myemail@administrator.com
            print “ERRCD=${ERRCD}” << /tmp/Send_errcd.log
exit 1        
fi
I was able to search something in the net which seemed like a good idea, since in his code, he checked the return code, the bytes transferred and transfer complete as the basis for whether there was an error:
Code:
ftp -nv server.com<<-EOF
user USER Password                          
prompt
ascii
put testfile /export/dir/test/testfileftp               
bye"|ftp -iv > ftpreturn.log

EOF
 
#Check if FTP is successful or not
ftpresult=$?
bytesindatafile=wc -c testfile | cut -d " " -f 1
bytestransferred=grep -e '^[0-9]* bytes sent' ftpreturn.log | cut -d " " -f 1
ftptransfercomplete=grep -e '226 ' ftpreturn.log | cut -d " " -f 1
 
echo "-- FTP result code: $ftpresult" >> ftpreturn.log echo "-- bytes in datafile: $bytesindatafile bytes" >> ftpreturn.log echo "-- bytes transferred: $bytestransferred bytes sent" >> ftpreturn.log
if [ "$ftpresult" != "0" ] || [ "$bytestransferred" != "$bytesindatafile" ] || ["$ftptransfercomplete" != "226" ] then
          echo "The CANS process failed" | mailx -s "The FTP process failed with error code $ERRCD on $(date '+%m-%d:%H:%M')" myemail@administrator.com
fi
However in that code block above, i get the error that the -c and -e commands are not valid (I am using ksh). Please help me dissect the code or if you have a suggestion on how I could check the success or not of an ftp, as well as use that error code for the email to be sent and as the basis for whether my next script will be kicked off, i would highly appreciate it.
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 12:42 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