0

can you please help me with very strange situation,

I have Ubuntu 18.04 and running some bash script and my script looks like this.

    #!/bin/bash
    FOLDER="$1"
    FILE="$2"

BASENAME=$(/bin/basename "$FOLDER/$FILE" | /bin/sed 's/\.[^.]*$//')

HOST="FTPSERVER"
USER="username"
PASSWORD="pass"
###########################

cd /home/vod/output/
#start=$(date +%s)

ftp -n -v >> /var/log/ftptransfer_hrmxf.log 2>&1 $HOST <<END_SCRIPT
binary
user $USER $PASSWORD
prompt
cd media
put $FILE
quit
END_SCRIPT
############### FIXME!!!! #######################

echo "$BASENAME" >> /var/log/videos_done

the issue is here that ECHO Command doesn't output the Basename and instead it output the Blank character.

please help me understand what am I doing wrong ?

Thank you So Much.

  • 3
    Do some troubleshooting. What is the result of /bin/basename "$FOLDER/$FILE"? What happens if you put that result through the sed command manually? Somewhere along the line the result is blank, but we don't know at which point. – Jos Nov 2 '18 at 17:24
1

First, basename is located in /usr/bin/basename NOT where you have it coded in your scripting. Thus, because the basenamecommand has failed (and you have not checked this in your code), the value of the varialble $BASENAME is most likely NULL.

What I usually do in any scripting is place an explicit PATH at the start of the script. Something like:

 PATH=/usr/bin:/bin:/usr/local/bin
 export PATH

It is not immediately clear what the purpose of the sed command is.

Also try using the command bash -uvx scriptname to examine the expansion and setting of the variables before the command and when the command gets executed.

  • yes that was exactly the issue. thank you for the help and suggestion. – kunal Nov 3 '18 at 13:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.