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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
|
02-08-2012, 02:07 PM
|
#1
|
Senior Member
Registered: May 2010
Location: Palm Island
Distribution: RHEL, CentOS, Debian, Oracle Solaris 10
Posts: 1,420
|
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.
|
02-08-2012, 02:18 PM
|
#2
|
LQ Guru
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 27,576
|
Quote:
Originally Posted by Satyaveer Arya
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.
|
02-08-2012, 02:21 PM
|
#3
|
Member
Registered: Feb 2009
Location: 192.168.x.x
Distribution: Slackware
Posts: 852
|
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.
|
02-08-2012, 02:48 PM
|
#4
|
Senior Member
Registered: May 2010
Location: Palm Island
Distribution: RHEL, CentOS, Debian, Oracle Solaris 10
Posts: 1,420
Original Poster
|
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.
|
02-08-2012, 02:52 PM
|
#5
|
Senior Member
Registered: Jul 2004
Distribution: Slackware
Posts: 2,140
|
What output did you expect from the script ?
|
|
1 members found this post helpful.
|
02-08-2012, 02:58 PM
|
#6
|
Senior Member
Registered: May 2010
Location: Palm Island
Distribution: RHEL, CentOS, Debian, Oracle Solaris 10
Posts: 1,420
Original Poster
|
Quote:
What output did you expect from the script ?
|
I expected that the script should run properly and give the correct output.
|
|
|
02-08-2012, 02:59 PM
|
#7
|
Senior Member
Registered: Jul 2004
Distribution: Slackware
Posts: 2,140
|
And what is the correct output you expect when you redirect output to /tmp/sarg-reports.*.errors ?
|
|
1 members found this post helpful.
|
02-08-2012, 03:04 PM
|
#8
|
LQ Guru
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 27,576
|
Quote:
Originally Posted by Satyaveer Arya
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.
|
02-08-2012, 03:15 PM
|
#9
|
Senior Member
Registered: May 2010
Location: Palm Island
Distribution: RHEL, CentOS, Debian, Oracle Solaris 10
Posts: 1,420
Original Poster
|
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. 
|
|
|
02-08-2012, 03:32 PM
|
#10
|
Senior Member
Registered: May 2010
Location: Palm Island
Distribution: RHEL, CentOS, Debian, Oracle Solaris 10
Posts: 1,420
Original Poster
|
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.
|
|
|
02-08-2012, 03:37 PM
|
#11
|
Senior Member
Registered: Jul 2004
Distribution: Slackware
Posts: 2,140
|
Quote:
Originally Posted by Satyaveer Arya
This is what I run all step by step:
But no output. 
|
... which it is to be expected when redirecting output to a file 
|
|
|
02-08-2012, 03:37 PM
|
#12
|
LQ Guru
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 27,576
|
Quote:
Originally Posted by Satyaveer Arya
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.
|
02-09-2012, 11:51 AM
|
#13
|
Senior Member
Registered: May 2010
Location: Palm Island
Distribution: RHEL, CentOS, Debian, Oracle Solaris 10
Posts: 1,420
Original Poster
|
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.
|
02-09-2012, 12:00 PM
|
#14
|
Senior Member
Registered: Jul 2004
Distribution: Slackware
Posts: 2,140
|
Sorry, but can you understand this:
कार्यक्रम एक फाइल में उत्पादन का उत्पादन

|
|
1 members found this post helpful.
|
02-09-2012, 12:19 PM
|
#15
|
Senior Member
Registered: May 2010
Location: Palm Island
Distribution: RHEL, CentOS, Debian, Oracle Solaris 10
Posts: 1,420
Original Poster
|
Quote:
Sorry, but can you understand this:
कार्यक्रम एक फाइल में उत्पादन का उत्पादन
|
I can understand this, but what exactly you want to say?
|
|
|
All times are GMT -5. The time now is 08:07 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|