Need to write a shell script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need to write a shell script
# 1  
Old 07-11-2012
Need to write a shell script

Hi, I need some help to write a script
i need to write script that will count the no of logs generated for the day and specify the logfiles names which is not generated for the day.
Default no of log generate per day is 29
if less than 29 logs generated it should specify the perticular logfile name.
The lofiles are like
a.log
b.log
c.log

The logs are generated everyday in a perticular directory location and with datestamp like (Jul 10) (Jul 9) etc.
# 2  
Old 07-11-2012
What have you done??
# 3  
Old 07-11-2012
I have wrote a script like this:


Code:
#!/bin/sh
Date=`date +"%b %d"`
cd /prod/logs
printf "No of log files are\n"
ls -ltr |grep "$Date"|wc -l
ls -ltr |grep "$Date"|awk '{print $9}'>>b.txt
mv b.txt /home/sid_ap
cd /home/sid_ap
printf "No log file for\n"
comm -13 a.txt b.txt


But this is not showing the proper o/p for dates like Jul 1, Jul 2.
However, i am getting the o/p fine for Jul 10, Jul 11 .
Also when it compares the two files (a.txt and b.txt) it is giving o/p b.txt as default.

---------- Post updated at 03:51 PM ---------- Previous update was at 03:24 PM ----------

I have corrected the date problem using %e instead of %d.
can some one help me out why the b.txt coming as o/p when i am comparing the 2 files.
i am getting a o/p like this :

Code:
No of log files are
29
No log file for
b.txt


Though a.txt and b.txt contains same no of logfiles i am getting b.txt as o/p.

Last edited by Scrutinizer; 07-11-2012 at 07:51 AM.. Reason: code tags
# 4  
Old 07-11-2012
use
Code:
grep -v -f a.txt b.txt

in place of comm

Last edited by Scott; 07-11-2012 at 11:10 AM.. Reason: Code tags
# 5  
Old 07-12-2012
Thanks,
but it is not resolving the problem. gives me the same o/p.
i got the problem
Code:
ls -ltr |grep "$Date"|awk '{print $9}'>>b.txt

this line of code is adding an extra value b.txt to the file b.txt. Thats why the o/p is coming like this.
Can anybody tell me why it is coming? or how can i rectify that?

Last edited by Franklin52; 07-12-2012 at 04:54 PM.. Reason: Please use code tags for data and code samples, thank you
# 6  
Old 07-12-2012
please provide the output
# 7  
Old 07-12-2012
you could just exclude that file,

Code:
 ls -ltr | grep "$Date" | grep -v b.txt | awk '{print $9}'>>b.txt

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Please help me to write the shell script

Please help me to write the shell script AC|NAME|STATE|MAXVALUE|MINVALUE---------heading 111|UMA|ODISHA|123,00.00|54.00 111|UMA|ODISHA|124,00.00|25.00 111|UMA|ODISHA|114,00.00|58.00 111|UMA|ODISHA|104,00.00|00.00 111|UMA|ODISHA|194,00.00|19.00 111|UMA|ODISHA|184,00.00|64.00... (5 Replies)
Discussion started by: alokjyotibal
5 Replies

2. Shell Programming and Scripting

How to write config shell script to pass variables in master shell script?

Dear Unix gurus, We have a config shell script file which has 30 variables which needs to be passed to master unix shell script that invokes oracle database sessions. So those 30 variables need to go through the database sessions (They are inputs) via a shell script. one of the variable name... (1 Reply)
Discussion started by: dba1981
1 Replies

3. UNIX for Dummies Questions & Answers

How to write Config shell script to pass variables in master shell script?

Dear Unix gurus, We have a config shell script file which has 30 variables which needs to be passed to master unix shell script that invokes oracle database sessions. So those 30 variables need to go through the database sessions (They are inputs) via a shell script. one of the variable name... (1 Reply)
Discussion started by: dba1981
1 Replies

4. Shell Programming and Scripting

Need to write a shell script

Hi, I need to write a statement which will read a data from a specific line based on condition and then read related lines to delete. For example: |T20150322 100930290 208940000 598000080 700000000 930000202 100000000 .T56789 |T20150322 0100000000 0200000000 0500000000 9000000000... (1 Reply)
Discussion started by: abhi.mit32
1 Replies

5. Shell Programming and Scripting

Help shell script to write

Hi All, How to write a shell script 1. i have file name "/home/krupa"(krupa) 2. i have to wite a shell scripting , 3.script will not execute until reach "krupa" file in the location "/home/krupa"(krupa) and it will wait or go to sleep mode 3. if already "krupa" is there then execute the... (4 Replies)
Discussion started by: krupasindhu18
4 Replies

6. Shell Programming and Scripting

how to write shell script

Hi , i need to write a script like this In 1.sh ./test.sh wait(5sec) send ctrl+C to server ./testxxxx.sh first i need invoke test.sh from 1.sh , after wating for some time i need to close the test.sh script & i need to start new script i tried to invoke script... (2 Replies)
Discussion started by: pvr_satya
2 Replies

7. Shell Programming and Scripting

Need to Write Shell Script based off of this shell command

I'm trying to read a bunch of log files and output the lines that contain particular strings. To accomplish this, I've been running the following from the command line: find . -name "*" | xargs grep " " | grep " " > output.txt Two grep statements are needed in case I'm looking for a... (3 Replies)
Discussion started by: Rally_Point
3 Replies

8. Shell Programming and Scripting

I need to write a shell script.

Hi Guys, I need to write a shell script, to which I have getting results from CPU and Memory Utilization. This is to generate automatically through Shell script by running cron job. Is it possible to write it. I am new to this shell scripting. Can you please help me on this ASAP. ... (6 Replies)
Discussion started by: lakshmanrk
6 Replies

9. Shell Programming and Scripting

please Write a shell script

Hi Team, I am unable to write script. please guide me. My rquirement is as given below one file will have three columns with n number of rows like hostname port sid -------- ---- --- sun056 1527 PSP1 sun111 1529 PRP1 sun107 1580 PRD1 the script should... (6 Replies)
Discussion started by: rvrao77
6 Replies

10. Shell Programming and Scripting

need help to write shell script

. I wrote shell script with help to extract data and generate report . I need help to modify that in sub section . Currently I am generating the report in this format Version Name Host Total Number of Fails 10 Animator 45 10 Krachel ... (0 Replies)
Discussion started by: getdpg
0 Replies
Login or Register to Ask a Question