- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: scp by using script
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Discussions
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
Community
Resources
Forums
Blogs
- 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
07-10-2013 08:35 AM
07-10-2013 08:35 AM
scp by using script
for i in hostname
do
scp -r target files $i:/home/testuser
done
exit
since i am going to perform scp for 150 servers,i need to redirect logs to a file.
i need to check if target files is copied to target host.
- Tags:
- redirection
- scp
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-10-2013 09:30 AM
07-10-2013 09:30 AM
Re: scp by using script
> since i am going to perform scp for 150 servers,i need to redirect logs to a file.
As with most other commands, you can do it with the >, >>, 2> and/or 2>> redirection operators.
The only trick is that you probably should use >>, so the logs of the later scp runs won't overwrite the log file of the previous run, but instead adds to it.
for i in hostname do scp -r target files $i:/home/testuser >>statistics.log 2>>errors.log done exit
> i need to check if target files is copied to target host.
The simplest way is to check the exit status of the scp command. "man scp" says it will be 0 if the copy operation is successful, and greater than 0 if not successful.
So:
for i in hostname do scp -r target files $i:/home/testuser >>statistics.log 2>>errors.log if [ $? -gt 0 ] then echo "*** Copy to host $i failed ***" >>errors.log fi done exit
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-10-2013 01:44 PM - edited 07-10-2013 01:45 PM
07-10-2013 01:44 PM - edited 07-10-2013 01:45 PM
Re: scp by using script
>The only trick is that you probably should use >>
You can redirect the output of the whole loop and you won't need that ">>":
for i in hostname; do
scp -r target files $i:/home/testuser
if [ $? -ne 0 ] then
echo "*** Copy to host $i failed ***" 1>&2
fi
done > statistics.log 2> errors.log
Contrary to the man page, your check on $? should really be -ne instead of -gt.