Thursday, 15 May 2014

bash - script to zip a file and change it's owenrships -



bash - script to zip a file and change it's owenrships -

i have script working on reads off of text file , utilize info stored in text file set each line entered in array. array reference files imported directory in script. problem built function zip contents of directory , alter it's ownerships, when run script zipping , attempting alter ownerships of pwd. here code below:

file=~/exporttool/zipfiles.txt index=0 declare -a studyinstanceuids while read line ; studyinstanceuids[$index]="$line" index=$((index+1)) echo $line done < $file in "${studyinstanceuids[@]}" echo "$i" | ./cmd2; done echo "exams in!"; ##function argument take prompt alter ownerships echo "what name of owner: " read $owner zipforowner(){ arg1=$1 in "${studyinstanceuids[@]}"; zip -r ~/export/"${studyinstanceuids[@]}"/20140620_"${studyinstanceuids[@]}".zip . sudo chown $1:$1 ~/export/"${studyinstanceuids[@]}"/"${studyinstanceuids[@]}".zip sudo mv ~/export/"${studyinstanceuids[@]}"/"${studyinstanceuids[@]}".zip ~/home/"$1" done } zipforowner $owner exit;

does have suggestions

edit: heere results running in xterm

+ file=/home/support/exporttool/zipfiles.txt + index=0 + declare -a studyinstanceuids + read line + studyinstanceuids[$index]=1.3.46.670589.16.11.8.34254330145.20140603.134057.0 + index=1 + echo 1.3.46.670589.16.11.8.34254330145.20140603.134057.0 1.3.46.670589.16.11.8.34254330145.20140603.134057.0 + read line + in '"${studyinstanceuids[@]}"' + echo 1.3.46.670589.16.11.8.34254330145.20140603.134057.0 + ./cmd2 please come in studyinstanceuid: + echo 'exams in!' exams in! + echo 'what name of owner: ' name of owner: + read sftpuser + zipforowner + arg1= + in '"${studyinstanceuids[@]}"' + zip -r /home/support/export/1.3.46.670589.16.11.8.34254330145.20140603.134057.0/20140620_1.3.46.670589.16.11.8.34254330145.20140603.134057.0.zip . adding: .studiestoexportsend.txt.swp^c zip error: interrupted (aborting) + sudo chown : /home/support/export/1.3.46.670589.16.11.8.34254330145.20140603.134057.0/1.3.46.670589.16.11.8.34254330145.20140603.134057.0.zip [sudo] password support:

this line problem:

zip -r ~/export/"${studyinstanceuids[@]}"/20140620_"${studyinstanceuids[@]}".zip .

you're attempting create zip file called ~/export/"${studyinstanceuids[@]}"/20140620_"${studyinstanceuids[@]}".zip (good) of contents in current directory . (bad).

you need alter . folder want zipped.

bash shell

No comments:

Post a Comment