grep "226 Transfer complete" | wc -l


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting grep "226 Transfer complete" | wc -l
# 1  
Old 07-20-2009
grep "226 Transfer complete" | wc -l

echo $ftp_ctr returns '0' instead of '1'. Please help

Code:
331 Enter password
230 User logged in
200 Transfer mode set to BINARY
local: file1 remote: file2
227 Entering Passive Mode (xxxxxxxx).
125 Uploading in BINARY file xxx 
226 Transfer completed
24453780 bytes sent in 67 seconds (3.6e+02 Kbytes/s)
221 bye
0

Code:
# Upload to ftp 
################################################### 
ftp -v -n $HOST <<EOF
quote user $FTPUSER
quote pass $PASSWD
cd "/name1/name2"
bin
put $FILEIN $FILEOUT
EOF
 
# Check the ftp status and file
# ## wc -l tells the number of lines (accounts)
################################################### 
ftp_ctr=`ftp<<EOF| grep "226 Transfer complete" | wc -l
EOF
`
echo $ftp_ctr


Last edited by vgersh99; 07-20-2009 at 05:58 PM.. Reason: code tags, PLEASE!
# 2  
Old 07-20-2009
I'm unsure what you are doing in your wc statement with the ftp command, but I always redirect the ftp to a log and then grep from that log.



Code:
ftp -pnv > /tmp/ftp.log <<-EOF
...
EOF
CHECKERR=`cat /tmp/ftp.log | grep 226 | wc -l`

# 3  
Old 07-20-2009
Quote:
Originally Posted by benefactr
I'm unsure what you are doing in your wc statement with the ftp command, but I always redirect the ftp to a log and then grep from that log.



Code:
ftp -pnv > /tmp/ftp.log <<-EOF
...
EOF
CHECKERR=`cat /tmp/ftp.log | grep 226 | wc -l`

use grep -c 226, oneless pipe Smilie
# 4  
Old 07-20-2009
cannot use ftp -pvn


here is the message :
Code:
ftp: p: unknown option
Usage: ftp [-v] [-d] [-i] [-n] [-g] [-k realm] [-f] [-x] [-u] [-t] [host]


Last edited by vgersh99; 07-20-2009 at 05:59 PM.. Reason: code tags, PLEASE!
# 5  
Old 07-20-2009
To keep the forums high quality for all users, please take the time to format your posts correctly.

First of all, use Code Tags when you post any code or data samples so others can easily read your code. You can easily do this by highlighting your code and then clicking on the # in the editing menu. (You can also type code tags [code] and [/code] by hand.)

Second, avoid adding color or different fonts and font size to your posts. Selective use of color to highlight a single word or phrase can be useful at times, but using color, in general, makes the forums harder to read, especially bright colors like red.

Third, be careful when you cut-and-paste, edit any odd characters and make sure all links are working property.

Thank You.

The UNIX and Linux Forums
# 6  
Old 07-20-2009
Quote:
Originally Posted by Lenora2009
cannot use ftp -pvn


here is the message :
Code:
ftp: p: unknown option
Usage: ftp [-v] [-d] [-i] [-n] [-g] [-k realm] [-f] [-x] [-u] [-t] [host]

Use your orginal ftp statement, mine was just a example, but just add the redirect before the <<EOF in your just like I did in mine.
# 7  
Old 07-20-2009
Yes, thank you:

# Upload to ftp
###################################################
ftp -v -n $HOST > /temp/ftp.log <<EOF
quote user $FTPUSER
quote pass $PASSWD
cd "/name1/name2"
bin
put $FILEIN $FILEOUT
EOF

# Check the ftp status and file
# ## wc -l tells the number of lines (accounts)
###################################################
ftp_ctr=`cat /temp/ftp.log | grep 226 | wc -l`
echo $ftp_ctr[/CODE]

Last edited by Lenora2009; 07-21-2009 at 06:13 PM.. Reason: code tags, PLEASE!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash script - Print an ascii file using specific font "Latin Modern Mono 12" "regular" "9"

Hello. System : opensuse leap 42.3 I have a bash script that build a text file. I would like the last command doing : print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt where : print_cmd ::= some printing... (1 Reply)
Discussion started by: jcdole
1 Replies

2. Shell Programming and Scripting

grep with "[" and "]" and "dot" within the search string

Hello. Following recommendations for one of my threads, this is working perfectly : #!/bin/bash CNT=$( grep -c -e "some text 1" -e "some text 2" -e "some text 3" "/tmp/log_file.txt" ) Now I need a grep success for some thing like : #!/bin/bash CNT=$( grep -c -e "some text_1... (4 Replies)
Discussion started by: jcdole
4 Replies

3. Shell Programming and Scripting

Problem with "find" and "grep" command

I want to list all files/lines which except those which contain the pattern ' /proc/' OR ' /sys/' (mind the leading blank). In a first approach I coded: find / -exec ls -ld {} | grep -v ' /proc/| /sys/' \; > /tmp/list.txt But this doesn't work. I got an error (under Ubuntu): grep:... (5 Replies)
Discussion started by: pstein
5 Replies

4. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

5. Shell Programming and Scripting

ps -ef | grep "string1" "string2" " "string3"

Hi all, can any one suggest me the script to grep multiple strings from ps -ef pls correct the below script . its not working/ i want to print OK if all the below process are running in my solaris system. else i want to print NOT OK. bash-3.00$ ps -ef | grep blu lscpusr 48 42 ... (11 Replies)
Discussion started by: steve2216
11 Replies

6. Solaris

Solaris escape my script from "-" to "/226"

Hello everyone. I beg your guys pardon please. I try to ls -al in many path/directories. So, I put the code in text file which look like below; ls -al / ls -al /etc ls -al /etc/default ... however, when I paste it to Solaris over SecureCRT, it seems the code was escaped from "-" to... (0 Replies)
Discussion started by: Smith
0 Replies

7. AIX

xx=`date +"%a %b %d"`;rsh xxx grep "^$XX" zzz ?

AIX 4.2 I am trying to do an rsh grep to search for date records inside server logs by doing this : xx=`date +"%a %b %d"` rsh xxx grep "^$XX" zzz gives : grep: 0652-033 Cannot open Jun. grep: 0652-033 Cannot open 11. But if I do : xx=`date +"%a %b %d"` grep "^$XX" zzz it works... (2 Replies)
Discussion started by: Browser_ice
2 Replies

8. Shell Programming and Scripting

ls -laR | grep "^-" | awk '{print $9}'| grep "$.txt"

Hi, I don't know hot to make this command work: ls -laR | grep "^-" | awk '{print $9}'| grep "$.txt" It should return the list of file .txt It's important to search .txt at the end of the line, becouse some file name have "txt" in their name but have other extensions (13 Replies)
Discussion started by: DNAx86
13 Replies

9. UNIX for Dummies Questions & Answers

Explain the line "mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`"

Hi Friends, Can any of you explain me about the below line of code? mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'` Im not able to understand, what exactly it is doing :confused: Any help would be useful for me. Lokesha (4 Replies)
Discussion started by: Lokesha
4 Replies

10. Shell Programming and Scripting

grep to find content in between curly braces, "{" and "},"

problem String ~~~~~~~~~~~~~~~~~~ icecream= { smart peopleLink "good" LC "happy" , smartpeopleLink "dull" LC "sad" } aend = {smart vc4 eatr kalu} output needed ~~~~~~~~~~~~~~~~~~ smart peopleLink "good" LC "happy" , smartpeopleLink "dull" LC "sad" smart vc4... (4 Replies)
Discussion started by: keshav_rk
4 Replies
Login or Register to Ask a Question