nixCraft Linux Forum

nixCraft

Linux / UNIX Tech Support Forum

script for automation

This is a discussion on script for automation within the Shell scripting forums, part of the Development/Scripting category; I have a list of files for creating a package.But before going ahead with package i have to check for ...


Go Back   nixCraft Linux Forum > Development/Scripting > Shell scripting

Linux answers from nixCraft.


Shell scripting You can discuss the shell scripting, request shell scripts and scripting techniques

Reply

 

LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 05-05-2009, 03:27 PM
Junior Member
User
 
Join Date: Apr 2009
OS: Debian
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
huntethan is on a distinguished road
Exclamation script for automation

I have a list of files for creating a package.But before going ahead with package i have to check for the file paths

for eg:after running find command on prompt i get
cd acebill
find . -name CR09041494_final.xls
./promo/data/CR09041494_final.xls

find . -name CR09041495_final.xls
./promo/data/CR09041495_final.xls

find . -name ITC0904216703.sql
./promo/sql/swb/ITC0904216703.sql

find . -name Execution_Instructions_RLSE04222009.doc
./promo/doc/Execution_Instructions_RLSE04222009.doc

After getting the path under acebill i have to create a directory named current with same directory structure as found out from find command for the files.
for eg:
like from above find commands
mkdir -p current/promo/data
mkdir -p current/promo/doc
mkdir -p current/promo/sql/swb

after creation of this directory structure i have to copy these files from their previous directories to their corresponding new location
for eg:
$ cd acebill
$ cp promo/data/CR09041494_final.xls current/promo/data
$ cp promo/data/CR09041495_final.xls current/promo/data
$ cp promo/doc/Execution_Instructions_RLSE04222009.doc current/promo/doc


please suggest me a script which can automate this process for number of a large number of files
Reply With Quote
  #2 (permalink)  
Old 05-05-2009, 07:26 PM
nixcraft's Avatar
Never say die
User
 
Join Date: Jan 2005
Location: BIOS
OS: RHEL
Scripting language: Bash and Python
Posts: 2,710
Thanks: 11
Thanked 245 Times in 184 Posts
Rep Power: 10
nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute
Default

Use dirname to get directory names:
Code:
 dirname /promo/doc/Execution_Instructions_RLSE04222009.doc
/promo/doc
Next, use variable to store it and create a dir:
Code:
BASE=/home/test
D=$(dirname /promo/doc/Execution_Instructions_RLSE04222009.doc)
mkdir -p $BASE/$D
cp /promo/doc/Execution_Instructions_RLSE04222009.doc $BASE/$D
Use for loop to automate above procedure.
__________________
Vivek Gite
Linux Evangelist
Be proud RHEL user, and let the world know about your enterprise choices! Join RedHat user group.
Always use CODE tags for posting system output and commands!
Do you run a Linux? Let's face it, you need help
Reply With Quote
  #3 (permalink)  
Old 19-05-2009, 04:17 AM
Member
User
 
Join Date: May 2009
OS: Mandriva
Posts: 82
Thanks: 0
Thanked 16 Times in 16 Posts
Rep Power: 3
cfajohnson has a spectacular aura about cfajohnson has a spectacular aura about cfajohnson has a spectacular aura about
Default

[QUOTE=nixcraft;18814]Use dirname to get directory names:
Code:
 dirname /promo/doc/Execution_Instructions_RLSE04222009.doc

There's no need to use an external command:

Code:
file=/promo/doc/Execution_Instructions_RLSE04222009.doc
dirname=${file%/*}
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off



All times are GMT +5.5. The time now is 05:38 AM.


Powered by vBulletin® Version 3.8.5 - Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2
©2005-2010 nixCraft. All rights reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38