Sponsored Content
Full Discussion: Shell Script..plzz help
Top Forums Shell Programming and Scripting Shell Script..plzz help Post 302473820 by ctsgnb on Monday 22nd of November 2010 05:41:41 PM
Old 11-22-2010
1) Which OS do you run ?
2) So you want your script to take 2 input arguments in format YYYYMMDD, and then, for every day in between these date, it check whether it can find an existing file with the concerned day in a directory that have a corresponding name, so the file should have the generic form :
./YYYYMMDD/<any_number>__*(text)_YYYYMMDD.txt file
???

Code:
$ ksh myd 20101117
file missing for date 20101117
file missing for date 20101118
file missing for date 20101119
file missing for date 20101120
file missing for date 20101121
file missing for date 20101122
$ mkdir 20101120
$ touch ./20101120/whatevername_20101120.txt
$ ksh myd 20101117
file missing for date 20101117
file missing for date 20101118
file missing for date 20101119
file missing for date 20101121
file missing for date 20101122
$

also handle leap year

Code:
$ ksh myd 19880226 19880302
file missing for date 19880226
file missing for date 19880227
file missing for date 19880228
file missing for date 19880229
file missing for date 19880301
file missing for date 19880302
$

Or here is a better version that includes runtime improvement :
Scanning from 20090101 to 20101122 came from :
Basically :
Code:
real    1m36.595s
user    0m12.428s
sys     0m48.939s

After adding just the single + 8870 iteration saving it decreased to :
Code:
real    0m27.938s
user    0m2.862s
sys     0m10.471s

And using built-in variable and +70 and +71 iteration saving we finally come to the runtime:
Code:
real    0m5.177s
user    0m1.083s
sys     0m3.152s

Here is the code (feel free to use and adapt to your needs)
For your information, i tested it on
Code:
FreeBSD <anonymized> 8.1-RELEASE FreeBSD 8.1-RELEASE #0: Sun  Jul 25 16:41:25 MDT 2010     <anonymized> amd64

as well as
Code:
SunOS <anonymized> 5.10 Generic_141414-01 sun4u sparc SUNW,Sun-Fire-V490

Code:
#!/usr/bin/ksh

usage(){
echo "Usage : $0 {date_min} {date_max}     those dates must be YYYYMMDD formated"
exit 1
}

chk_date(){
typeset -i m d
y="${1%????}" ; t="${1%??}" ; m="${t#$y}" ; d="${1#??????}"
cal $m $y 2>/dev/null | tail +3 | sed -e 'N;N;N;N;N;s/\n/ /g' | grep " $d" >/dev/null 2>&1 && return 0 || return 1
}

min=${1:-20100101}
max=${2:-$(date '+%Y%m%d')}

eval chk_date $min || usage
eval chk_date $max || usage

while [[ $min -le $max ]]
do
    eval chk_date $min && echo $min

case ${min#????} in
@(0[13578]|10)31) min=$(( $min + 70)) ;;
@(0[2469]|11)30) min=$(( $min + 71 )) ;;
1231) min=$(( $min + 8870 )) ;;
*) min=$(( $min + 1 )) ;;
esac

done | while read n
do
     ( ls ./$n/*_$n.txt >/dev/null 2>&1 ) || echo "file missing for date $n"
done


Last edited by ctsgnb; 11-23-2010 at 12:56 PM..
This User Gave Thanks to ctsgnb For This Post:
 

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

problem with GREP, help plzz

I just want the output of this command to be stored in a variable like, str = `grep Application.dbName serverdata/ServerProp.txt` but while executing it says like, str : startup 11: not found, where startup is the script name. but while running the command alone like, grep... (2 Replies)
Discussion started by: cs_sakthi
2 Replies

2. Shell Programming and Scripting

shell script & sqlplus "plzz help"

hi friends, i m tryin to load data from one set of table to other i have sql procedure al ready for it..! i m going to load the procedure only if data in one of my table for example table "landing " have 10 records each attribute of this table is file_name status date ... (2 Replies)
Discussion started by: kulbir
2 Replies

3. Shell Programming and Scripting

I need to add something to a file, plzz help

The first step for you to create the script to change “JAVA_OPTS” variable definition as follows: Original line: JAVA_OPTS="-Dname=$JAVA_NAME -Xmx$JVM_MAX -DAGENT_HOME=$RT_HOME -DINSTALL_DIR=$RT_HOME -Djavax.net.ssl.keyStore=$RT_HOME/conf/client.keystore ... (3 Replies)
Discussion started by: asirohi
3 Replies

4. Shell Programming and Scripting

Not able to solve these questions plzz help

1.Display a list of /usr/share/doc subdirectories containing information about shells.How many README files do these subdirectories contain? Don't count anything in the form of "README.a_string". 2.Make a list of files in your home directory that were changed less that 10 hours ago, using grep,... (2 Replies)
Discussion started by: cynosure2009
2 Replies

5. Shell Programming and Scripting

How to use ssh execute other shell script on other host (shell script include nohup)?

i want use ssh on the host01 to execute autoexec.sh on the host02 like following : host01> ssh host02 autoexec.sh autoexec.sh include nohup command like follwing : nohup /home/jack/deletedata.sh & after i execute ssh host02 autoexec.sh one the host01. i can't found deletedata.sh... (1 Reply)
Discussion started by: orablue
1 Replies

6. Shell Programming and Scripting

Strange errors with shell scripts..plzz help

Hi all... Please help me with this questions. I am not good at shell scripting. 1) It seems like there are many ways that we can run the shell scripts. what is the difference between each one? i)./shell_script.sh ii).(space)./ shell_script.sh iii)sh shell_script.sh ... (3 Replies)
Discussion started by: sanskumar2003
3 Replies

7. Homework & Coursework Questions

need help with a shel script plzz

hey how u doing guys ... I'm a student @ EMU and taking a beginner Linux class and I have those two extra credit project that im struggling with so I hope to get some correction and help write a shell script that will 1-prompt the user for a file name 2-check to see if the file exists... (2 Replies)
Discussion started by: flyman
2 Replies

8. Shell Programming and Scripting

Unable to pass shell script variable to awk command in same shell script

I have a shell script (.sh) and I want to pass a parameter value to the awk command but I am getting exception, please assist. diff=$1$2.diff id=$2 new=new_$diff echo "My id is $1" echo "I want to sync for user account $id" ##awk command I am using is as below cat $diff | awk... (2 Replies)
Discussion started by: Ashunayak
2 Replies

9. UNIX for Dummies Questions & Answers

How to write Config shell script to pass variables in master shell script?

Dear Unix gurus, We have a config shell script file which has 30 variables which needs to be passed to master unix shell script that invokes oracle database sessions. So those 30 variables need to go through the database sessions (They are inputs) via a shell script. one of the variable name... (1 Reply)
Discussion started by: dba1981
1 Replies
All times are GMT -4. The time now is 08:03 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy