Hi there, I hope you're good...
I am new to linux commands and shell scripting and would like to create a .sh script on a linux server to download data from an external FTP site to our internal ftp site and then transfer the data to a share on a windows fileserver. i would also like to create a notification email when the process is complete. Any help would be greatly appreciated?
Here is a script we use to upload data to the external FTP but I now need to create one for downloading the data:
#!/bin/bash
# FTP settings
HOST='example.co.uk'
USER='user'
PASSWD='example'
TMPUPABC='/ftp/FTPSITE/tmpupload'
MNTDIRABC='/mnt/server_mastershare/FTPSITE/To_example_ABC'
MNTARCABC='/mnt/server_mastershare/FTPSITE/Archive_Upload_ABC'
# Email settings
SUBJECT="FTP upload for ABC"
EMAIL="Joe.Bloggs@example.co.uk"
EMAILMESSAGEABC="/ftp/FTPSITE/FTPSITEemailmessageABC.txt"
FTPRESULT="/ftp/FTPSITE/ftpresult.txt"
# Other variables
DATE=`date +%Y-%m-%d_%H%M`
# Start of main script
# look for empty dir and generate email if files found
if [ "$(ls -A $MNTDIRABC)" ]; then
mkdir /mnt/server_mastershare/FTPSITE/Archive_upload_ABC/$DATE
cp -r $MNTDIRABC/* /mnt/server_mastershare/FTPSITE/Archive_upload_ABC/$DATE
mv -f $MNTDIRABC/* $TMPUPABC
cd $TMPUPABC
echo "FTP to FTPSITE for ABC : found the following files and will now attempt to upload them"> $EMAILMESSAGEABC
echo "**********************************************************************">> $EMAILMESSAGEABC
tree $TMPUPABC >>$EMAILMESSAGEABC
echo "**********************************************************************">> $EMAILMESSAGEABC
echo "Listing of remote server">> $EMAILMESSAGEABC
echo "**********************************************************************">> $EMAILMESSAGEABC
# Connect to remote server using lftp and sync 'up'
lftp -u user,example sftp://example.co.uk <<EOD
cd from_gbo
cd ABC
mirror -R --Remove-source-files
ls >> $EMAILMESSAGEABC
quit 0
EOD
/usr/bin/mail -s "$SUBJECT" "$EMAIL" < $EMAILMESSAGEABC
# Tidy files & folders
rm -rf $TMPUPABC/*
rm -rf $EMAILMESSAGEABC
else
echo "$TMPDUPABC is Empty"
fi
I am new to linux commands and shell scripting and would like to create a .sh script on a linux server to download data from an external FTP site to our internal ftp site and then transfer the data to a share on a windows fileserver. i would also like to create a notification email when the process is complete. Any help would be greatly appreciated?
Here is a script we use to upload data to the external FTP but I now need to create one for downloading the data:
#!/bin/bash
# FTP settings
HOST='example.co.uk'
USER='user'
PASSWD='example'
TMPUPABC='/ftp/FTPSITE/tmpupload'
MNTDIRABC='/mnt/server_mastershare/FTPSITE/To_example_ABC'
MNTARCABC='/mnt/server_mastershare/FTPSITE/Archive_Upload_ABC'
# Email settings
SUBJECT="FTP upload for ABC"
EMAIL="Joe.Bloggs@example.co.uk"
EMAILMESSAGEABC="/ftp/FTPSITE/FTPSITEemailmessageABC.txt"
FTPRESULT="/ftp/FTPSITE/ftpresult.txt"
# Other variables
DATE=`date +%Y-%m-%d_%H%M`
# Start of main script
# look for empty dir and generate email if files found
if [ "$(ls -A $MNTDIRABC)" ]; then
mkdir /mnt/server_mastershare/FTPSITE/Archive_upload_ABC/$DATE
cp -r $MNTDIRABC/* /mnt/server_mastershare/FTPSITE/Archive_upload_ABC/$DATE
mv -f $MNTDIRABC/* $TMPUPABC
cd $TMPUPABC
echo "FTP to FTPSITE for ABC : found the following files and will now attempt to upload them"> $EMAILMESSAGEABC
echo "**********************************************************************">> $EMAILMESSAGEABC
tree $TMPUPABC >>$EMAILMESSAGEABC
echo "**********************************************************************">> $EMAILMESSAGEABC
echo "Listing of remote server">> $EMAILMESSAGEABC
echo "**********************************************************************">> $EMAILMESSAGEABC
# Connect to remote server using lftp and sync 'up'
lftp -u user,example sftp://example.co.uk <<EOD
cd from_gbo
cd ABC
mirror -R --Remove-source-files
ls >> $EMAILMESSAGEABC
quit 0
EOD
/usr/bin/mail -s "$SUBJECT" "$EMAIL" < $EMAILMESSAGEABC
# Tidy files & folders
rm -rf $TMPUPABC/*
rm -rf $EMAILMESSAGEABC
else
echo "$TMPDUPABC is Empty"
fi