ksh : multiple for wordlists


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting ksh : multiple for wordlists
# 1  
Old 05-28-2013
ksh : multiple for wordlists

Hi guys

This is my first post on here and I am fairly new to ksh scripting, please be gentle!

I am trying to create a script that takes an fssnap of all slices and then .tar's them. The trouble that I am having is with the .tar element, I want it to label the .tar based on which slice it is currently tar'ing (i.e. root.tar, opt.tar, var.tar, etc).

This is what I have so far:

Code:
for slice in / /opt /var /export/home
   do
     echo "Archiving $slice"
     rootsnap=`fssnap -F ufs -o unlink,backing-store=/tmp/backup/$bckstore/root_snap $slice`
     mount -o ro $rootsnap /mnt
     tar cfpE $tarstore/root.tar /mnt          (<<<<---- I want this filename to change based on current slice)
     unount /mnt
     fssnap -d $slice
done


So the for statement cant be injected as a variable in the filename because of the characters, is there any way of adding multiple wordlists in the for statement?

Thanks

Andy

Last edited by joeyg; 05-28-2013 at 08:51 AM.. Reason: Please wrap code and data in CodeTags
# 2  
Old 05-28-2013
Quote:
Originally Posted by andy123
I am trying to create a script that takes an fssnap of all slices and then .tar's them. The trouble that I am having is with the .tar element, I want it to label the .tar based on which slice it is currently tar'ing (i.e. root.tar, opt.tar, var.tar, etc).
First off, you might want to get your wording compatible to the OS you are (now) working on: these are not "slices", but filesystems. It will help you accomodate to your environment by using the wording common to this platform. This has nothing to do with your problem, but i am sure will help in the long run.

Code:
for slice in / /opt /var /export/home
   do
     echo "Archiving $slice"
     rootsnap=`fssnap -F ufs -o unlink,backing-store=/tmp/backup/$bckstore/root_snap $slice`
     mount -o ro $rootsnap /mnt
     tar cfpE $tarstore/root.tar /mnt          (<<<<---- I want this filename to change based on current slice)
     unount /mnt
     fssnap -d $slice
done

hmm, the variables "$bckstore" and "$tarstore" are used, but nowhere defined. Further,

Code:
     rootsnap=`fssnap -F ufs -o unlink,backing-store=/tmp/backup/$bckstore/root_snap $slice`

should be written

Code:
     rootsnap=$(fssnap -F ufs -o unlink,backing-store=/tmp/backup/$bckstore/root_snap $slice)

because backticks should not be used any more. When you start to write ksh scripts, as you say, better start by developing good habits instead of bad ones.

Quote:
Originally Posted by andy123
So the for statement cant be injected as a variable in the filename because of the characters, is there any way of adding multiple wordlists in the for statement?
I am not sure what you mean by this. You have the value from the wordlist already in a variable, "$slice". What keeps you from using it like this:

Code:
     tar cfpE $tarstore/root.tar ${slice}

If your values contain whitespace (seems not to be the case in your code) you have to use quoting:

Code:
for value in a b "c d" e f ; do
     print - "${value}"
done

I hope this helps.

bakunin
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Multiple if within while loop ksh

Hi All, I'm trying to write while loop with multiple if conditions. Each and every if condition with different variables. whenever one if condition fails i have remove the file from filename and have to pick another file and loop should exit until the last file found in filename. Please help... (4 Replies)
Discussion started by: Kayal
4 Replies

2. UNIX for Beginners Questions & Answers

Urgent.!!! Multiple if within while loop ksh

Hi All, I'm trying to write while loop with multiple if conditions. Each and every if condition with different variables. whenever one if condition fails i have remove the file from filename and have to pick another file and loop should exit until the last file found in filename. Please help... (2 Replies)
Discussion started by: Kayal
2 Replies

3. Shell Programming and Scripting

How to run multiple Queries in a ksh Script?

How to run multiple Queries in a ksh Script I have a KSH script that has one SQL Query and generates and emails output of the query in HTML format. I want to change the script so that it has three SQL queries and the last query generates and emails the HTML output page of just that query. So far... (5 Replies)
Discussion started by: JolietJake
5 Replies

4. Shell Programming and Scripting

How to run multiple .py in ksh?

Hi programmers, say I have 4 files : file1.py,file2.py,file3.py,file4.py How do I, on a korn shell, create one file, run_all, that is one file that sequentially calls file1-file4, but only so if they complete w/o errors? Something like: #!/usr/bin/ksh file1.py /*......????*/ ... (7 Replies)
Discussion started by: sas
7 Replies

5. Shell Programming and Scripting

Read multiple input from CLI :ksh

Hi folks.. i got a requirement to red multiple directories from STDIN and store them to a variable. ex:- echo "Enter directory to add:" echo " Enter directory to add:" read value till there is input and when there is no input close the read loop and store variable into an array ... (1 Reply)
Discussion started by: bangaram
1 Replies

6. Shell Programming and Scripting

Multiple indexed conditions with ksh

Dear Unix Experts, I have randomly generated the x, y, and z coordinates of 16 atoms of two species, A and B (8 atoms each) Then I calculated the spacing between all the A atoms labeled d1, B atoms labeled d2 and between A and B atoms labeled d3. I would like to save the x, y, z coordinates to... (1 Reply)
Discussion started by: vahid
1 Replies

7. Shell Programming and Scripting

ksh Multiple Pattern Matching Operators

I figured this would be simple, but I am stuck. Variable longpath="/dir1/dir2/dir3/filename.stuff.morestuff.garbage" I want to end up with just "filename.extra.moreextra". So, I want to get rid of the path and .garbage I want to do this with just ksh internals. So, no sed,grep,awk,expr,... (4 Replies)
Discussion started by: Topaz
4 Replies

8. Shell Programming and Scripting

ksh to copy multiple files

Guys, I've got a list of about 200 files I need to copy from /tmp to /data. I can't use wildcards because the filenames are all very different. What I want to do is cut and paste them into a file and read that as the input to a copy command (line by line). I tried using find and -exec... (4 Replies)
Discussion started by: Grueben
4 Replies

9. Shell Programming and Scripting

Stringing Multiple commands together in KSH

I am trying to to this findCDZfile=`ls -at `find /opt/apps/busobj/bobj/bobje/data/ -name CDZ*.tmp`` and it doesn't seem to like me - is there a special escape character I need to use? (2 Replies)
Discussion started by: cpare
2 Replies

10. UNIX for Advanced & Expert Users

batch or wordlists search and replace

Hello Experts! I've become perplexed :confused: as to why I can't get this to work and have given up the male "I can do it" attitude. I am asking the unix experts. The script I am writing involves reading a file that contains thousands of keywords (not csv), just one line after another of... (0 Replies)
Discussion started by: zerobreach.com
0 Replies
Login or Register to Ask a Question