Sponsored Content
Top Forums Shell Programming and Scripting I have this list of files . Now I will have to pick the latest file based on some condition Post 302910424 by LoneRanger on Thursday 24th of July 2014 11:26:26 AM
Old 07-24-2014
Is this homework/assignment? There are specific forums for these.
What have you tried so far? No It's not.
What output/errors do you get? I am not getting expected output.
Are the ** shown actually part of the file name or just to highlight the important part? Just to highlight the important part
How are you generating the listing? We might be able to process it in-line rather than writing and processing a file.

I am generating it using
Code:
find . -name "*.log" -mtime -8

What OS and version are you using? I am not sure. Some flavor some Linux.
What are your preferred tools? (C, shell, perl, awk, etc.) Shell
What logical process have you considered? (to help steer us to follow what you are trying to achieve) I am trying to pick the filename , date part ,size and the order_number part and insert all into a DB table from shell script. do the comparison there an pick the right file name and pass it back into shell script for further processing.


My code so far :: it's not giving me expected output though-


Code:
 
 export LOGDIR=/home/rmsbatch/testdata
 
# TEMPDIR : Path where all non zero files need to be moved after search.
export TEMPDIR=/home/rmsbatch/testdata/TEMP
 # RESULTFILE : Path of the Final File 
export RESULTFILE=${TEMPDIR}/belk_rpo_error.txt
 ###############################################################################
#                                     MAIN                                    #
###############################################################################
set -x
if [ $# -ne 1 ]
  then
    echo "Please Provide Date range"
    echo "Example: ./belk_rpo_shell_script.ksh "
    exit 1
fi
 DATE_RANGE=$1
echo $DATE_RANGE
echo " SET ECHO OFF
SET NEWPAGE 0
SET SPACE 0
SET PAGESIZE 0
SET FEEDBACK OFF
SET HEADING OFF
SET TRIMSPOOL ON
SET TAB OFF
           select to_char(sysdate,'YYYYMMDD')
                                  from dual ;" > date.sql
 END_DATE=`sqlplus -s $UP <<EOF @date.sql
exit;
EOF`
 echo " SET ECHO OFF
SET NEWPAGE 0
SET SPACE 0
SET PAGESIZE 0
SET FEEDBACK OFF
SET HEADING OFF
SET TRIMSPOOL ON
SET TAB OFF
           select to_char(sysdate-$DATE_RANGE,'YYYYMMDD')
                  from dual ;" > date1.sql
 START_DATE=`sqlplus -s $UP <<EOF @date1.sql
exit;
EOF`
 echo $START_DATE
echo $END_DATE
 cd $LOGDIR
 if [ ! -d "$LOGDIR/tmp" ]; then
  mkdir $LOGDIR/tmp
fi
 touch -t ${START_DATE}0000 ./tmp/NEWSTARTDATE
touch -t ${END_DATE}2359 ./tmp/NEWENDDATE
 find . -type f ! -size 0 \( -newer ./tmp/NEWSTARTDATE -a \! -newer ./tmp/NEWENDDATE \) -print |grep '.log'|
 while read fname
do
cp -p $fname  $TEMPDIR/${fname}
  
  PONUM=$(echo "${fname:17:9}")
  find . -type f  -size 0 \( -newer ./tmp/NEWSTARTDATE -a \! -newer ./tmp/NEWENDDATE \) -print |grep $PONUM |  
   
  while read fn
  do
    rm -f $TEMPDIR/$fn
    rm -f $TEMPDIR/${fname}
  done 
done
  
 cd $TEMPDIR
 
if test -f $RESULTFILE; then
  rm -rf $RESULTFILE;
fi
# Create an empty $RESULTFILE
touch -t ${START_DATE} $RESULTFILE
  
 for f in `ls *`; do
  cat $f >> $RESULTFILE;
done
 
nawk '!x[$0]++' $RESULTFILE > temp
mv temp $RESULTFILE
 
sed '/@0PACKAGE_ERROR@1ORA/d' $RESULTFILE > temp
mv temp $RESULTFILE
 
if [ -d "$LOGDIR/tmp" ]; then
  rm -rf $LOGDIR/tmp
fi
 
#for f in `ls belk_rpo_error_po* 2>/dev/null`
#do
#  rm -rf $f
#done

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

ksh: How to get latest file from a list of files in a directory

Hi, I need to get the latest file from a list of files in a particular directory. Please could anyone help me out to get the file. Thank you, - Jay. (1 Reply)
Discussion started by: Jayathirtha
1 Replies

2. Shell Programming and Scripting

Pick the latest set of files

I have task in which I need to pickup a set of files from a directory depending on the following criteria: Every month 6 files are expected to arrive at /test. The files come with date timestamp and the latest file set for the month needs to be used Suppose this is the set of files that present... (5 Replies)
Discussion started by: w020637
5 Replies

3. Shell Programming and Scripting

how can i pick the latest log file as per below

in the below .. i want to pick the latest logfile which is having JPS.PR inside.. that means i want particularly "spgport040408041223.log:@@@@@@@@ 04:13:09 Adding: JPS.PR." which is latest among these.. is it possible to compare the current time with logfile time ? reptm@xblr0758rop>... (4 Replies)
Discussion started by: mail2sant
4 Replies

4. Shell Programming and Scripting

Find the latest directory and loop through the files and pick the error messages

Hi, I am new to unix and shell scripting,can anybody help me in sctipting a requirement. my requirement is to get the latest directory the name of the directory will be like CSB.monthdate_time stamp like CSB.Sep29_11:16 and CSB.Oct01_16:21. i need to pick the latest directory. in the... (15 Replies)
Discussion started by: sudhir_83k
15 Replies

5. UNIX for Dummies Questions & Answers

Need command to pick the latest file

Hi In my script i am trying to access mainframe server using FTP, in the server i have filee with the timestamp.I need to get the file with the latest timestamp among them . The server has the below files / ftp> cd /outbox 250 CWD command successful ftp> ls 200 PORT command successful... (4 Replies)
Discussion started by: laxmi131
4 Replies

6. UNIX for Dummies Questions & Answers

How to pick only the latest files based on the timestamp?

I have a few log files which get generated on a daily basis..So, I need to pick only the ones which get generated for that particular day. -rw-r--r-- 1 staff 510732676 Apr 7 22:01 test.log040711 -rwxrwxrwx 1 staff 2147482545 Apr 7 21:30 test.log.2 -rwxrwxrwx 1 staff 2147482581 Apr 7 19:26... (43 Replies)
Discussion started by: win4luv
43 Replies

7. Shell Programming and Scripting

to pick the latest file modified in a directory

I wan to pick the latest modified file name and redirect it to a file .. ls -tr | tail -1 >file but this is printing file ins side the filename , can anyone help me out (5 Replies)
Discussion started by: vishwakar
5 Replies

8. Shell Programming and Scripting

Urgent ...pls Sorting files based on timestamp and picking the latest file

Hi Friends, Newbie to shell scripting. Currently i have used the below to sort data based on filenames and datestamp $ printf '%s\n' *.dat* | sort -t. -k3,4 filename_1.dat.20120430.Z filename_2.dat.20120430.Z filename_3.dat.20120430.Z filename_1.dat.20120501.Z filename_2.dat.20120501.Z... (1 Reply)
Discussion started by: robertbrown624
1 Replies

9. UNIX for Dummies Questions & Answers

Sorting files based on timestamp and picking the latest file

Hi Friends, Newbie to shell scripting Currently i have used the below to sort data based on filenames and datestamp $ printf '%s\n' *.dat* | sort -t. -k3,4 filename_1.dat.20120430.Z filename_2.dat.20120430.Z filename_3.dat.20120430.Z filename_1.dat.20120501.Z filename_2.dat.20120501.Z... (12 Replies)
Discussion started by: robertbrown624
12 Replies

10. Shell Programming and Scripting

Should pick latest file within past 3 days using UNIX script and perform steps in message below.

Hi , Can anyone help me how do perform below requirement in unix. Step1:we will receive multiple files weekly with same name(as below) in a folder(In folder we will have other files also def.dat,ghf.dat) Filenames: 1) abc_20171204_052389.dat 2)abc_20171204_052428.dat DON'T modify... (23 Replies)
Discussion started by: sunnykamal59
23 Replies
SET 
ROLE(7) SQL Commands SET ROLE(7) NAME
SET ROLE - set the current user identifier of the current session SYNOPSIS
SET [ SESSION | LOCAL ] ROLE rolename SET [ SESSION | LOCAL ] ROLE NONE RESET ROLE DESCRIPTION
This command sets the current user identifier of the current SQL session to be rolename. The role name can be written as either an identi- fier or a string literal. After SET ROLE, permissions checking for SQL commands is carried out as though the named role were the one that had logged in originally. The specified rolename must be a role that the current session user is a member of. (If the session user is a superuser, any role can be selected.) The SESSION and LOCAL modifiers act the same as for the regular SET [set(7)] command. The NONE and RESET forms reset the current user identifier to be the current session user identifier. These forms can be executed by any user. NOTES
Using this command, it is possible to either add privileges or restrict one's privileges. If the session user role has the INHERITS attribute, then it automatically has all the privileges of every role that it could SET ROLE to; in this case SET ROLE effectively drops all the privileges assigned directly to the session user and to the other roles it is a member of, leaving only the privileges available to the named role. On the other hand, if the session user role has the NOINHERITS attribute, SET ROLE drops the privileges assigned directly to the session user and instead acquires the privileges available to the named role. In particular, when a superuser chooses to SET ROLE to a non-superuser role, she loses her superuser privileges. SET ROLE has effects comparable to SET SESSION AUTHORIZATION [set_session_authorization(7)], but the privilege checks involved are quite different. Also, SET SESSION AUTHORIZATION determines which roles are allowable for later SET ROLE commands, whereas changing roles with SET ROLE does not change the set of roles allowed to a later SET ROLE. SET ROLE does not process session variables as specified by the role's ALTER ROLE [alter_role(7)] settings; this only happens during login. SET ROLE cannot be used within a SECURITY DEFINER function. EXAMPLES
SELECT SESSION_USER, CURRENT_USER; session_user | current_user --------------+-------------- peter | peter SET ROLE 'paul'; SELECT SESSION_USER, CURRENT_USER; session_user | current_user --------------+-------------- peter | paul COMPATIBILITY
PostgreSQL allows identifier syntax ("rolename"), while the SQL standard requires the role name to be written as a string literal. SQL does not allow this command during a transaction; PostgreSQL does not make this restriction because there is no reason to. The SESSION and LOCAL modifiers are a PostgreSQL extension, as is the RESET syntax. SEE ALSO
SET SESSION AUTHORIZATION [set_session_authorization(7)] SQL - Language Statements 2010-05-14 SET ROLE(7)
All times are GMT -4. The time now is 08:33 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy