Script unusual behavior

 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers Script unusual behavior
# 1  
Old 04-18-2017
Script unusual behavior

Hello,

I have noticed some unusual behavior while running the script.
when i use below script it gives output 355.23


Code:
#!/bin/bash
ONEDAY=`date +%Y%m%d --date="1 days ago"`
cat /opt/occ/var/performance/counters_`date -d "1 day ago" +%Y%m%d`*|grep "Gy,Gy-Gy-CCR"|awk -F"," '{print $1,$7}'|awk '{if (last && $2 != last) {print last, sum; sum=0} sum=sum+ $3; last = $2} END {print last, sum}' > GY_DATA_$ONEDAY
for line in `cat GY_DATA |awk '{print $2}'`; do cv=$line; diff=`echo "$cv - $lv"|bc`;lv=$cv; echo "$diff"; done|sed '1d'|sort -g|tail -1|awk '{print $1/300}' > GY_TPS_$ONEDAY

however when i run below part manually i get different output. which is 352.12.
Code:
by saying manually I mean I pasted the content on terminal


Code:
cat /opt/occ/var/performance/counters_`date -d "1 day ago" +%Y%m%d`*|grep "Gy,Gy-CCR"|awk -F"," '{print $1,$7}'|awk '{if (last && $2 != last) {print last, sum; sum=0} sum=sum+ $3; last = $2} END {print last, sum}' > GY_DATA
for line in `cat GY_DATA |awk '{print $2}'`; do cv=$line; diff=`echo "$cv - $lv"|bc`;lv=$cv; echo "$diff"; done|sed '1d'|sort -g|tail -1|awk '{print $1/300}' > GY_TPS

now after running it manually, when i run my script again it get the same value everytime which 352.12.

now i an unable to understand why i am getting such a behavior from same content.
after running it manually once even if i rum my script n times i get the same result .

the content is same, the only difference is one is scripted and another is run manually by me.
please help and suggest me what is going wrong
# 2  
Old 04-18-2017
Please become accustomed to provide decent context info of your problem.
It is always helpful to support a request with system info like OS and shell, related environment (variables, options), preferred tools, and adequate (representative) sample input and desired output data and the logics connecting the two, to avoid ambiguities and keep people from guessing.

On the first glance, the output files are different, but input files aren't.
# 3  
Old 04-18-2017
hi Rudic,

below is the requested details

Code:
 
 lsb_release -a
LSB Version:    :base-4.0-amd64:base-4.0-noarch:core-4.0-amd64:core-4.0-noarch:graphics-4.0-amd64:graphics-4.0-noarch:printing-4.0-amd64:printing-4.0-noarch
Distributor ID: RedHatEnterpriseServer
Description:    Red Hat Enterprise Linux Server release 6.5 (Santiago)
Release:        6.5
Codename:       Santiago


sometimes it become really very difficult to explain the problem .

please let me know in case you found anything unclear.

I will try my best to explain it again
# 4  
Old 04-18-2017
Some input sample (as highlighted in my previous post)?
# 5  
Old 04-18-2017
below is the script I run

Code:
#!/bin/bash
ONEDAY=`date +%Y%m%d --date="6 days ago"`
cat /opt/occ/var/performance/counters_`date -d "6 day ago" +%Y%m%d`*|grep "Gy,Gy-Gy-CCR"|awk -F"," '{print $1,$7}'|awk '{if (last && $2 != last) {print last, sum; sum=0} sum=sum+ $3; last = $2} END {print last, sum}' > GY_DATA_$ONEDAY
for line in `cat GY_DATA |awk '{print $2}'`; do cv=$line; diff=`echo "$cv - $lv"|bc`;lv=$cv; echo "$diff"; done|sed '1d'|sort -g|tail -1|awk '{print $1/300}' > GY_TPS_$ONEDAY

this is how I run .
Code:
[root]# ./GY.sh


below is the content which I run manually by simply pasting the data on terminal.

Code:
 
  cat /opt/occ/var/performance/counters_`date -d "1 day ago" +%Y%m%d`*|grep "Gy,Gy-Gy-CCR"|awk -F"," '{print $1,$7}'|awk '{if (last && $2 != last) {print last, sum; sum=0} sum=sum+ $3; last = $2} END {print last, sum}' > GY_DATA
for line in `cat GY_DATA |awk '{print $2}'`; do cv=$line; diff=`echo "$cv - $lv"|bc`;lv=$cv; echo "$diff"; done|sed '1d'|sort -g|tail -1|awk '{print $1/300}' > GY_TPS

the concern here is if run the script I will gives values let say 355.23 after this if I paste the content on terminal it gives value 352.12.

after running it manually if I run the script again or n times also it give the 352.12.

this behavior I am not able to understand.

---------- Post updated at 01:50 PM ---------- Previous update was at 01:47 PM ----------

Code:
 
  "6 day ago"

actually "1 day ago" by mistake I type it. and I was net getting the option for edit so I am posting it
# 6  
Old 04-18-2017
Not sure how much clearer I can make it: PLEASE post a sample (i.e. a few lines) of your input data so people in here can run your commands against it. How else do you expect people to test your script and error description?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

unusual problem with cp command

I have made a simple script to zip a file then first copy it to a specific directory using cp command then move it to another directory. Files are getting generated at regular intervals in the dir. /one/two/three/four/. I have entry of my script in cron to run after every 2 min. #!/bin/sh... (9 Replies)
Discussion started by: Devesh5683
9 Replies

2. Shell Programming and Scripting

shell script behavior is strange or I'm not understanding

Hi I have wrote the small script, where $SRC=$HOME the input file is simple text file having directories in my $SRC on pre line desktop download myfiles games #!/bin/bash FILENAME=$1 ERROR_LOG="$SRC/err.$$.log" while read line do echo "########## strat Gmake $line... (6 Replies)
Discussion started by: the.reverser
6 Replies

3. HP-UX

Unusual Behavior?

Our comp-operator has come across a peculiar ‘feature'. We have this directory where we save all the reports that were generated for a particular department for only one calendar year. Currently there are 45,869 files. When the operator tried to backup that drive it started to print a flie-listing... (3 Replies)
Discussion started by: vslewis
3 Replies

4. Shell Programming and Scripting

Behavior of Bad Script in Cron Job

Hi A Ksh script is deployed in a server and executed through cronjob. If one of the line in the middle of the script fails . Are the remaining lines executed ? (3 Replies)
Discussion started by: Sivaswami
3 Replies

5. Shell Programming and Scripting

Script is showing abnormal behavior...

Hi, facing unusual problem, below are 2 same scripts, one is working and other is not. please help --- THIS SCRIPT IS WORKING FINE!!!! #! /bin/sh phone=`grep "<phone>" data.xml | sed 's:<phone>::;s:</phone>::'` echo "Phone Number is:"$phone repnum=554156 cat data.xml | sed -e... (3 Replies)
Discussion started by: Prateek007
3 Replies

6. Shell Programming and Scripting

Unusual Problem

what is wrong with the below script: --------------------------------------------------------------------------------- #!/bin/bash echo "Setting JrePath..." grep -w "export JrePath" /etc/profile Export_Status=$? if echo "JrePath declared" elif echo "JrePath not declared" echo... (4 Replies)
Discussion started by: proactiveaditya
4 Replies

7. Solaris

RC script behavior within Zones

Is there a difference in behavior with start up scripts that are inside of local zones, were trying to write some startup scripts, and it appears things are not running the same, and in some cases, it appears that rc sctripts are not running at all. Anyone else run into this? (1 Reply)
Discussion started by: BG_JrAdmin
1 Replies

8. UNIX for Dummies Questions & Answers

Weird Behavior of a Script

ok, there's a script i'm working on written in shell programming. #!/bin/sh this script is written to spit out the contents of certain variables inside of it so the output looks something like this: server01=89 server02=69 server03=89 server04=76 now, when i run this script from the... (4 Replies)
Discussion started by: SkySmart
4 Replies

9. UNIX for Dummies Questions & Answers

Odd .sh behavior in script

Hello, I have been working on a what I thought was a fairly simple script for installing a software kit on Linux and Unix I am not new to scripting but am far from being fluent in sh scripting. any assistance would be appreciated. I have an odd bug occuring when executing the script. When... (2 Replies)
Discussion started by: robertmcol
2 Replies

10. Shell Programming and Scripting

very unusual question about while

is there anyway to make while run a command faster than per second? timed=60 while do command sleep 1 done i need something that can run a script for me more than one time in one second. can someone help me out here? (3 Replies)
Discussion started by: Terrible
3 Replies
Login or Register to Ask a Question