Labeling tapes in shell for loop breaking
Hi guys, I am attempting to label some tapes for amanda using amlabel in a for loop. However my for loop appears to be breaking:
Code:
#!/bin/bash Code:
su - amandabackup -c "for n in $(seq 1 10); do $AMLABEL $TAPEID $TAPEID\-${n} slot ${n}; done" Here is the error I get upon run: Code:
[root@amandaserver ~]# ./maketape.sh virtualtape Thanks |
It'll be easier to debug over several lines
Code:
#!/bin/bash The set cmd will show you exactly what the parser is doing. Some links http://rute.2038bug.com/index.html.gz http://tldp.org/LDP/Bash-Beginners-G...tml/index.html http://www.tldp.org/LDP/abs/html/ |
Still banging head
So I simplified the script into the following one liner:
Code:
su - amandabackup -c "for n in $(seq 1 15); do echo ${n}; done" odd however because the loop executes fine as a standard user. It's when I use su - that it breaks. Code:
|
If you do a "set -x" in your current shell, the problem becomes obvious:
Code:
$ su - rnichols -c "for n in $(seq 1 15); do echo ${n}; done"
Code:
su - amandabackup -c "for n in \$(seq 1 10); do $AMLABEL $TAPEID $TAPEID-\${n} slot \${n}; done" Note: there is no need to escape the "-" sign as it is not a legal character for a variable name. |
Thanks rknichols,
It wasn't until I mulled over your responses 1 & 2 that it became somewhat clear of what was occurring. I guess the confusion comes here: Code:
-bash: -c: line 1: syntax error near unexpected token `2' I learned another thing about delayed execution from your post. I never even knew this existed. Thanks for the reply you have helped solve the mystery. |
Quote:
|
Understood, Thanks for the help. Finally got the tape labeling part done.
|
All times are GMT -5. The time now is 12:25 PM. |