- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- exit my scripts
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-30-2006 10:28 PM
тАО10-30-2006 10:28 PM
I have created a script to ftp files to and from an sftp server.
I have a check function within the script:
# generic check function
check () {
if [[ $? -ne 0 ]] ; then
logfile "Unix Alert: Error Processing sftp01 MRD files, please investigate"
mail -s "$DATE:$TIME:$PROGPATH/$PROGNAME has failed, please investigate" chris@mail <$LOGFILE
rm $LCKFILE
fi
My question is I want to then exit out of the entire script so I put exit 1 after the rm $LCKFILE but this then continued within the script.
what is the exit code to stop the script processing completely within the check function?
many thanks
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-30-2006 10:32 PM
тАО10-30-2006 10:32 PM
Re: exit my scripts
exit 127
regards,
ivan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-30-2006 10:46 PM
тАО10-30-2006 10:46 PM
Re: exit my scripts
# generic check function
check () {
if [[ $? -ne 0 ]] ; then
logfile "Unix Alert: Error Processing sftp01 MRD files, please investigate"
mail -s "$DATE:$TIME:$PROGPATH/$PROGNAME has failed, please investigate" chris@mail <$LOGFILE
rm $LCKFILE
CODE=1
fi
exit $CODE
Yang
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-30-2006 10:48 PM
тАО10-30-2006 10:48 PM
Solution# generic check function
CODE=0
check () {
if [[ $? -ne 0 ]] ; then
logfile "Unix Alert: Error Processing sftp01 MRD files, please investigate"
mail -s "$DATE:$TIME:$PROGPATH/$PROGNAME has failed, please investigate" chris@mail <$LOGFILE
rm $LCKFILE
CODE=1
fi
exit $CODE
Yang
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-30-2006 10:51 PM
тАО10-30-2006 10:51 PM
Re: exit my scripts
Your code should perform as you want if you call the 'check' function immediately after a command that you want to evaulate for success. If you need to do several commands, but check only the status of the first command later in your code, you would need to do something like:
#!/usr/bin/sh
check () {
if [[ $1 -ne 0 ]] ; then
echo "non-zero; exiting..."
exit 1
fi
}
cp #...produces a non-zero return...
X=$?
date
check ${X}
echo "oops!"
exit 0
...Are you sure that your code meets this requirement?
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-30-2006 11:07 PM
тАО10-30-2006 11:07 PM
Re: exit my scripts
set_env
check () {
if [[ $? -ne 0 ]] ; then
logfile "Unix Alert: Error Processing sftp01 MRD files, please investigate"
mail -s "$DATE:$TIME:$PROGPATH/$PROGNAME has failed, please investigate" chris@mail <$LOGFILE
rm $LCKFILE
fi
}
logfile () {
MSG_STRING="$*"
echo "$DATE:$TIME: $MSG_STRING" >> $LOGFILE
}
ftp code .......... >> ftp script
./ftpscript
check
ftp code .......... >> ftp script2
./ftpscript2
check
ftp code ........... >> ftp script3
./ftpscript3
check
logfile " Finished processing ftp "
If the script encounters any error's then I want it to exit here however I have noticed ftp1 failing then the check mails abd the script will then continue.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-31-2006 12:06 AM
тАО10-31-2006 12:06 AM
Re: exit my scripts
How does your FTP script determine the success for failure of the FTP it does?
If you are relying on a non-zero return value from an FTP to denote a failed FTP, then that is a problem.
Your FTP script needs to examine the result of its transfer in the reply it returns. As documented in the 'ftpd(1M)' manpages, this is a three-digit code. For example, a value of 226 might indicate a successful transfer. You need to capture this dialog; examine it; and construct your own zero (0) or one (1) exit status from your FTP script. In that fashinon, your 'check' function will work as expected.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-31-2006 12:21 AM
тАО10-31-2006 12:21 AM
Re: exit my scripts
RET=0
check () {
if [[ $? -ne 0 ]] ; then
logfile "Unix Alert: Error Processing sftp01 MRD files, please investigate"
mail -s "$DATE:$TIME:$PROGPATH/$PROGNAME has failed, please investigate" chris@mail <$LOGFILE
rm $LCKFILE
RET=1
fi
}
logfile () {
MSG_STRING="$*"
echo "$DATE:$TIME: $MSG_STRING" >> $LOGFILE
}
ftp code .......... >> ftp script
./ftpscript
check
if [ $RET -ne 0 ] ; then
exit 1
fi
ftp code .......... >> ftp script2
./ftpscript2
check
if [ $RET -ne 0 ] ; then
exit 1
fi
ftp code ........... >> ftp script3
./ftpscript3
check
if [ $RET -ne 0 ] ; then
exit 1
fi
logfile " Finished processing ftp "
Yang
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-31-2006 02:26 AM
тАО10-31-2006 02:26 AM
Re: exit my scripts
there's no need of global variables - set a return value for your check function:
check () { [ $1 -eq 0 ] && return 0
logfile ...
mail -s ...
rm ...
return $1
}
create-ftpscript >ftpscript1
ftpscript1
if ! check $?
then exit $? # this will be the ret.val of check()
fi
...
mfG Peter
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-31-2006 03:16 AM
тАО10-31-2006 03:16 AM
Re: exit my scripts
Thanks for your comments, I am not particulaly interested in the FTP'd file itself because if the file transfer is a failure then it will be picked up again elsewhere.
I am looking for failures within the transfer process - ie if one ftp failed then the script must stop so when run next time the remaining files processed.
I will attach the script as it is now.
Pete,
can you elaborate on your comments as I am not sure of the syntax here - as I can see yang has the solution?
Thanks for your help - if you have any idea's then I will take them onboard.
cheers