Sponsored Content
Top Forums Shell Programming and Scripting Cygwin script log redirection not working well Post 302725547 by heykiran on Friday 2nd of November 2012 10:26:02 AM
Old 11-02-2012
Cygwin script log redirection not working well

I have a simple script which will send a curl request and redirect the output to a log file.

Code:
for i in {1..20}
do
 curl google.com -is >>log.log &
 echo "request # $i" >> log.log
done

After it completes the execution, if I run the following command I should see 20 lines because I am printing it in the loop.
Code:
cat log.log|grep request|wc -l

But I see 1 or 2 lines and all my log is messed up. I know that I am sending curl command to the background so the log will be mixed up. But I should see 20 "request" when I grep the log.

The same script works fine in my ubuntu. Also it works fine in my friends cygwin. I uninstalled cygwin and installed it back but no change. I guess it is something with my windows configuration? Anyone know why it is happening?

My messed up log
Code:
request # 1
HTTP/1.1 301HTTP/1.1 301HTTP/1.1 301HTTP/1.1 301 Moved Permanently
Location: http://www.google.com/
Content-Type: text/html; charset=UTF-8
Date: Fri, 02 Nov 2012 14:22:32 GMT
Expires: Sun, 02 Dec 2012 14:22:32 GMT
Cache-Control: public, max-age=2592000
Server: gws
Content-Length: 219
X-XSS-Protection: 1; mode=block
X-Frame-Options: SAMEORIGIN

<HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">
<TITLE>301 Moved</TITLE></HEAD><BODY>
<H1>301 Moved</H1>
The document has moved
<A HREF="http://www.googHTTP/1.1 301 Moved PermaHTTP/1.1 301HTTP/1.1 301HTTP/1.1 301 Moved Permanently
Location: http://www.google.com/
Content-Type: text/html; charset=UTF-8
Date: Fri, 02 Nov 2012 14:22:32 GMT
Expires: Sun, 02 Dec 2012 14:22:32 GMT
Cache-Control: public, max-age=2592000
Server: gws
Content-Length: 219
X-XSS-Protection: 1; mode=block
X-Frame-Options: SAMEORIGIN

<HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">
<TITLE>301 Moved</TITLE></HEAD><BODY>
<H1>301 Moved</H1>
The document has moved
<A HREF="http://www.googHTTP/1.1 301 HTTP/1.1 301 HTTP/1.1 301 HTTP/1.1 301 HTTP/1.1 301 Moved Permanently
Location: http://www.google.com/
Content-Type: text/html; charset=UTF-8
Date: Fri, 02 Nov 2012 14:22:32 GMT
Expires: Sun, 02 Dec 2012 14:22:32 GMT
Cache-Control: public, max-age=2592000
Server: gws
Content-Length: 219
X-XSS-Protection: 1; mode=block
X-Frame-Options: SAMEORIGIN

<HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">
<TITLE>301 Moved</TITLE></HEAD><BODY>
<H1>301 Moved</H1>
The document has moved
<A HREF="http://www.google.com/">hHTTP/1.1 301 HTTP/1.1 301 HTTP/1.1 301 HTTP/1.1 301 HTTP/1.1 301 HTTP/1.1 301 Moved Permanently
Location: http://www.google.com/
Content-Type: text/html; charset=UTF-8
Date: Fri, 02 Nov 2012 14:22:32 GMT
Expires: Sun, 02 Dec 2012 14:22:32 GMT
Cache-Control: public, max-age=2592000
Server: gws
Content-Length: 219
X-XSS-Protection: 1; mode=block
X-Frame-Options: SAMEORIGIN

<HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">
<TITLE>301 Moved</TITLE></HEAD><BODY>
<H1>301 Moved</H1>
The document has moved
<A HREF="http://www.gHTTP/1.1 301 Moved Permanently
Location: http://www.google.com/
Content-Type: text/html; charset=UTF-8
Date: Fri, 02 Nov 2012 14:22:32 GMT
Expires: Sun, 02 Dec 2012 14:22:32 GMT
Cache-Control: public, max-age=2592000
Server: gws
Content-Length: 219
X-XSS-Protection: 1; mode=block
X-Frame-Options: SAMEORIGIN

<HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">
<TITLE>301 Moved</TITLE></HEAD><BODY>
<H1>301 Moved</H1>
The document has moved
<A HREF="http://www.google.com/">here</A>.
</BODY></HTML>

 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Redirection not working as expected

Portion of my script below : if ; then NUMBEROFFEILDS=`cat ${BASE_SCRIPT_LOC}/standardfilecleanup.lst|grep -w ${db_file_path}|awk -F: '{print NF}'` COUNT=4 while ; do awk_var="$"`echo $COUNT` file_name1=`cat ${BASE_SCRIPT_LOC}/standardfilecleanup.lst|grep -w... (1 Reply)
Discussion started by: findprakash
1 Replies

2. UNIX for Dummies Questions & Answers

Redirection of output to a log file

Apologies for the trivial nature of this question but I cannot seem to get a simple re direct to a log file to work Step 1 touch log.txt at -f batch.sh now >> log.txt I am trying to get the batch.sh contents into the log file Manny Thanks (8 Replies)
Discussion started by: JohnCrump
8 Replies

3. UNIX for Dummies Questions & Answers

Capping output redirection log file length

I am trying to write a script which will output notifications to a logfile, but I would like to cap the logfile to, let's say, 200 lines. Specifically I am using custom firmware, DD-wrt, on my router and I am implementing a script to connect to my work vpn. I have a loop that pings a computer... (2 Replies)
Discussion started by: joemommasfat
2 Replies

4. Shell Programming and Scripting

opening new instance of cygwin from withing cygwin

I'm using cygwin on win7, What I would like to do is something like this: cygstart cygwin tail -f /foo/test.log | perl -pe 's/error/\e I know I can start a new instance using either of these: mintty -e ... cygstart tail ... But neither of those open in ANSI mode, so I can't do... (0 Replies)
Discussion started by: Validatorian
0 Replies

5. Shell Programming and Scripting

stderr redirection not working

I am running tcsh/csh shell on my machine. lately i have realized my stderr file redirection is not working. Please find the terminal logs as below: >echo b c >>& log >cat log b c >echo $a b c >>& log a: Undefined variable. >cat log b c I have never faced such issues, hence not sure... (5 Replies)
Discussion started by: animesharma
5 Replies

6. Shell Programming and Scripting

SED on cygwin not working with Hex or Octal

Hi, I have downloaded a web page that I need to cleanup before passing to xmlstarlet. Using UltraEdit's HEX utility part of my download is as follows: 3C 2F 61 3E 0A 09 0A 09 09 3C 2F 61 3E which in ASCII is </a> </a> I need to locate this string and replace it with just... (7 Replies)
Discussion started by: dazhoop
7 Replies

7. Shell Programming and Scripting

Command output redirection in script not working

I need to count the number of lines in a .txt file and put it in a variable. I am using the following code #!/bin/bash count = $(wc -l "some file.txt" | awk '{print$1}') echo $count It is giving the following error. line3: count: command not foundWhat am I doing wrong here? :confused: (7 Replies)
Discussion started by: haritha.gorijav
7 Replies

8. UNIX and Linux Applications

Cygwin application not working on my machine.

I have windows XP machine. Today i have tried to install Cygwin, I've downloaded all the packages then ran the setup. It's showed completed. But when i try to open this it's not working. Do i need to do anything extra for this..? Please help... (3 Replies)
Discussion started by: pamu
3 Replies

9. Red Hat

Log Redirection to Remote Host

hey, I need your help. I have a rhel server that runs application, that application writing to her local application log. I want that log will be realtime copying to a another remote rhel server. The thing is that I prohibited touch the application code. Is that possible? ... (5 Replies)
Discussion started by: moshesa
5 Replies

10. Shell Programming and Scripting

>& redirection not working within csh script

I'm having a strange problem with basic >& output redirection to a simple log file in csh. When I run this particular output redirection on the command line, it works, but then when I run the same output redirection command >& in my c shell script, I get a blank log file. Nothing is output to the... (5 Replies)
Discussion started by: silencio
5 Replies
All times are GMT -4. The time now is 10:06 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy