Computing.Net > Forums > Unix > SCP script

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

SCP script

Reply to Message Icon

Name: stant
Date: February 7, 2004 at 17:56:14 Pacific
OS: Solaris
CPU/Ram: 16 GB
Comment:

Hi,

I need some help to write up a script that searches directory for *.txt files, scp's them to a remote server, puts the files into a bkup directory locally. IF scp has not completed successfully script notifies me via email.

Thanks much!




Sponsored Link
Ads by Google

Response Number 1
Name: Dlonra
Date: February 8, 2004 at 08:05:47 Pacific
Reply:

how far along are you?


0

Response Number 2
Name: stant
Date: February 9, 2004 at 21:09:18 Pacific
Reply:

I am a unix newbie and looking for some help getting on the way. Does this look ok? Feel free to critize.

umask 000
DIR=/usr/files;
BKUPDIR=/bkup/addr_files;
RSYS=iss04
REMOTEUSER=xyc26
REMOTEDIR=/datafiles

export RSYS REMOTEDIR REMOTEUSER
# copy all address files to remote server.
for file in `/bin/ls $DIR/address*.txt`
do
if [ -s "$file" ] then
echo "Copying file to $RSYS..."
/usr/local/bin/scp $file REMOTEUSER@$RSYS:$REMOTEDIR
# backup all address files on local server.
/usr/bin/mv "$file" $BKDIR 2> /dev/null;
echo $Done." ;
fi
done
/usr/bin/find /usr/files -name 'address*.txt' -mtime +120 -exec rm {} \;

Thanks!


0

Response Number 3
Name: aigles
Date: February 10, 2004 at 05:36:19 Pacific
Reply:


echo "Copying file to $RSYS..."
/usr/local/bin/scp $file $REMOTEUSER@$RSYS:$REMOTEDIR

if [ $? -eq 0 ]
then
# backup all address files on local server.
/usr/bin/mv "$file" $BKDIR 2> /dev/null;
echo "Done." ;
else
# mail error
echo "Failed to copy file $file $RSYS:$REMOTEDIR" | mail -s "$0 - Error" dest_user
echo "Error"
fi

Jean-Pierre.


0

Response Number 4
Name: stant
Date: February 11, 2004 at 17:32:01 Pacific
Reply:

Thanks Jean-Pierre!


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: SCP script

Test ssh connection from KSH script www.computing.net/answers/unix/test-ssh-connection-from-ksh-script/6950.html

cron/scp/expect Problem www.computing.net/answers/unix/cronscpexpect-problem/5307.html

Status of a remote file using SCP? www.computing.net/answers/unix/status-of-a-remote-file-using-scp/7390.html