Validation in shell script.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Validation in shell script.
# 1  
Old 11-08-2010
Validation in shell script.

Code:
PICKUPDIR=/home/ready/
DROPDIR=/home/downloaded/
TODAY=$(date '+%d%m%y')
LOGFILE=xyz-$TODAY.log
###########
#FUNCTIONS#
###########
#function to perform file transfer to servercopy folder
opalO ()
{
cd $PICKUPDIR
for fileName in `ls -1 TES_ONE*`
do
cp $fileName $DROPDIR
done
} >> $LOGDIR/$LOGFILE
#############
#Main Script#
#############
echo "Start trnasfer to downloaded \c" >> $LOGDIR/$LOGFILE 
date >> $LOGDIR/$LOGFILE
opalO
wait
echo "Start file renaming: \c" >> $LOGDIR/$LOGFILE
date >> $LOGDIR/$LOGFILE
cd $PICKUPDIR
for FILE in `ls Tes_ONE*.*`
do
echo ${FILE} " : File Moved" >> $LOGDIR/$LOGFILE
mv ${FILE} ${FILE}.arch 
done
echo "End" >> $LOGDIR/$LOGFILE
exit 0

opalO function transfer the files from 'ready' to 'downloaded' folder.
I want to keep validation,if there is no files (TES_ONE*) in ready folder then an error message(No Files Availble) should go into the log file.
How can i place this validation in the above code? Please assist me.

Thanks in advance.
# 2  
Old 11-08-2010
Try this:

Code:
opalO ()
{
  if [ -f "$1" ]; then
    for fileName in "$@"
    do
      cp "$fileName" "$DROPDIR"
    done
  else
    echo "no files available"
  fi
}

opalo TES_ONE*

This User Gave Thanks to Scrutinizer For This Post:
# 3  
Old 11-10-2010
Please help me to handle below scenerio -

1) File abc.txt has approx 10,000 records in it. It can have more records.
2) Above, script to be executed to transfer the file from ready to downloaded folder
3) There is a process ‘load' which checks every ready directory every minute. If it finds the file in downloaded folder then the process ‘load' picks the file and passes this to
another process.

Is there any possibility, before transferring all the records, process ‘load' will pick the file as soon as kept in downloaded folder? If yes, kindly provide me the solution for this.

---------- Post updated 11-09-10 at 04:28 PM ---------- Previous update was 11-08-10 at 06:29 PM ----------

Kindly reply to my query.

---------- Post updated at 05:10 PM ---------- Previous update was at 04:28 PM ----------

Hi,

solution provided worked fine but i want one enhancement to add.
Actually if there is no file in ready folder then the further statements, to rename the file to .arch, should not be executed.

Kindly help me as i am quite newi n writting the shell scripts.

Thanks a lot.

---------- Post updated 11-10-10 at 12:49 PM ---------- Previous update was 11-09-10 at 05:10 PM ----------

Hi,

Kindly reply on my queries.

Thanks
# 4  
Old 11-10-2010
Adding an if condition to your code would do the job i believe
Code:
cd $PICKUPDIR
if [ -f "${PICKUPDIR}*" ]
then
	for FILE in `ls Tes_ONE*.*`
	do
		echo ${FILE} " : File Moved" >> $LOGDIR/$LOGFILE
		mv ${FILE} ${FILE}.arch 
	done
fi
echo "End" >> $LOGDIR/$LOGFILE
exit 0


Last edited by michaelrozar17; 11-10-2010 at 03:35 AM.. Reason: mistyped pickupdir
# 5  
Old 11-10-2010
3. Check out inotifywait on Linux.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help with validation of URLs in shell script

hello every one I wrote the script to validate all the urls from my server . sourcing text file which contains the list of urls and trying to check every url and based on response printing url is up or not. the issue when i use the below code with url is printing url exist and and in loop it's... (3 Replies)
Discussion started by: markjohn1
3 Replies

2. UNIX for Dummies Questions & Answers

Validation to be added in the shell script

I need help with one of my shell script. The script is working fine but i need to add two condition - i need to get rid of all the below ftp messages and need to have only ftp completed or failed message. example when i run the script i get below lines - Connected to xxxx 220 (vsFTPd... (1 Reply)
Discussion started by: chandraprakash
1 Replies

3. Shell Programming and Scripting

Script for validation

Hi, I need a script which do below I have one process which runs 24*7 daily and I always has to monitor it now i want to have this automated such that if it stops at anytime we get a exception mail. For example i use ps -ef|grep 'etl' above command gives me the desired output. ... (7 Replies)
Discussion started by: sv0081493
7 Replies

4. Shell Programming and Scripting

Help With UNIX Shell Scripting For Data Validation

Hi All, I am completely new to Unix Shell Scripting. I m validating(Basic File Validation) an .HHT file in TIBCO. After that i need to do Data Validation through UNIX Shell scripting. Rules in DataValidation: 1.) Need to Check Every field wheather it is a Char or Number?(Fields are... (1 Reply)
Discussion started by: Chaitanya K
1 Replies

5. Shell Programming and Scripting

String validation in shell script

Hi All, I am a newbie...I would like to have a function which ll check if a file contains valid strings before "=" operator. Just to give you my requirement: assume my file has content: hello= gsdgsd sfdsg sgdsg sgdgdg world= gggg hhhh iiiii xxxx= pppp ppppp pppp my... (1 Reply)
Discussion started by: rtagarra
1 Replies

6. Shell Programming and Scripting

Shell script validation using process.

Hi All, I have a shell script in Linux and it will be invoked by 2 methods, 1) An automated background process . 2) Logining into the box and directly executing the script. I need to put a validation in my shell script such that it will be executed successfully on when an... (11 Replies)
Discussion started by: vininx
11 Replies

7. Shell Programming and Scripting

EMail Address Validation (Shell Script)

Hi, Can anyone provide me the code snippet for EMail Address Validation. User is going to enter the email address in form window. I need to validate the format is correct. Thanks in Advance BS (3 Replies)
Discussion started by: balajiora
3 Replies

8. Shell Programming and Scripting

shell script data & time validation

How to validate a date and optionly a time in shell scripting when i get the date and time as pararmeters that sent out with the call of the file? (in my case sh union.sh `first parameter ,second parameter...` (4 Replies)
Discussion started by: tal
4 Replies

9. Shell Programming and Scripting

Test File Reading & Validation using Shell script

Please help develop script for below requirement -------Sample file------------------------------- HSVSHOSTRECON 20090115011817BP DARMAR60064966247003504720000000000000000000066626000000000000133000003D003463001332 ... (14 Replies)
Discussion started by: niraj_bhatt
14 Replies

10. Shell Programming and Scripting

Need help in file validation by shell script

Hi I am new to this forum.I need a help in the following: We receve pipe delimited file with transaction ID,tran_date,Quest_cd,Ans_cd,ans_value. Same transaction ID can be repeated with different quest_cd and ans_cd. Basically I need to check if a perticular pair of quest_cd and ans_cd... (1 Reply)
Discussion started by: srichakra
1 Replies
Login or Register to Ask a Question