Cp not working in shell script but running perfectly from shell


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Cp not working in shell script but running perfectly from shell
# 1  
Old 04-09-2015
RedHat Cp not working in shell script but running perfectly from shell

Dear All,


I have script.


Code:
Dest=""
IFS=' 
'
for translation in $(echo $MY_MAP)
do
   t1=$(echo $translation | cut -d"=" -f1)
   t2=$(echo $translation | cut -d"=" -f2| cut -d"," -f1)
   
   if [ $u_testname = $t1 ]
   then
     	   Dest=$UNX/$u_product_path/$u_study_path/$UNXTR/$t2
      break;
   fi
done

if [ "x$Dest" = "x" ];
then
   Dest=$UNX/$u_product_path/$u_study_path/$UNXTR/$MAP_OTHER
fi

if [ ! -d $Dest ]
then
   mkdir -p $Dest
fi

echo "printing Filename:" $n_filezip_name "Destination :" $Dest/$l_filezip_name
echo "Current Working Directory:" 
echo cp -f $n_filezip_name $Dest/$l_filezip_name
pwd
cp -f $n_filezip_name $Dest/$l_filezip_name - This is not working

echo $?
  if [ $? -ne 0 ]
   then
      echo "$DATE [OCEDL ERROR] Not able to cp long_unix_name to $Dest"
  fi
IFS='
'
}

When i run this it produces
echo $? as 0
But if I run this from shell it does what it should do. Any Guess what is wrong I consider IFS is culprit but not able to debug it.

Code:
cp -f $n_filezip_name $Dest/$l_filezip_name

this is not working.

Any help or advise would be great help to me.

Thanks.
# 2  
Old 04-09-2015
perhaps lack of quoting?

Try:
Code:
cp -f "${n_filezip_name}" "${Dest}/$1_filezip_name"

# 3  
Old 04-09-2015
What is MY_MAP?

What is u_testname?

Why have you set IFS to a newline? If your goal is to read something line-by-line, it'd be better to use a while read loop.

You can simplify this:if [ "x$Dest" = "x" ]; into this: if [ -z "$Dest" ]

This section will never work right:

Code:
echo $?
  if [ $? -ne 0 ]
   then
      echo "$DATE [OCEDL ERROR] Not able to cp long_unix_name to $Dest"
  fi


...because echo sets the value of $? to zero after it runs.
# 4  
Old 04-09-2015
I don't think IFS is the culprit; it doesn't seem you're using it anywhere.
n_filezip_name is not defined (at least in that code snippet).
And, after echo $?, the [ $? ... will test echo's exit code, not cp's.
# 5  
Old 04-09-2015
I counted 10 variable that are not defined.

Code:
if [ ! -d $Dest ]
then
   mkdir -p $Dest
fi

This test will fail if the last name in the path of Dest resolves to another file type. I would test the exit code of mkdir. Something like this
Code:
mkdir -p "$Dest" || ( echo "EXITING SCRIPT"; exit )

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Homework & Coursework Questions

Shell script help: not working as I like

Student just starting to learn shell script I have file named smallFile John:Doe:ECE:3.54:doe@jd.home.org:111.222.3333 James:Davis:ECE:3.71:davis@jd.work.org:111.222.1111 Al:Davis:CS:2.63:davis@a.lakers.org:111.222.2222 Ahmad:Rashid:MBA:3.74:ahmad@mba.org:111.222.4444... (2 Replies)
Discussion started by: jetoutant
2 Replies

2. Shell Programming and Scripting

Running 3 shell script parallel in another shell script

Hi, I'm trying to do teh below thing. I have a single script which uses 3 different parameters to do 3 different work like belwo. test1.sh par1 -- it shuts down an instance test1.sh par2 -- it shuts down an instance test1.sh par3 -- it shuts down an instance Now I created a script... (7 Replies)
Discussion started by: bhaski2012
7 Replies

3. Shell Programming and Scripting

Shell script not working

. /home/bscs6/.kshrc set -x monthy=`date +%m` daty=`date +%d` yeary=`date +%Y` cd /home/bscs6/scripts sqlplus sysadm/sysadm@SEGODI @lms_profile.sql mv /home/bscs6/scripts/lmsprofile.log /home/bscs6/scripts/LMS_PROFILE_DUMP_$daty$monthy$yeary.txt gives me the error below: LMS_PROFILE.sh:... (3 Replies)
Discussion started by: malefho
3 Replies

4. Shell Programming and Scripting

Changing shell from a script and running something from the new shell

Hi We use "tcsh" shell . We do the following steps manually: > exec ssh-agent zsh > python "heloo.py" (in the zsh shell) I am trying to do the steps above from a shell script This is what I have so far echo "Executing " exec ssh-agent zsh python "hello.py" exit 0 Problem is... (5 Replies)
Discussion started by: heman82
5 Replies

5. Ubuntu

Shell script not working accordingly

loop=y while do clear tput cup 5 15 echo -n "People Database" echo -n "====================================" tput cup 8 12 echo -n "L-Print Last Names" tput cup 9 12 echo -n "F-Print First NAmes" tput cup 10 12 echo -n "C-Print First Name, Last Name sorted by city" tput cup 11 12... (3 Replies)
Discussion started by: Akhilaprabhakar
3 Replies

6. UNIX for Dummies Questions & Answers

shell Script working

i wrote a shell program in Home Directory. and i changed to other directory. i want to try to execute shell script in Other Dir. it is not executed. how can i make this script to execute in other directory also?? Thanks, Arun (11 Replies)
Discussion started by: arun508.gatike
11 Replies

7. Shell Programming and Scripting

Shell script running command in different shell

Hi All, Is there any way where we can run few commands with different shell in a shell script ? Let's have an example below, My first line in script reads below, #!/bin/sh However due to some limitation of "/bin/sh" shell I wanted to use "/bin/bash" while executing few... (9 Replies)
Discussion started by: gr8_usk
9 Replies

8. Solaris

Running from Shell Vs running from RC script

Hi, i have a script which need to do behave differently when run as a startup process from init.d/ rc2.d script and when run manually from shell. How do i distinguish whether my script is run by init process or by shell?? Will the command /proc/$$/psinfo | grep "myscript" work well???... (2 Replies)
Discussion started by: vickylife
2 Replies

9. Shell Programming and Scripting

CRON is not working perfectly

I scheduled a cron job to run @ 1:00 as follows , 00 01 * * * /app/cbf/CLIF/version-1.0.0.0/scripts/archival.sh Please find the archival.sh script. But cron is throwing a mail stating sqlplus command not found So can anybody suggest what might be the problem ??? (13 Replies)
Discussion started by: manas_ranjan
13 Replies

10. Shell Programming and Scripting

Shell script is not working...

Hi All, I have oracle 9i and 10g on unix. now i have 920.env and 1020.en file to set p respective enviornment. when I excecute this commnad . $HOME/920.env from the shell prompt it is working fine. and also same for 1020.env . Now same command . $HOME/920.env i am putting in shell... (2 Replies)
Discussion started by: vishalpatel03
2 Replies
Login or Register to Ask a Question