Why is this script not working?

 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers Why is this script not working?
# 1  
Old 01-09-2017
Why is this script not working?

Code:
for file in $(find /home/p611568/*.rpt -mtime -2 | grep -v ftplog)
 do
   awk '$1 == "XifPages," {PAGE = $5}
        $1 == "XifEndOfDocuments," {LINE = $5}
        index($0,"Value") && index($1,"Info") {sevGTI = 1}
        END {if (sevGTI)
                printf "%7s%10s%s",PAGE,LINE
        }
       ' $file>>/home/p611568/new.txt
       chmod 775 /home/p611568/new.txt
done

Moderator's Comments:
Mod Comment Please use CODE tags when displaying sample input, sample output, and code segments.

Last edited by Don Cragun; 01-09-2017 at 03:05 PM.. Reason: Add CODE tags again.
# 2  
Old 01-09-2017
Wouldn't it be nice if you told us WHAT is not working, for WHAT input data?
# 3  
Old 01-09-2017
Given that you haven't shown us what input this script is processing, what output you are hoping to produce, what diagnostic messages are being produced when you run this script, told us what shell you're using, nor told us what operating system you're using, it is hard to guess at what might be wrong other than to note that the format string in the printf call in your awk code tries to print three strings but is only given two variables to be printed by that format string. And, of course, all of your printed page and line numbers will be on a single partial line since no <newline> character will be printed by anything in your script.
# 4  
Old 01-09-2017
sorry the file in am inputting is anything that ends with .rpt
Code:
home/p611568/d2e/logs/*.rpt


I have to pull these four lines out from the file:

Code:
 Info    ApplicationParmValues(Job)      Application Parameters...Name = gpad135


and gpad135 (print $6) and name it job name


Code:
 Total XifPages                              1                     1                     1                     1 

From the last field 1 (print $6) and name it pages

Code:
Total XifEndOfDocuments             1                  1             1                    1      

from the last field 1(print $6) and name it as lines

Code:
Info    GenericInfo(Job)        CompletionCode: Value=0, Description=The task has completed successfully without errors

the code I have to revise is:

Code:
 [for file in $(find /home/p611568/d2e/logs/*.rpt -mtime -2 | grep -v ftplog)
 do
 
 awk '$1 == "Monday," {DATE = $2 $3 $4}
        $1 == "Monday," {TIME = $6}
        $1 == "Tuesday," {DATE = $2 $3 $4}
        $1 == "Tuesday," {TIME = $6}
        $1 == "Wednesday," {DATE = $2 $3 $4}
        $1 == "Wednesday," {TIME = $6}
        $1 == "Thursday," {DATE = $2 $3 $4}
        $1 == "Thursday," {TIME = $6}
        $1 == "Friday," {DATE = $2 $3 $4}
        $1 == "Friday," {TIME = $6}
        $1 == "Saturday," {DATE = $2 $3 $4}
        $1 == "Saturday," {TIME = $6}
        $1 == "Sunday," {DATE = $2 $3 $4}
        $1 == "Sunday," {TIME = $6}
        $1 == "Info" {QName = $6}
#       $1 == "Info" {Value = $4}
        $1 == "XifPages" {pages = $6}
        $1 == "Value" {Value = $4}
        index($0,"Value") && index($1,"Info") {sevGTI = 1}
        END {if (sevGTI)
                printf "%20s%10s%10s%20s%10s%10s%s",DATE,TIME,QName,pages,Value,ORS
        }
       ' $file>>/home/p611568/xenoshistory.txt
       chmod 775 /home/p611568/xenoshistory.txt
done]

I have revised it several times but NOTHING I do seems to work. Please advise. thanks. I am a beginner at writing scripts and any input you could give me I would appreciate it.


Moderator's Comments:
Mod Comment Please use CODE tags as required by forum rules!
You risk to be set to read only or even banned if you continue ignoring these requests!

And, don't overuse colours instead of code tags.

Last edited by RudiC; 01-09-2017 at 05:42 PM.. Reason: Added CODE tags.
# 5  
Old 01-09-2017
Your specification is very difficult to understand; I give up. Some comments:
- None of the sample input lines you posted has a weekday.
- None of the $1 has any of the Xif... values.
- Is PAGE in post#1 the same as pages in post#4?
- Is "job name" the same as QNAME?
- still yout printf format string has one more format specifier than variables to print.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help with speeding up my working script to take less time - how to use more CPU usage for a script

Hello experts, we have input files with 700K lines each (one generated for every hour). and we need to convert them as below and move them to another directory once. Sample INPUT:- # cat test1 1559205600000,8474,NormalizedPortInfo,PctDiscards,0.0,Interface,BG-CTA-AX1.test.com,Vl111... (7 Replies)
Discussion started by: prvnrk
7 Replies

2. Shell Programming and Scripting

Script not working

Hi i have write the one scripts and the scripts is error. The scripts purpose select one directory to check the file is there or not. i will give the two format of file to search the mention the path one file is there to select the file one copy the another location.please check the my script give... (1 Reply)
Discussion started by: rajivgandhi
1 Replies

3. UNIX for Dummies Questions & Answers

My script is not working

Hi All, I am trying to calculate the total_amount based on two key fields. Here is the script. I am new to unix. So please help me to find out the error in this script. I'm getting error like "command not found" and ]; is missing.. PRE_LBNO=0 PRE_DATE=0 TOT_PAY=0 for line in `cat... (4 Replies)
Discussion started by: lathanandhini
4 Replies

4. Shell Programming and Scripting

expect script inside shell script not working.

Shell Scipt: temp.sh su - <$username> expect pass.exp Expect script: pass.exp #!/usr/bin/expect -f # Login ####################### expect "Password: " send "<$password>\r" it comes up with Password: but doesnt take password passed throguh file. (2 Replies)
Discussion started by: bhavesh.sapra
2 Replies

5. Shell Programming and Scripting

Script not working in cron but working fine manually

Help. My script is working fine when executed manually but the cron seems not to catch up the command when registered. The script is as follow: #!/bin/sh for file in file_1.txt file_2.txt file_3.txt do awk '{ print "0" }' $file > tmp.tmp mv tmp.tmp $file done And the cron... (2 Replies)
Discussion started by: jasperux
2 Replies

6. Shell Programming and Scripting

Script is not working from cron while working manually

Hello, I am facing a very strange problem when I run my script manuallu ./Fetchcode which is using to connect with MKS integrity from linux end it workks fine but when I run it from cron it doesn't work.Can someone help me 1) How could I check my script when it is running from cron like... (3 Replies)
Discussion started by: anuragpgtgerman
3 Replies

7. Shell Programming and Scripting

HELP !! script not working..

Hi all, I have a piece of code which cork perfect. It copy the no of lines from some files (*.log) into finalLog file. It read the lines after the line have text "ntot". Here it is : #!/bin/bash ... (10 Replies)
Discussion started by: nrjrasaxena
10 Replies

8. UNIX for Dummies Questions & Answers

script not working

hi guys im new to unix and what to get this script working the scripts purpose its purpose is to move files i copy it from a HP UX pdf just for practice but when i execute it comes up wit this error command not found on the line if plz help me and thank in advance to those who do ps im... (3 Replies)
Discussion started by: ShinTec
3 Replies

9. Shell Programming and Scripting

Perl script 'system' linking to local shell script not working

Trying to figure out why this works: printpwd.pl #!/usr/bin/perl use CGI::Carp qw( fatalsToBrowser ); print "Content-type: text/html\n\n"; $A = system("pwd"); $A = `pwd`; print "$A\n"; ^^actually that works/breaks if that makes any sense.. i get the working directory twice but when... (5 Replies)
Discussion started by: phpfreak
5 Replies

10. Shell Programming and Scripting

Script not working..."sort" not working properly....

Hello all, I have a file - 12.txt cat 12.txt =============================================== Number of executions = 2 Total execution time (sec.ms) = 0.009883 Number of executions = 8 Total execution time (sec.ms) = 0.001270 Number of... (23 Replies)
Discussion started by: Rahulpict
23 Replies
Login or Register to Ask a Question