Strange "mv" issue


 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers Strange "mv" issue
# 1  
Old 09-02-2018
Strange "mv" issue

Hi Folks -


I have this piece of code within a function:


Code:
    echo ---------------------------------------------------------                                                                                                
    echo "Download Data File"                                         
    echo ---------------------------------------------------------
    echo "Action    : downloadfile"
    echo "Data File : ${_TEMPFILE}"
    echo ---------------------------------------------------------

    pushd "${_EPMAUTOMATE_BIN}"
    #    ./epmautomate.sh downloadfile ${_DATAMGMT_BIN}/${_TEMPFILE} > /dev/null
        _RVAL="$?"

        if [ "$_RVAL" -eq "0" ]
        then
            echo && echo "Successful : Download Data File"                           
        else
            echo && echo "Failed : Download Data File"          
        fi
    
        #::-- Move and rename Data File to XXXX_XXXX_MM_YYYY format --::#
        mkdir -p "${_INBOXPATH}"
        mv "${_TEMPFILE}" "{_INBOXPATH}${_FILE}"
    popd


And it keeps erroring out saying:
Quote:
mv: cannot stat `tempFDMEE.csv': No such file or directory

Quote:
_TEMPFILE is tempFDMEE.csv

However, I can confirm tempFDMEE.csv exists in this bin:
Code:
_EPMAUTOMATE_BIN


Am I doing anything wrong? Thanks!
# 2  
Old 09-02-2018
Seems you are missing a “$” in your code?
# 3  
Old 09-02-2018
What you have posted as material for troubleshooting is very ambiguous and your confirmation that tempFDMEE.csv exists doesn't help, since you did not post any result or output that really confirms it.

That said, here some tips that you may choose to put in practice.
Add set -xv somewhere in the beginning of the script to help you debug

I do not know why you commented this line:
Code:
#    ./epmautomate.sh downloadfile ${_DATAMGMT_BIN}/${_TEMPFILE} > /dev/null

and not the following, expecting something meaningful of it
Code:
        if [ "$_RVAL" -eq "0" ]
        then
            echo && echo "Successful : Download Data File"                           
        else
            echo && echo "Failed : Download Data File"          
        fi

Back again to the following line but without comment and assuming that is free of issues

Code:
./epmautomate.sh downloadfile ${_DATAMGMT_BIN}/${_TEMPFILE} > /dev/null

Redirecting the stdout to oblivion doesn't very robust. Is there a possibility that the output is the content of the download? Who knows?
./epmauthomate.sh should send information and status of the running of program, including warnings and errors to stderr. In that way you may be able to ignore it if you choose it as 2> /dev/null


Concerning:
Code:
if [ "$_RVAL" -eq "0" ]

The return of the previous command with a zero, in this case is not a guarantee the veracity of the echo statement:
Code:
echo "Successful : Download Data File"

Depending how it was written ./epmauthomate.sh could and will return a zero even when the result was not a successful download but rather a clean exist.

Perhaps something like this would be more ensuring
Code:
if [ "$_RVAL" -eq "0" ] && [ -e "${_TEMPFILE}" ]


Code:
        then
            echo && echo "Successful : Download Data File"                           
        else
            echo && echo "Failed : Download Data File"          
        fi

The && is superfluous or without purpose.

Consider this:
Code:
        then
            echo
            echo "Successful : Download Data File"                           
        else
            echo 
            echo "Failed : Download Data File"

What's the problem with this?
Code:
        mv "${_TEMPFILE}" "${_INBOXPATH}${_FILE}"

As shown, it does regardless if the file exist or was downloaded successfully, despise of the claim to the contrary.
Code:
[ -e "${_TEMPFILE}" ] && mv "${_TEMPFILE}" "${_INBOXPATH}${_FILE}"

would test before trying to mv.

Some possible changes, then, assuming that ${_FILE} has a proper value.

Code:
    echo ---------------------------------------------------------                                                                                                
    echo "Download Data File"                                         
    echo ---------------------------------------------------------
    echo "Action    : downloadfile"
    echo "Data File : ${_TEMPFILE}"
    echo ---------------------------------------------------------

    pushd "${_EPMAUTOMATE_BIN}"
       ./epmautomate.sh downloadfile ${_DATAMGMT_BIN}/${_TEMPFILE} 2> /dev/null
        _RVAL="$?"

        if [ "$_RVAL" -eq "0" ] && [ -e "${_TEMPFILE}" ]
        then
            echo
            echo "Successful : Download Data File" 

           mkdir -p "${_INBOXPATH}"
           mv "${_TEMPFILE}" "${_INBOXPATH}${_FILE}"
                                     
        else
            echo
            echo "Failed : Download Data File"          
        fi
     popd

------ Post updated at 09:56 AM ------

Quote:
Originally Posted by Neo
Seems you are missing a “$” in your code?
Good catch but it doesn't explain the output:
Code:
mv: cannot stat `tempFDMEE.csv': No such file or directory

If the file tempFDMEE.csv exists
Code:
mv "${_TEMPFILE}" "{_INBOXPATH}${_FILE}"

It would rename tempFDMEE.csv literately {_INBOXPATH}whatever_${_FILE}_has_or_nothing in the current directory

Last edited by Aia; 09-02-2018 at 12:58 PM.. Reason: inline code for && and remove dangling [/CODE]
This User Gave Thanks to Aia For This Post:
# 4  
Old 09-03-2018
Thank you for your help!
I've updted the code per your reccomendations and it's working as expected. The original issues was a pathing error - my fault. But your suggestions were applicable and best practice so I added them.


The "#" was just to comment out that line so it wouldn't fire while I debugged.


Thanks again and have a great labor day!
This User Gave Thanks to SIMMS7400 For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash script - Print an ascii file using specific font "Latin Modern Mono 12" "regular" "9"

Hello. System : opensuse leap 42.3 I have a bash script that build a text file. I would like the last command doing : print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt where : print_cmd ::= some printing... (1 Reply)
Discussion started by: jcdole
1 Replies

2. Shell Programming and Scripting

Why awk print is strange when I set FS = " " instead of FS = "\t"?

Look at the following data file(cou.data) which has four fields separated by tab. Four fields are country name, land area, population, continent where it belongs. As for country name or continent name which has two words, two words are separated by space. (Data are not accurately... (1 Reply)
Discussion started by: chihuyu
1 Replies

3. UNIX for Dummies Questions & Answers

Using "mailx" command to read "to" and "cc" email addreses from input file

How to use "mailx" command to do e-mail reading the input file containing email address, where column 1 has name and column 2 containing “To” e-mail address and column 3 contains “cc” e-mail address to include with same email. Sample input file, email.txt Below is an sample code where... (2 Replies)
Discussion started by: asjaiswal
2 Replies

4. Shell Programming and Scripting

""Help Me!""Beginner awk learning issue

Hi All, I have just now started learning awk from the source - Awk - A Tutorial and Introduction - by Bruce Barnett and the bad part is that I am stuck on the very first example for running the awk script. The script is as - #!/bin/sh # Linux users have to change $8 to $9 awk ' BEGIN ... (6 Replies)
Discussion started by: csrohit
6 Replies

5. UNIX for Advanced & Expert Users

"╭─ " Character combo in $PATH causes strange autocompletion behavior in zsh

I've posted about this before, but only recently narrowed the problem down to a specific cause. Ok, first of all, the behavior: It occurs when autocompletion brings up its list (not when there is only a single option). Basically, if I were to type, say, cd ~/<TAB> I would get something... (2 Replies)
Discussion started by: marshaul
2 Replies

6. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

7. UNIX for Advanced & Expert Users

strange "No such file or directory" errors on NFS volumes

we're seeing very strange "No such file or directory" errors on NFS volumes on one of our suse servers - can anyone please help? we're seeing it for both our NetApp NAS Device and one of our Solaris NFS servers too Here is what we're seeing: stg-backup:~ # cd /rmt/sge stg-backup:/rmt/sge... (3 Replies)
Discussion started by: fishsponge
3 Replies

8. UNIX for Dummies Questions & Answers

Explain the line "mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`"

Hi Friends, Can any of you explain me about the below line of code? mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'` Im not able to understand, what exactly it is doing :confused: Any help would be useful for me. Lokesha (4 Replies)
Discussion started by: Lokesha
4 Replies

9. Shell Programming and Scripting

bash: cd command to access "strange" directories

I have a problem using bash. Simply, I cannot find the right command (if there's one!) to enter in the "- Arch_02 -" directory. As you can see, the name begins with a hyphen and this is causing some trouble: localhost arch2 # pwd /mnt/arch2 localhost arch2 # ls -l total 4 dr-x------ 1 root... (3 Replies)
Discussion started by: robotronic
3 Replies
Login or Register to Ask a Question