Shell Script..plzz help


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Shell Script..plzz help
# 8  
Old 11-22-2010
Sequence means.....like from sept to till date ...we need find that every day is present or not....like the sequnce of dates (like from day 1 to 31 or 30 we need to have every day) and 12775048994_125342__***(text)_201010010800.txt ---------bold ones are need to checked its based on date ..but the first big numbers are dynamic ones ..they all not same for every day..it will be generated dynamically.......(all txt names are dynamically generated except the text what i have mentioned... it depends on market name..but it doesn't matter)..
# 9  
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:
# 10  
Old 11-23-2010
thanks a lot for your time..
i am workin on putty ...and my servers are built on UNIX platform (i am not sure)
the file naming convention is like this
12775048994_125342 __***(text)_201010010800.txt
Italic ones are random numbers which will be in increasing order (we don't bother about it....) but, if we check it would be fine.....
# 11  
Old 11-23-2010
Quote:
Originally Posted by krux_rap
thanks a lot for your time..
i am workin on putty ...and my servers are built on UNIX platform (i am not sure)
the file naming convention is like this
12775048994_125342 __***(text)_201010010800.txt
Italic ones are random numbers which will be in increasing order (we don't bother about it....) but, if we check it would be fine.....
To know on which unix plateform you are, use the command
Code:
uname -a

This User Gave Thanks to ctsgnb For This Post:
# 12  
Old 11-23-2010
PLATFORM : SunOS ***** 5.10 Generic_142900-02 sun4v sparc SUNW,T5440
# 13  
Old 11-23-2010
Ok uou are running Solaris 10 so it would just run fine :

adapt my code to your needs (with your directories) and run it.

If it doesn't fit , please provide more details about what you expect (provide sample of input and expected output).
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

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

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

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

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

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

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

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

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

9. 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
Login or Register to Ask a Question