multiple output redirection in linux

Whether you are using Linux on the desktop or as a server, it's still good that you're using Linux. Linux related questions go here.

Moderator: General Moderators

Post Reply
akkad
Forum Newbie
Posts: 14
Joined: Tue Jul 31, 2007 4:09 am

multiple output redirection in linux

Post by akkad »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


ok let met explain the problem from begining :

in my page i have forms that allow the user to chose the report month and year and when the user will submit that the page will bring a full report of his traffic on that time.
what i want to do is that :
when the user will chose the month the code will search in the log files created on that time and send their contents tot calamaris for specific user:

<code>

Code: Select all

echo shell_exec("cat `ls `find ./logs -name access.log.* ` -l | grep May |  awk '{print $9}'`| grep akadi_icho | /usr/bin/perl  ./calamaris/calamaris -a -P 60 -T 0 -r 400 -d 500 -u -O -F html");
</code>

but because the following command:

<code>

Code: Select all

ls ./logs -l | grep May | awk '{print $9}'
access.log.81
access.log.82
access.log.86
</code>
it is not giving the path so the cat can't be executed (here i put for May just as example ), so i have used the command in this way combined with find command to get the path of the files:
<code>

Code: Select all

ls `find ./logs -name access.log.*` -l | grep May | awk '{print $9}'
./logs/access.log.81
./logs/access.log.82
./logs/access.log.86
</code>

now i want to send the contents of this file to calamaris for specific user such akadi_icho, but i don't know why cat is not working so , i tried the following way:

<code>

Code: Select all

cat ./logs/`ls ./logs -l | grep May | awk '{print $9}'` | grep saro_der_avanesian 

output is :
ages/letters/black/239.gif saro_der_avanesian FIRST_PARENT_MISS/proxy.aic.net image/gif
1178460942.330    848 10.2.0.181 TCP_MISS/200 459 GET http://www.google-analytics.com/__utm.gif? saro_der_avanesian FIRST_PARENT_MISS/proxy.aic.net image/gif
cat: access.log.82: No such file or directory
cat: access.log.86: No such file or directory
</code>
it is searching in the first file just , [s]u[/s] you can see that it didn't iterate for the second and third file , so what should i do .


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

[quote="[url=http://forums.devnetwork.net/viewtopic.php?t=30037]Forum Rules[/url] Section 1.1"][b]11.[/b] Please use proper, complete spelling when posting in the forums. AOL Speak, leet speak and other abbreviated wording can confuse those that are trying to help you (or those that you are trying to help). Please keep in mind that there are many people from many countries that use our forums to read, post and learn. They do not always speak English as well as some of us, nor do they know these aberrant abbreviations. Therefore, use as few abbreviations as possible, especially when using such simple words.

Some examples of what not to do are ne1, any1 (anyone); u (you); ur (your or you're); 2 (to too); prolly (probably); afaik (as far as I know); etc.[/quote]
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Post by VladSun »

Code: Select all

ls ./logs -l | grep May | awk '{print $9}'
access.log.81
access.log.82
access.log.86 

 cat ./logs/`ls ./logs -l | grep May | awk '{print $9}'` | grep saro_der_avanesian 

=>

cat ./logs/access.log.81 access.log.82 access.log.86 .......
You can see that you have only the first file with a right path specified. It's a better way to write a bash script file and execute it.
E.g.:

Code: Select all

#!/bin/bash

for f in `ls ./logs | grep "$1" | grep "$2"`; do
  echo $f
done
where $1 and $2 are month and name arguments passed to the script.
There are 10 types of people in this world, those who understand binary and those who don't
Post Reply