I doubt ftp understands your RM_CMD... You know ftp is a quite dumb type of shell, that only understand its own internal commands... look at the man pages, there is a delete, del command
Apologies, wasn't paying attention, didn't notice the hereis document ... LS_CMD didn't need to be an environmental variable. But the leading spaces in front of the "!" are causing the problem:
./scriptname.sh[51]: -s: not found
rm: cannot remove .. or .
This is the error in logfile
Connected to xxx.xxx.xxx.x.
220 dummy FTP server (Version 1.1.214.4(PHNE_38458) Mon Feb 15 06:03:12 GMT 2010) ready.
Remote system type is UNIX.
Using binary mode to transfer files.
331 Password required for myuser.
230 User myuser logged in.
250 CWD command successful.
200 PORT command successful.
150 Opening BINARY mode data connection for a.xml.
226 Transfer complete.
200 PORT command successful.
150 Opening ASCII mode data connection for /usr/bin/ls.
total 0
-rw-rw---- 1 myuser mqm 0 Nov 11 08:31 a.xml
226 Transfer complete.
?Invalid command
221 Goodbye.
Since you are not running the ftp interactively, the "!" fails. Instead:
if $FTP_CMD -v -n $HOST << eof >> $LOGFILE 2>&1
user $USER $PASSWORD
cd $DIR
put $mainfile
ls -l
eof
then
rm /path/test/$file2del
fi
This will delete the file if the ftp was successful.
Be aware that encoding a password in a script is typically considered to be "bad". Please consider using a .netrc file. Or moving to ssh/scp/sftp with keys. If the latter is an option, man rsync (linux) may be of use.