LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-08-2012, 02:07 PM   #1
Satyaveer Arya
Senior Member
 
Registered: May 2010
Location: Palm Island
Distribution: RHEL, CentOS, Debian, Oracle Solaris 10
Posts: 1,420

Rep: Reputation: 305Reputation: 305Reputation: 305Reputation: 305
A script is not giving any output.


Hi,

I have tried this below mentioned script for creating sarg weekly report. I checked this script by running manually and ends up with no output. Can anyone please tell me that what's wrong with this script? Is there any error in this script?

Quote:
#!/bin/sh
# Following are the variable for the date

TODAY=$(date --date "today" +%d/%m/%Y)
YESTERDAY=$(date --date "1 day ago" +%d/%m/%Y)
WEEKAGO=$(date --date "1 week ago" +%d/%m/%Y)
MONTHAGO=$(date --date "1 month ago" +%d/%m/%Y)

# Location of the log files
LOGDIR=/var/log/squid/

# Filter out the lastest 2 log files based on modified date
LATEST2=`ls -lt $LOGDIR | grep -v "total" | head -n 2 | awk '{print $8}'`

# Location for creating error report file
TMPFILE=/tmp/sarg-reports.$RANDOM
ERRORS="${TMPFILE}.errors"

FILES=`for i in $LATEST2 ; do echo -n "-l $LOGDIR$i "; done`

#This is for sarg weekly report
/usr/bin/sarg $FILES -xz -d $WEEKAGO >$ERRORS 2>&1
I'm not good in shell scripting, so I don't know what's wrong with this script.

Last edited by Satyaveer Arya; 02-08-2012 at 02:18 PM.
 
Click here to see the post LQ members have rated as the most helpful post in this thread.
Old 02-08-2012, 02:18 PM   #2
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 27,576

Rep: Reputation: 8134Reputation: 8134Reputation: 8134Reputation: 8134Reputation: 8134Reputation: 8134Reputation: 8134Reputation: 8134Reputation: 8134Reputation: 8134Reputation: 8134
Quote:
Originally Posted by Satyaveer Arya View Post
Hi,
I have tried this below mentioned script for creating sarg weekly report. I checked this script by running manually and ends up with no output. Can anyone please tell me that what's wrong with this script? Is there any error in this script?
Maybe look through your other two threads, about Sarg problems first:
http://www.linuxquestions.org/questi...g-tool-918310/
http://www.linuxquestions.org/questi...server-927079/

And if the script doesn't generate any output, or any errors, what do you think we'll be able to tell you?? As before, and with ANY shell script, run through it one line at a time, and run each command manually from a terminal. See if they return what you think they will. If you did, you'd see the error in the LASTEST2 variable.

Please try to follow advice others have given you, and do some basic troubleshooting on your own.
Quote:
Originally Posted by Satyaveer Arya
I'm not good in shell scripting, so I don't know what's wrong with this script.
..and until you read any of the scripting tutorials, or do any debugging/troubleshooting on your own, you never will be good at it.

Last edited by TB0ne; 02-08-2012 at 02:20 PM.
 
1 members found this post helpful.
Old 02-08-2012, 02:21 PM   #3
millgates
Member
 
Registered: Feb 2009
Location: 192.168.x.x
Distribution: Slackware
Posts: 852

Rep: Reputation: 389Reputation: 389Reputation: 389Reputation: 389
Hi, what is the output of this line?

Code:
ls -lt $LOGDIR | grep -v "total" | head -n 2 | awk '{print $8}'
depending on your ls implementation you may need to change {print $8} to {print $9}

Last edited by millgates; 02-08-2012 at 02:23 PM.
 
2 members found this post helpful.
Old 02-08-2012, 02:48 PM   #4
Satyaveer Arya
Senior Member
 
Registered: May 2010
Location: Palm Island
Distribution: RHEL, CentOS, Debian, Oracle Solaris 10
Posts: 1,420

Original Poster
Rep: Reputation: 305Reputation: 305Reputation: 305Reputation: 305
Hello millgates,

Here is the output of this line:

Quote:
[root@proxy weekly]# ls -lt $LOGDIR | grep -v "total" | head -n 2 | awk '{print $8}'
02:20
02:20
[root@proxy weekly]#
And when I used this:

Quote:
[root@proxy weekly]# ls -lt $LOGDIR | grep -v "total" | head -n 2 | awk '{print $9}'
access.log
store.log
[root@proxy weekly]#
is gives this output.

Last edited by Satyaveer Arya; 02-08-2012 at 02:54 PM.
 
2 members found this post helpful.
Old 02-08-2012, 02:52 PM   #5
Cedrik
Senior Member
 
Registered: Jul 2004
Distribution: Slackware
Posts: 2,140

Rep: Reputation: 244Reputation: 244Reputation: 244
What output did you expect from the script ?
 
1 members found this post helpful.
Old 02-08-2012, 02:58 PM   #6
Satyaveer Arya
Senior Member
 
Registered: May 2010
Location: Palm Island
Distribution: RHEL, CentOS, Debian, Oracle Solaris 10
Posts: 1,420

Original Poster
Rep: Reputation: 305Reputation: 305Reputation: 305Reputation: 305
Quote:
What output did you expect from the script ?
I expected that the script should run properly and give the correct output.
 
Old 02-08-2012, 02:59 PM   #7
Cedrik
Senior Member
 
Registered: Jul 2004
Distribution: Slackware
Posts: 2,140

Rep: Reputation: 244Reputation: 244Reputation: 244
And what is the correct output you expect when you redirect output to /tmp/sarg-reports.*.errors ?
 
1 members found this post helpful.
Old 02-08-2012, 03:04 PM   #8
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 27,576

Rep: Reputation: 8134Reputation: 8134Reputation: 8134Reputation: 8134Reputation: 8134Reputation: 8134Reputation: 8134Reputation: 8134Reputation: 8134Reputation: 8134Reputation: 8134
Quote:
Originally Posted by Satyaveer Arya View Post
Hello millgates,
Here is the output of this line:
Code:
[root@proxy weekly]# ls -lt $LOGDIR | grep -v "total" | head -n 2 | awk '{print $8}'
02:20
02:20
And when I used this:
Code:
[root@proxy weekly]# ls -lt $LOGDIR | grep -v "total" | head -n 2 | awk '{print $9}'
access.log
store.log
is gives this output.
Are you joking, or are you being serious? Yes, that's why I told you to look at that line in my first reply, as did millgates. Can you not understand what that variable line is returning to you?

What are you wanting to get from that variable?? That would be the FILE NAME. The $8 is returning the FILE TIME, so when you change it to $9, it will magically return the correct information.

Again, As before, and with ANY shell script, run through it one line at a time, and run each command manually from a terminal. See if they return what you think they will. If you did, you'd see the error in the LASTEST2 variable. Please try to follow advice others have given you, and do some basic troubleshooting on your own. Have you tried to read/follow/understand ANY of the shell-scripting guides, or advice given to you in other threads, where you're having problems with shell-scripts??
Quote:
Originally Posted by Satyaveer Arya
It's not that I'm smart, it's just that I stay with problems longer.
Really????
 
1 members found this post helpful.
Old 02-08-2012, 03:15 PM   #9
Satyaveer Arya
Senior Member
 
Registered: May 2010
Location: Palm Island
Distribution: RHEL, CentOS, Debian, Oracle Solaris 10
Posts: 1,420

Original Poster
Rep: Reputation: 305Reputation: 305Reputation: 305Reputation: 305
TBOne,

Quote:
Are you joking, or are you being serious? Yes, that's why I told you to look at that line in my first reply, as did millgates. Can you not understand what that variable line is returning to you?
I told you earlier that I'm not good in shell scripting. Infact, gradually I'm learning shell scripting, that's why I didn't know this below:

Quote:
What are you wanting to get from that variable?? That would be the FILE NAME. The $8 is returning the FILE TIME, so when you change it to $9, it will magically return the correct information.
Quote:
It's not that I'm smart, it's just that I stay with problems longer.
Only in the case of shell scripting.
 
Old 02-08-2012, 03:32 PM   #10
Satyaveer Arya
Senior Member
 
Registered: May 2010
Location: Palm Island
Distribution: RHEL, CentOS, Debian, Oracle Solaris 10
Posts: 1,420

Original Poster
Rep: Reputation: 305Reputation: 305Reputation: 305Reputation: 305
This is what I run all step by step:

Quote:
[root@proxy weekly]# WEEKAGO=$(date --date "1 week ago" +%d/%m/%Y)
[root@proxy weekly]# echo $WEEKAGO
02/02/2012
[root@proxy weekly]# LOGDIR=/var/log/squid/
[root@proxy weekly]# echo $LOGDIR
/var/log/squid/
[root@proxy weekly]# LATEST2=`ls -lt $LOGDIR | grep -v "total" | head -n 2 | awk '{print $9}'`
[root@proxy weekly]# echo $LATEST2
access.log store.log
[root@proxy weekly]# TMPFILE=/tmp/sarg-reports.$RANDOM
[root@proxy weekly]# echo $TMPFILE
/tmp/sarg-reports.22070
[root@proxy weekly]# ERRORS="${TMPFILE}.errors"
[root@proxy weekly]# echo $ERRORS
/tmp/sarg-reports.22070.errors
[root@proxy weekly]# FILES=`for i in $LATEST2 ; do echo -n "-l $LOGDIR$i "; done`
[root@proxy weekly]# echo $FILES
-l /var/log/squid/access.log -l /var/log/squid/store.log
[root@proxy weekly]# /usr/bin/sarg $FILES -xz -d $WEEKAGO >$ERRORS 2>&1
[root@proxy weekly]#
But no output.

I think still something wrong in this part:
Quote:
[root@proxy weekly]# echo $FILES
-l /var/log/squid/access.log -l /var/log/squid/store.log
because sarg takes access.log file, not store.log file. Isn't it?

Last edited by Satyaveer Arya; 02-08-2012 at 03:35 PM.
 
Old 02-08-2012, 03:37 PM   #11
Cedrik
Senior Member
 
Registered: Jul 2004
Distribution: Slackware
Posts: 2,140

Rep: Reputation: 244Reputation: 244Reputation: 244
Quote:
Originally Posted by Satyaveer Arya View Post
This is what I run all step by step:



But no output.
... which it is to be expected when redirecting output to a file
 
Old 02-08-2012, 03:37 PM   #12
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 27,576

Rep: Reputation: 8134Reputation: 8134Reputation: 8134Reputation: 8134Reputation: 8134Reputation: 8134Reputation: 8134Reputation: 8134Reputation: 8134Reputation: 8134Reputation: 8134
Quote:
Originally Posted by Satyaveer Arya View Post
This is what I run all step by step:
Code:
[root@proxy weekly]# WEEKAGO=$(date --date "1 week ago" +%d/%m/%Y)
[root@proxy weekly]# echo $WEEKAGO
02/02/2012
[root@proxy weekly]# LOGDIR=/var/log/squid/
[root@proxy weekly]# echo $LOGDIR
/var/log/squid/
[root@proxy weekly]# LATEST2=`ls -lt $LOGDIR | grep -v "total" | head -n 2 | awk '{print $9}'`
[root@proxy weekly]# echo $LATEST2
access.log store.log
[root@proxy weekly]# TMPFILE=/tmp/sarg-reports.$RANDOM
[root@proxy weekly]# echo $TMPFILE
/tmp/sarg-reports.22070
[root@proxy weekly]# ERRORS="${TMPFILE}.errors"
[root@proxy weekly]# echo $ERRORS
/tmp/sarg-reports.22070.errors
[root@proxy weekly]# FILES=`for i in $LATEST2 ; do echo -n "-l $LOGDIR$i "; done`
[root@proxy weekly]# echo $FILES
-l /var/log/squid/access.log -l /var/log/squid/store.log
[root@proxy weekly]# /usr/bin/sarg $FILES -xz -d $WEEKAGO >$ERRORS 2>&1
[root@proxy weekly]#
But no output.
...because the last command is getting redirected, isn't it?? Change the $8 to $9 in your shell script and run it.
Quote:
Originally Posted by Satyaveer Arya
I told you earlier that I'm not good in shell scripting. Infact, gradually I'm learning shell scripting, that's why I didn't know this below:
Only in the case of shell scripting.
...and I told you earlier that you'll NEVER be good at it, until you start DOING it, reading tutorials, and applying basic troubleshooting. The VERY FIRST POST gave you the solution....all you had to do is look at the line (and we even TOLD YOU WHAT LINE TO LOOK AT), and change the $8 to a $9. Even that's not enough.

Read shell scripting tutorials...understand what they're saying, and apply basic, common-sense troubleshooting skills. These things apply to ALL problems, not just shell scripts. Walk through things one step at a time, and figure out what's wrong.
http://tldp.org/LDP/abs/html/
 
2 members found this post helpful.
Old 02-09-2012, 11:51 AM   #13
Satyaveer Arya
Senior Member
 
Registered: May 2010
Location: Palm Island
Distribution: RHEL, CentOS, Debian, Oracle Solaris 10
Posts: 1,420

Original Poster
Rep: Reputation: 305Reputation: 305Reputation: 305Reputation: 305
Hello TBOne,

Quote:
#!/bin/sh
# Following are the variable for the date

TODAY=$(date --date "today" +%d/%m/%Y)
YESTERDAY=$(date --date "1 day ago" +%d/%m/%Y)
WEEKAGO=$(date --date "1 week ago" +%d/%m/%Y)
MONTHAGO=$(date --date "1 month ago" +%d/%m/%Y)

# Location of the log files
LOGDIR=/var/log/squid/

# Filter out the lastest 2 log files based on modified date
LATEST2=`ls -lt $LOGDIR | grep -v "total" | head -n 3 | awk '{print $9}'`

# Location for creating error report file
TMPFILE=/tmp/sarg-reports.$RANDOM
ERRORS="${TMPFILE}.errors"

FILES=`for i in $LATEST2 ; do echo -n "-l $LOGDIR$i "; done`

#This is for sarg daily report
/usr/bin/sarg $FILES -xz -d $YESTERDAY >$ERRORS 2>&1
yesterday whole night I tried this above script running manually. It was taking long enough to generate a weekly report. The script took around 5 hrs and keeps on running even then and never ended with a result.. What could be the problem?
 
1 members found this post helpful.
Old 02-09-2012, 12:00 PM   #14
Cedrik
Senior Member
 
Registered: Jul 2004
Distribution: Slackware
Posts: 2,140

Rep: Reputation: 244Reputation: 244Reputation: 244
Sorry, but can you understand this:

कार्यक्रम एक फाइल में उत्पादन का उत्पादन

 
1 members found this post helpful.
Old 02-09-2012, 12:19 PM   #15
Satyaveer Arya
Senior Member
 
Registered: May 2010
Location: Palm Island
Distribution: RHEL, CentOS, Debian, Oracle Solaris 10
Posts: 1,420

Original Poster
Rep: Reputation: 305Reputation: 305Reputation: 305Reputation: 305
Quote:
Sorry, but can you understand this:

कार्यक्रम एक फाइल में उत्पादन का उत्पादन
I can understand this, but what exactly you want to say?
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Giving output of a command as the input to another whirlpool Programming 5 09-07-2010 03:31 PM
vmstat giving corrupted output Abhishek1986 Linux - Kernel 4 05-22-2010 06:05 PM
Audigy 2 ZS not giving any output khaledaboualfa Ubuntu 1 07-19-2006 05:56 PM
fdisk -l has stopped giving output Bruce Hill Slackware 59 09-06-2004 08:14 AM
df -h is giving weird output chens_83 Linux - General 2 12-09-2002 11:32 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:07 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration