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. |
What have you tried before? Can you perform the steps at the command prompt?
|
Quote:
thx |
Quote:
|
Also remembering that a script is just what you enter on the command line put in a file :)
|
thx reply ,
i just tried it , it seems works . for file in $(< dummy.txt); do base=${file%.prn} scp /tmp/$base.xls remote:/tmp done But I have another requirement - actually , the file name in dummy.txt have two type of prefix , one is xxx ( eg. xxxfile.prn ) , another one is yyy ( eg. 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 ? |
You should bookmark these
http://rute.2038bug.com/index.html.gz http://tldp.org/LDP/Bash-Beginners-G...tml/index.html http://www.tldp.org/LDP/abs/html/ You'll save yourself a lot of time in the long run if you learn bash and associated tools. Try the Substring Extraction section here http://tldp.org/LDP/abs/html/string-manipulation.html to extract eg xxx or yyy from the $base & then match it. |
Assuming you have a recent enough version of bash, the regex comparison operator =~ will probably be useful.
|
Quote:
thx |
Please use [code][/code] tags around your code and data, to preserve formatting and to improve readability. Please do not use quote tags, colors, or other fancy formatting.
You might want to try giving us some actual examples of filenames and directory trees to work with, rather than trying to describe them. Anyway, your loop is very close, except: don't read lines with for! Use a while+read loop instead. Or read the file into an array first with the mapfile command, and loop over that. As for your new requirement, I suggest simply adding a case statement to the loop to test the naming pattern of each file, and run the appropriate command. Code:
case $file in The Bash Guide is a good resource that covers all the basics of scripting. Check it out: http://mywiki.wooledge.org/BashGuide |
All times are GMT -5. The time now is 11:46 AM. |