![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Checking condition inside the loop | ithirak17 | Shell Programming and Scripting | 1 | 03-13-2008 08:37 AM |
| running sed inside script file | bajaj111 | UNIX for Dummies Questions & Answers | 4 | 11-08-2006 06:58 AM |
| how to find Script file location inside script | asami | Shell Programming and Scripting | 10 | 03-15-2006 12:57 AM |
| Script to check for a file, check for 2hrs. then quit | mmarsh | UNIX for Dummies Questions & Answers | 2 | 09-16-2005 03:46 PM |
| awk script to split a file based on the condition | superprogrammer | Shell Programming and Scripting | 12 | 06-14-2005 04:59 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
script to check for a condition inside a file
Hi
I am writing a script file which sends the log files along with their size in a folder named log to a file called temp.log using the following cmd: ls -st 190_GSTV_HUX_003QISCGSK026** >> /home/user/temp.log the temp.log looks like this: 16 190_GSTV_HUX_003QISCGSK026_message070321.log 21 190_GSTV_HUX_003QISCGSK026_activity070321.log 10 190_GSTV_HUX_003QISCGSK026_error070321.log now i need to write a script which checks for the error log file size inside the temp.log ie., i need to check if the error log file(190_GSTV_HUX_003QISCGSK026_error070321.log) size is zero or not from the file temp.log is there any cmd to do the same? any help is greatly appreciated thanks in advance!! Last edited by kiran1112; 03-21-2007 at 06:59 AM.. |
|
||||
|
Hi,
not sure whether I understood your problem properly...You can do something like this if u want to take out size and filename seperately .. ls -st GSTV_error** >> /home/user/temp.log cat temp.log | awk -F" " 'NR >1 {print "File "$2 " Size "$1 ;}' or you can go for while read line do { file=$(echo $line| cut -f1) size=$(echo $line| cut -f2) echo "$file $size" if [ "$file" = "something" -a $size -eq val ] then ...do something.. fi } done <temp |
|
||||
|
Ok.Try something like below then...
ls -st >temp while read line do { file=$(echo $line| cut -f2 -d" ") size=$(echo $line| cut -f1 -d" ") if [ "$file" = "190_GSTV_HUX_003QISCGSK026_error070321.log" -a $size -gt 0 ] then echo "$file and $size" #or do whatever you want to do with that.. fi } done <temp Last edited by dennis.jacob; 03-21-2007 at 07:14 AM.. |
|
||||
|
Hi
many thanks for ur quick reply... i am trying to do this: ls -st 190_GSTV_HUX** >> /home/gaaadmin/GAAAdapter/gskgaa/test.log cd .. check=`awk 'NR == 6 {print $1}' test.log` if [ $check -eq 0 ] then echo "noerror" else echo "error present" fi but the thing is this condition checks only for the first line in test.log which may or may not be the error log file ... so my quwstion is how do we get it to check only for the filename which contains error... hope i m not confusing you thanks |
|
||||
|
If you just want to display those files with zero size,
go for this... awk '{if ($1>0) {print "no errors in "$2; }else{ print "Error in "$2;}} temp.log Or if you can use the below approch to tackle this.. while read line do { file=$(echo $line| cut -f2 -d" ") size=$(echo $line| cut -f1 -d" ") if [ "$file" = "190_GSTV_HUX_003QISCGSK026_error070321.log" -a $size -gt 0 ] then echo "$file and $size" #or do whatever you want to do with that.. fi } done <temp |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|