ProgrammingThis 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.
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.
Distribution: RHEL, CentOS, Debian, Oracle Solaris 10
Posts: 1,415
Rep:
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
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?
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.
[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.
Distribution: RHEL, CentOS, Debian, Oracle Solaris 10
Posts: 1,415
Original Poster
Rep:
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.
...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/
# 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?
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.