HPE GreenLake Administration
- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- SFTP script
Operating System - Linux
1828418
Members
3662
Online
109977
Solutions
Forums
Categories
Company
Local Language
back
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
back
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-24-2005 02:53 AM
10-24-2005 02:53 AM
SFTP script
I want to write a customized sftp script.
1> Check for some particular files..
2> IF file exists send check for destination ping/ssh.
3> Put file across to destination host.
4> Mail across result of success fail to a address..
Anyone has it in place? Or idea's, please send across..
Thanks and regards
Prashant
1> Check for some particular files..
2> IF file exists send check for destination ping/ssh.
3> Put file across to destination host.
4> Mail across result of success fail to a address..
Anyone has it in place? Or idea's, please send across..
Thanks and regards
Prashant
"Intellect distinguishes between the possible and the impossible; reason distinguishes between the sensible and the senseless. Even the possible can be senseless."
- Tags:
- sftp
2 REPLIES 2
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-24-2005 03:42 AM
10-24-2005 03:42 AM
Re: SFTP script
Hi Prashant,
Try the following script. Modify according to your servers / setup.
#! /usr/bin/ksh
cls
echo
echo
echo
echo " SCRIPT TO SCP THE ARCHIVE LOGS TO DR "
echo
echo
echo
echo "Enter the Starting Sequence Archive no to scp: \c"
read a
echo "Enter the Ending Sequence Archive no to scp: \c"
read b
if [ \( `ls -lrt | grep -i $a | wc -l` = 1 \) -a \( `ls -lrt | grep -i $b | wc -l` = 1 \) ]
then
echo
else
echo "Uniqueness failed, recheck your file name and enter again"
exit
fi
reala=`ls -lrt | grep -i $a | awk '{print $9}'`
if [ $? = 0 ]
then
echo "Confirm the file to scp is $reala type (y or n): \c"
read ans1
if [ "$ans1" = "y" ]
then
echo
echo "scp will be started from file $reala \n"
echo
else
echo
echo "scp is aborted becoz of wrong file name $reala \n"
echo
exit 1
fi
else
echo "File with sequence $a doesn't exist \n"
fi
realb=`ls -lrt |grep -i $b | awk '{print $9}'`
if [ $? = 0 ]
then
echo "Confirm the Ending file to scp is $realb type (y or n): \c"
read ans2
if [ "$ans2" = "y" ]
then
echo
echo "scp will be started up to the file $realb \n"
echo
else
echo
echo "scp is aborted becoz of wrong file name $realb \n"
echo
exit 2
fi
else
echo
echo "File with sequence $b doesn't exist \n"
fi
reala1=`echo $reala | awk -F _ '{print $3}'|awk -F . '{print $1}'`
realb1=`echo $realb | awk -F _ '{print $3}'|awk -F . '{print $1}'`
while [ $reala1 -le $realb1 ]
do
# echo "present value is *$reala1* "
scp -p *$reala1* USERID@IP_OF_SERVER:/DIRECTORY_PATH
if [ $? = 0 ]
then
echo "Completed the scp of file `ls *$reala1*` on `date`" >> /tmp/scplogs
else
echo "COULD NOT DO SCP TO DR on `date` EITHER LINK IS DOWN / FILE SYSTEM IS FULL / DESTINATION INVALID " >> /tmp/scperror
mailx -s SCP_FAILED_TO_DR_CHECK_LINK EMAIL_ID < /tmp/scperror
exit
fi
reala1=`expr $reala1 + 1 `
done
exit
Hope this helps.
Syam
Try the following script. Modify according to your servers / setup.
#! /usr/bin/ksh
cls
echo
echo
echo
echo " SCRIPT TO SCP THE ARCHIVE LOGS TO DR "
echo
echo
echo
echo "Enter the Starting Sequence Archive no to scp: \c"
read a
echo "Enter the Ending Sequence Archive no to scp: \c"
read b
if [ \( `ls -lrt | grep -i $a | wc -l` = 1 \) -a \( `ls -lrt | grep -i $b | wc -l` = 1 \) ]
then
echo
else
echo "Uniqueness failed, recheck your file name and enter again"
exit
fi
reala=`ls -lrt | grep -i $a | awk '{print $9}'`
if [ $? = 0 ]
then
echo "Confirm the file to scp is $reala type (y or n): \c"
read ans1
if [ "$ans1" = "y" ]
then
echo
echo "scp will be started from file $reala \n"
echo
else
echo
echo "scp is aborted becoz of wrong file name $reala \n"
echo
exit 1
fi
else
echo "File with sequence $a doesn't exist \n"
fi
realb=`ls -lrt |grep -i $b | awk '{print $9}'`
if [ $? = 0 ]
then
echo "Confirm the Ending file to scp is $realb type (y or n): \c"
read ans2
if [ "$ans2" = "y" ]
then
echo
echo "scp will be started up to the file $realb \n"
echo
else
echo
echo "scp is aborted becoz of wrong file name $realb \n"
echo
exit 2
fi
else
echo
echo "File with sequence $b doesn't exist \n"
fi
reala1=`echo $reala | awk -F _ '{print $3}'|awk -F . '{print $1}'`
realb1=`echo $realb | awk -F _ '{print $3}'|awk -F . '{print $1}'`
while [ $reala1 -le $realb1 ]
do
# echo "present value is *$reala1* "
scp -p *$reala1* USERID@IP_OF_SERVER:/DIRECTORY_PATH
if [ $? = 0 ]
then
echo "Completed the scp of file `ls *$reala1*` on `date`" >> /tmp/scplogs
else
echo "COULD NOT DO SCP TO DR on `date` EITHER LINK IS DOWN / FILE SYSTEM IS FULL / DESTINATION INVALID " >> /tmp/scperror
mailx -s SCP_FAILED_TO_DR_CHECK_LINK EMAIL_ID < /tmp/scperror
exit
fi
reala1=`expr $reala1 + 1 `
done
exit
Hope this helps.
Syam
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-24-2005 03:45 AM
10-24-2005 03:45 AM
Re: SFTP script
One more thing...
You will need to enable an scp without password to make this script enabled. You can do this by generating authorized_keys in /.ssh folder.
The above script will also store your error and log files in specific files.
Wish you good luck
Regards,
Syam
You will need to enable an scp without password to make this script enabled. You can do this by generating authorized_keys in /.ssh folder.
The above script will also store your error and log files in specific files.
Wish you good luck
Regards,
Syam
- Tags:
- scp
The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
Company
Support
Events and news
Customer resources
© Copyright 2025 Hewlett Packard Enterprise Development LP