Sponsored Content
Full Discussion: pattern match in live stream
Top Forums Shell Programming and Scripting pattern match in live stream Post 302428977 by Corona688 on Friday 11th of June 2010 11:34:40 AM
Old 06-11-2010
You don't need to analyze the logfile at all to quit when scp fails. Every program has an exit status, 0 for success, anything else for some sort of error. You can tell it to quit when scp returns nonzero by:
Code:
/bin/scp -v you@example.com || exit 1

If you want to be more specific about the error conditions, scp appears to return different error codes for different errors:

Code:
SCP Return Codes
0	Operation was successful
1	General error in file copy
2	Destination is not directory, but it should be
3	Maximum symlink level exceeded
4	Connecting to host failed.
5	Connection broken
6	File does not exist
7	No permission to access file.
8	General error in sftp protocol
9	File transfer protocol mismatch
10	No file matches a given criteria
65	Host not allowed to connect
66	General error in ssh protocol
67	Key exchange failed
68	Reserved
69	MAC error
70	Compression error
71	Service not available
72	Protocol version not supported
73	Host key not verifiable
74	Connection failed
75	Disconnected by application
76	Too many connections
77	Authentication cancelled by user
78	No more authentication methods available
79	Invalid user name

So:

Code:
/bin/scp -v you@example.com
# There must be no statements between this assignment and the scp call!
SCPSTATUS="$?"

if [ "$SCPSTATUS" -ne 0 ]
then
        echo "SCP quit with status $SCPSTATUS"
        exit 1
fi

 

3 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Deleting lines from a stream after matching a pattern

Hi, I have a requirement to to an ldapsearch and remove the shadow attributes in the output file. What I do is ldapsearch() | operation to remove shadow > FILE The ldapsearch gives output like this(with same line formation): objectClass: FSConfig objectClass: extensibleObject fsCAIP:... (10 Replies)
Discussion started by: lorzinian
10 Replies

2. Shell Programming and Scripting

Matching a pattern 250 characters up and down stream

hii all i have a file a which contains some thing like this strand smthg position + yyx 3020 - yyw 10,000 now i have another file (file2) which contains the data starting from 1 to n positions i want to refer first file if + ... (4 Replies)
Discussion started by: anurupa777
4 Replies

3. Shell Programming and Scripting

Rearrange or replace only the second line after pattern match or pattern match

Im using the command below , but thats not the output that i want. it only prints the odd and even numbers. awk '{if(NR%2){print $0 > "1"}else{print $0 > "2"}}' Im hoping for something like this file1: Text hi this is just a test text1 text2 text3 text4 text5 text6 Text hi... (2 Replies)
Discussion started by: invinzin21
2 Replies
Tcl_StringMatch(3)					      Tcl Library Procedures						Tcl_StringMatch(3)

__________________________________________________________________________________________________________________________________________________

NAME
Tcl_StringMatch, Tcl_StringCaseMatch - test whether a string matches a pattern SYNOPSIS
#include <tcl.h> int Tcl_StringMatch(str, pattern) int Tcl_StringCaseMatch(str, pattern, flags) ARGUMENTS
const char *str (in) String to test. const char *pattern (in) Pattern to match against string. May contain special characters from the set *?[]. int flags (in) OR-ed combination of match flags, currently only TCL_MATCH_NOCASE. 0 specifies a case-sensitive search. _________________________________________________________________ DESCRIPTION
This utility procedure determines whether a string matches a given pattern. If it does, then Tcl_StringMatch returns 1. Otherwise Tcl_StringMatch returns 0. The algorithm used for matching is the same algorithm used in the string match Tcl command and is similar to the algorithm used by the C-shell for file name matching; see the Tcl manual entry for details. In Tcl_StringCaseMatch, the algorithm is the same, but you have the option to make the matching case-insensitive. If you choose this (by passing TCL_MATCH_NOCASE), then the string and pattern are essentially matched in the lower case. KEYWORDS
match, pattern, string Tcl 8.5 Tcl_StringMatch(3)
All times are GMT -4. The time now is 09:54 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy