Shell Script - If and smbclient (ftp)...help

Hi,

So I am writting a script to copy files from Linux to windows using smbclient, I have done this a fair amount of times now. Unfortunately this time I am using a simply if statement to determine if the file exists before beginning the smbclient section.....however if I tab the smbclient command over the screen from the left to under the then/else commands it doesn't work - but it does if I leave it on the right of the screen.........It is annoying as I like formatted scripts...

This does not work:

if [ -f log* ]
        then
                echo "Files exist - transferring files" | tee -a $LOGFILE
                smbclient $servername $password -U $username >>  $LOGFILE << FTP
                prompt
                lcd $REPHOME
                cd here
                mkdir $DATESTAMP
                cd $DATESTAMP
                mput log*
                exit
                FTP
        else
                echo "Files do not exist - skipping"
fi

However this does work:

if [ -f log* ]
        then
                echo "Files exist - transferring files" | tee -a $LOGFILE
smbclient $servername $password -U $username >>  $LOGFILE << FTP
 prompt
lcd $REPHOME
cd here
mkdir $DATESTAMP
cd $DATESTAMP
mput log*
exit
FTP
        else
                echo "Files do not exist - skipping"
fi

I know it isn't the end of the world but I would like to look nice too :stuck_out_tongue:

If you only use TAB's for indent, you could use <<- FTP instead of << FTP

2 Likes

thanks - these little quirks are simply difficult to find via search engine...I appreciate it

Thanks, I would add a comment to your script stating the necessity of only using TAB's. Otherwise if someone (or yourself) needs to edit the script in future he may have a hard time finding the problem if there is so much as a single space somewhere before the label. That is why I am not too keen on this solution. As an alternative you could leave the indents for the lines in the here-document and move only the closing label all the way to the left.

Well now I know - I will simply move the final label to the right as it is likely less experienced people may need to review the scripts.

Thanks again