|
Home > Archive > Unix Shell > November 2006 > Passing values from a file to a command in a for loop?
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Passing values from a file to a command in a for loop?
|
|
|
| Hello
I am writing a shell script that will perform tasks required for
offsiting our backup tapes.
The script will run and generate a list of tapes that need to go
offsite and their current status which can be full or appendable. This
list looks like this:
IBM0010 Full
IBM0011 Appendable
IBM0023 Full
The first column is the media id and the second is it's status. I want
to use this information and pass it to a command that will change the
tapes status to offsite. To do this I need to pass the media id and the
numerical status + 64 to the command. E.g. the numeric status of Full
is 4 and the numeric status of Appendable is 8. So to set IBM0010 to
offsite I run the command:
tvol update,IBM0010,,,,,,68,
And to set IBM0011 to offsite I run the command:
tvol update,IBM0011,,,,,,72,
I'm trying to find the best way of doing this - I'm looking at using a
for loop (is this the best way) but I'm having problems trying to work
out how to pass the parameters to the command.
Any ideas?
Thanks
Pete
| |
| Bill Marcum 2006-11-28, 1:17 pm |
| On 28 Nov 2006 07:29:54 -0800, Pete
<petejones1974@hotmail.com> wrote:
> Hello
> I am writing a shell script that will perform tasks required for
> offsiting our backup tapes.
> The script will run and generate a list of tapes that need to go
> offsite and their current status which can be full or appendable. This
> list looks like this:
>
> IBM0010 Full
> IBM0011 Appendable
> IBM0023 Full
>
> The first column is the media id and the second is it's status. I want
> to use this information and pass it to a command that will change the
> tapes status to offsite. To do this I need to pass the media id and the
> numerical status + 64 to the command. E.g. the numeric status of Full
> is 4 and the numeric status of Appendable is 8. So to set IBM0010 to
> offsite I run the command:
>
> tvol update,IBM0010,,,,,,68,
>
> And to set IBM0011 to offsite I run the command:
>
> tvol update,IBM0011,,,,,,72,
>
> I'm trying to find the best way of doing this - I'm looking at using a
> for loop (is this the best way) but I'm having problems trying to work
> out how to pass the parameters to the command.
> Any ideas?
> Thanks
> Pete
>
while read id status; do
case $status in
Full) new_status=68 ;;
Appendable) new_status=72 ;;
*) echo "Unknown status: $id $status" >&2; exit ;;
esac
tvol update,$id,,,,,,$new_status,
done < file
--
Immortality consists largely of boredom.
-- Zefrem Cochrane, "Metamorphosis", stardate 3219.8
| |
|
| Pete wrote:
> Hello
> I am writing a shell script that will perform tasks required for
> offsiting our backup tapes.
> The script will run and generate a list of tapes that need to go
> offsite and their current status which can be full or appendable. This
> list looks like this:
>
> IBM0010 Full
> IBM0011 Appendable
> IBM0023 Full
>
> The first column is the media id and the second is it's status. I want
> to use this information and pass it to a command that will change the
> tapes status to offsite. To do this I need to pass the media id and the
> numerical status + 64 to the command. E.g. the numeric status of Full
> is 4 and the numeric status of Appendable is 8. So to set IBM0010 to
> offsite I run the command:
>
> tvol update,IBM0010,,,,,,68,
>
> And to set IBM0011 to offsite I run the command:
>
> tvol update,IBM0011,,,,,,72,
>
> I'm trying to find the best way of doing this - I'm looking at using a
> for loop (is this the best way) but I'm having problems trying to work
> out how to pass the parameters to the command.
> Any ideas?
Not sure I understand correct, but try this...
awk 'BEGIN { offset = 64
s["Full"]=4
s["Appendable"]=8
}
{ print "tvol update,"$1",,,,,,"offset+s[$2]"," }
' your_file
....(assuming your input data in 'your_file') to get that result...
tvol update,IBM0010,,,,,,68,
tvol update,IBM0011,,,,,,72,
tvol update,IBM0023,,,,,,68,
Janis
> Thanks
> Pete
|
|
|
|
|