ls -ltr malfunctioning inside the k-shell script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting ls -ltr malfunctioning inside the k-shell script
# 1  
Old 05-29-2009
ls -ltr malfunctioning inside the k-shell script

i have a script that shows the "yesterday" and "todays" date entry in the few log files. IF the mentioned date entry is not found in the logs then it sends an mails. These are all persistance applications.

Code:
#!/bin/ksh


TZ=`date +%Z`+0 ;d=`date +%Y-%m-%d`
TZ=`date +%Z`+24 ; b=`date +%Y-%m-%d`
echo "Checking for date $b   $d"

cd /ednpdtu3/u01/pipe/logs

for i in MeterResetReport.log DBMaint.log 
do
count=0
count1=0
count=`cat $i* | grep "$b" | wc -l`
count1=`cat $i* | grep "$d" | wc -l`
V_VAR=`ls -ltr $i | sed "s/\.log//" | awk '{print $9}'`
if [ $count -eq 0 ] && [ $count1 -eq 0 ]
then
echo "$V_VAR has NO entry "
else
echo "$V_VAR has entry "
ls -ltr $i
fi

done

The problem i m facing is that when i m giving the command ls -ltr $i in the script it showing the wrong modification time for few apps.Below the ERROR


ERROR:
Code:
MeterResetReport has entry 
-rw-r--r--   1 pipe     pipe        2518799 May 27 23:41 MeterResetReport.log
DBMaint has entry 
-rw-r--r--   1 pipe     pipe        9383516 May 28 10:04 DBMaint.log

Actual ls -ltr when i type in command prompt shows different result which is correct
Code:
ls -ltr DBMaint.log
-rw-r--r--   1 pipe     pipe        9425244 May 29 05:06 DBMaint.log

ls -ltr MeterResetReport.log
-rw-r--r--   1 pipe     pipe        2518799 May 28 18:41 MeterResetReport.log

# 2  
Old 05-29-2009
I don't believe that it's possible for ls -ltr to produce a different output in the script from the command line for the same files, so I think you should check again!
# 3  
Old 05-29-2009
You are changing $TZ at the start of the script which affects the display from "ls".

For example:

Code:
TZ=GMT0BST
ls -lad abc29
-rw-r--r--   1 root       sys              0 May 29 12:59 abc29

TZ=GMT6BST
ls -lad abc29
-rw-r--r--   1 root       sys              0 May 29 06:59 abc29


What is in your system's /etc/TIMEZONE ? If you don't have that file, what is TZ set to normally?

The following technique only temporarily changes TZ and will not affect commands later in the script. For timezones other than UK the offset to get yesterday or tomorrow is relative to your normal offset. Notice that I also state the daylight saving time to match my /etc/TIMEZONE .

Code:
echo "Yesterday : $(TZ=GMT24BST;date)"
echo "Today     : $(date)"
echo "Tomorrow  : $(TZ=GMT-24BST;date)"


Last edited by methyl; 05-29-2009 at 09:36 AM.. Reason: Added example technique
# 4  
Old 05-29-2009
var="MeterResetReport.log DBMaint.log"

for i in $var

may be this would help

Thanks,
Yagami
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Capture run time of python script executed inside shell script

I have bash shell script which is internally calling python script.I would like to know how long python is taking to execute.I am not allowed to do changes in python script.Please note i need to know execution time of python script which is getting executed inside shell .I need to store execution... (2 Replies)
Discussion started by: Adfire
2 Replies

2. Shell Programming and Scripting

I have two commands “ls -h” and “ls -ltr”. How do i make sure “ls -ltr” is run after “ls -h” is suc

help me (2 Replies)
Discussion started by: sonu pandey
2 Replies

3. Shell Programming and Scripting

Using HTML inside shell script

Hi, Am trying to use HTML tags inside my script but its not printing the required output. Any idea how to use html inside script will be helpful. #!/bin/ksh echo '<html>' echo '<font face='Calibri' size='3'> JobName Status</font>' echo '</html>' Output<html> <font ... (6 Replies)
Discussion started by: rogerben
6 Replies

4. Shell Programming and Scripting

How to merge Expect script inside shell script?

Hi I have two scripts one is Expect and other is shell. I want to merge Expect code in to Shell script so that i can run it using only one script. Can somebody help me out ? Order to execute: Run Expect_install.sh first and then when installation completes run runTests.sh shell script. ... (1 Reply)
Discussion started by: ashish_neekhra
1 Replies

5. 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

6. Shell Programming and Scripting

perl inside shell script?

Hi UNIX Pros! Newbie here, I would like to ask if it is possible to use perl commands inside a shell script? i created a simple script which connects to oracle and run queries which the script saves to a separate .txt file for each query issued. What i want to do is to create a presentable and... (7 Replies)
Discussion started by: 4dirk1
7 Replies

7. Shell Programming and Scripting

how to run shell script inside expect script?

I have the code like this : shell script continues ... .... expect -c" spawn telnet $ip expect "login:" send \"$usrname\r\" expect "Password:" send \"$passwd\r\" expect "*\>" send \"$cmdstr\r\" ... (1 Reply)
Discussion started by: robbiezr
1 Replies

8. Shell Programming and Scripting

Call a perl script inside a shell script

Hi all, I have the following snippet of code.. #!/bin/sh echo "run perl script............" #Run the verification script perl bill_ver echo " perl script completed....." echo "rename files......" #Remove from all file in the directories test, test1, test2, test3 for f in... (3 Replies)
Discussion started by: chriss_58
3 Replies

9. Shell Programming and Scripting

invoking a shell script inside cgi shell script

Hi, I have an HTML form through which I get some text as input. i need to run a shell script say script.sh inside a perl-cgi script named main_cgi.sh on the form input. I want to write the contents of the form in a file and then perform some command line operations like grep, cat on the text... (2 Replies)
Discussion started by: smriti_shridhar
2 Replies

10. Shell Programming and Scripting

How to run unix commands in a new shell inside a shell script?

Hi , I am having one situation in which I need to run some simple unix commands after doing "chroot" command in a shell script. Which in turn creates a new shell. So scenario is that - I need to have one shell script which is ran as a part of crontab - in this shell script I need to do a... (2 Replies)
Discussion started by: hkapil
2 Replies
Login or Register to Ask a Question