Operating System - HP-UX
1830045 Members
4682 Online
109998 Solutions
New Discussion

Case Statement Help needed

 
SOLVED
Go to solution
rhansen
Frequent Advisor

Case Statement Help needed

I have twenty types of files under my home directory that needs to be uploaded that are broken into two groups of 10 each.
/home/abcd/test has 10 files
/home/abcd/dev has 10 files.

The naming convention of files is five digit,date.txt example: 12345.09232009.txt and so on.

Can someone help me in writing a case statement where it will have the logic to read files from test or dev directory and upload as necessary.

I was thinking along the following lines:
upload_dir_test=/home/abcd/test
upload_dir_dev=/home/abcd/dev

case $1 in
-u)


case $upload_dir_test in
12345)
upfile="12345*.txt"
;;

Could someone help me guide to the best way of doing this?

Thanks in advance.
5 REPLIES 5
Michael Steele_2
Honored Contributor

Re: Case Statement Help needed

Hi
If the same naming convention is used in both directories then there is no test. Right now you have

12345......txt for both dev and test - what is the distinction? The directory names? Just the dir. names?
Support Fatherhood - Stop Family Law
James R. Ferguson
Acclaimed Contributor

Re: Case Statement Help needed

Hi:

See if this helps:

#!/usr/bin/sh
typeset upload_dir_test=/tmp/TST
typeset upload_dir_dev=/tmp/DEV

case $1 in
-t )
cd ${upload_dir_test} || exit 1
;;
-d )
cd ${upload_dir_dev} || exit 1
;;
* )
echo "bad option"; exit 1
;;
esac
upfile=$(ls -1 [0-9][0-9][0-9][0-9][0-9]*.txt 2>/dev/null)
echo ${upfile}
exit 0

Regards!

...JRF...
rhansen
Frequent Advisor

Re: Case Statement Help needed

Sorry, I should have been clear in describing it. The ten files are below and after the files have been uploaded they will be removed and replaced by new files only the date stamps will change. Can you please advise accordingly.

/home/abcd/test/17648.09232009.txt
/home/abcd/test/24901.09232009.txt
/home/abcd/test/89012.09232009.txt
/home/abcd/test/28943.09232009.txt
/home/abcd/test/14567.09232009.txt
/home/abcd/test/90284.09232009.txt
/home/abcd/test/80010.09232009.txt
/home/abcd/test/13456.09232009.txt
/home/abcd/test/39284.09232009.txt
/home/abcd/test/29940.09232009.txt

/home/abcd/dev/17648.09232009.txt
/home/abcd/dev/24901.09232009.txt
/home/abcd/dev/89012.09232009.txt
/home/abcd/dev/28943.09232009.txt
/home/abcd/dev/14567.09232009.txt
/home/abcd/dev/90284.09232009.txt
/home/abcd/dev/80010.09232009.txt
/home/abcd/dev/13456.09232009.txt
/home/abcd/dev/39284.09232009.txt
/home/abcd/dev/29940.09232009.txt

And I am trying to have separate logic for DEV and TEST.

Thanks again.
kobylka
Valued Contributor
Solution

Re: Case Statement Help needed

Hello!

Script is attached.

Kind regards,

Kobylka
Dennis Handly
Acclaimed Contributor

Re: Case Statement Help needed

>case $upload_dir_test in
12345) upfile="12345*.txt"

I'm not sure what you want to do here.
If you want to upload all files with the pattern: [0-9][0-9][0-9][0-9][0-9].[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9].txt

Then you can simply use ls to find them:
ls $upload_dir_test/[0-9][0-9][0-9][0-9][0-9].[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9].txt
Or you can use grep after ls:
ls $upload_dir_test | grep "[0-9]\{5\}\.[0-9]\{8\}\.txt"