Operating System - HP-UX
1752587 Members
4792 Online
108788 Solutions
New Discussion юеВ

Re: script not executing properly ???

 
shan_7
Advisor

script not executing properly ???

Hi experts,

I attached one script for very basic copying to files with certain conditions.
First condition is ok but after it is not executing further.
If disable the second condition then also it is not copying the files.

Help me in this case.
Explain me details please.

Thanks in advance.

Shan
6 REPLIES 6
KapilRaj
Honored Contributor

Re: script not executing properly ???

found condition 6 bad..

==========================
# condition 6
if [ "ANSWER" = "yes" ] # <<<<< Change to $ANSWER
then
cp $1 $2
echo "file copied"
exit 0
==========================

It should be

=========================
# condition 6
if [ "$ANSWER" = "yes" ] # <<<<< Change to $ANSWER
then
cp $1 $2
echo "file copied"
exit 0
====================


Regds,

Kaps
Nothing is impossible
KapilRaj
Honored Contributor

Re: script not executing properly ???

If this is not yet fixed can u do a test run in debug mode and post the o/p?.

set -x
./script file1 file2

Regds,

Kaps
Nothing is impossible
Muthukumar_5
Honored Contributor

Re: script not executing properly ???

Hai,

Are you using the echo without messages for debugging. If so use set -x or set -v for that.

set -x - it will give messages after command execution

set -v - it will give the comman messages before execution.

Change the if [ "ANSWER" = "yes" ] as

if [ "$ANSWER" = "yes" ]

change this echo "file copied with " at end.

Regards,
Muthukumar
Easy to suggest when don't know about the problem!
KapilRaj
Honored Contributor

Re: script not executing properly ???

condition 1 :-

check if there are two args if not exit

condition 2 :-

check if both the args are the same. if same exit

condition 3 :-

check source file is a normal file. if not exit

condition 4 :-

check if source file is readable

condition 5 :-

check if the file already exist. if exist check with the user if he wants to over write.

condition 6 :-

check user's input is "yes". if yes copy the file else quit ..


Regds,

Kaps
check this thread as well.
http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=140137
Nothing is impossible
KapilRaj
Honored Contributor

Re: script not executing properly ???

Your qtn:-

my first command line arg is a file having no permission. but script is excuting properly
How?

Ans :-

Are running it as root ?

Kaps
Nothing is impossible
SAHA
Honored Contributor

Re: script not executing properly ???

This is working and modified script.

Thanks,
You must PASS failure on way to success !!!