pattern match in live stream


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting pattern match in live stream
# 1  
Old 06-09-2010
pattern match in live stream

hi!

i have a situation like this where i have to analyse the live log generated from

/bin/scp -v you@example.com

is if a pattern like say "Too many connections" comes i shud be able to identify it .
# 2  
Old 06-09-2010
/bin/scp -v you@example.com 2>&1 | grep "too many connections"
This User Gave Thanks to Corona688 For This Post:
# 3  
Old 06-11-2010
hi Corona688! thanks !..i want the script to exit with status 1 when the string in the is found ....
# 4  
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

Login or Register to Ask a Question

Previous Thread | Next Thread

3 More Discussions You Might Find Interesting

1. 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

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

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
Login or Register to Ask a Question