- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: New script (to copy files)
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
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
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
тАО05-21-2012 03:23 AM
тАО05-21-2012 03:23 AM
New script
I would like to have a new script to perform the below task .
I have a file called dummy.txt , the content of this file is as below .
aaa.prn
bbb.prn
ccc.prn
I would like to have a script which can do
1) check dummy.txt
2) then copy these files ( but with other extension .xls ) from a specify directory to another server
eg. scp the files /tmp/aaa.xls , /tmp/bbb.xls , /tmp/ccc.xls to /tmp of another server
can advise what can i do ?
thanks in advance.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-21-2012 12:33 PM
тАО05-21-2012 12:33 PM
Re: New script (to copy files)
You could do something like:
for file in $(< dummy.txt); do
base=${file%.prn} # strip suffix
scp /tmp/$base.xls remote:/tmp
done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-21-2012 08:23 PM
тАО05-21-2012 08:23 PM
Re: New script (to copy files)
it works , but may I have two additional requirement .
1) actually , the file name in dummy.txt have two type of prefix , one is xxx ( eg. xxxfile.prn ) , another one is yyy ( yyyfile.prn ) , if the file is xxx , then copy to /tmp of another server , if the file is yyy then copy to /tmp1 of another server , can advise what can i do ?
2) scp works fine to copy to remote server , can advise how to check and display if the scp is successful on the screen or not ?
thx
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-22-2012 12:09 AM - edited тАО05-22-2012 05:52 PM
тАО05-22-2012 12:09 AM - edited тАО05-22-2012 05:52 PM
Re: New script (to copy files)
>1) the filename in dummy.txt have two type of prefix, one is xxx (eg. xxxfile.prn), another one is yyy (yyyfile.prn), if the file is xxx , then copy to /tmp of another server, if the file is yyy then copy to /tmp1 of another server?
>2) can advise how to check and display if the scp is successful on the screen or not?
Did you want to remove that prefix? I'm not doing it here.
for file in $(< dummy.txt); do
base=${file%.prn} # strip suffix
if [[ $base = xxx* ]]; then
server=server1
tmp=/tmp
elif [[ $base = yyy* ]]; then
server=server2
tmp=/tmp1
else
echo "Not sure where to send $file" 1>&2
continue
fi
scp /tmp/$base.xls $server:$tmp
if [ $? -ne 0 ]; then
echo "scp failed to copy $file" 1>&2
fi
done