Linux / UNIX Tech Support Forum
This is a discussion on Wanting to check before running... within the Shell scripting forums, part of the Development/Scripting category; The following code is designed to clean out any unwanted "._" Mac OS specific files which have accidentally gotten included ...
|
|||||||
| Shell scripting You can discuss the shell scripting, request shell scripts and scripting techniques |
![]() |
|
|
LinkBack | Thread Tools | Display Modes |
|
|||
|
The following code is designed to clean out any unwanted "._" Mac OS specific files which have accidentally gotten included in a number of Zip archives. There are 247 files and this seems a good place to use some scripting to do the work. The following seems to work OK, but before I run it on the entire lot of files I thought it would be good to have someone who is more experienced look over my code. I do not have much experience with Bash and don't want to make a boatload of unwanted problems for myself.
Code:
#!/bin/bash
# init
function pause(){
read -p "$*"
}
for f in `ls multipart/`
do
if [[ "$f" == *.zip ]]
then
echo "Processing $f file..."
mv multipart/$f multipart/__temp/ # Move zip file to temp dir.
unzip multipart/__temp/*.zip # Unzip archive.
rm multipart/__temp/*.zip # Remove the old zip archive.
rm multipart/__temp/._*.mp3 # Remove the Apple "._" files.
zip -r multipart/__temp/$f *.mp3 # Zip the mp3 files to a new archive.
mv multipart/__temp/$f multipart/ # Move the new archive back.
rm multipart/__temp/* # Remove any other temp files.
pause 'Press any key to continue...'
fi
done
Is there any reason to be concerned about running the above script on a Linux-based web server? I've found that if I interrupt the script and cancel it, and restart it that it seems to append to the original files and I end up with new archives which are twice as big as the originals. This does not seem right and I wonder if there is something obvious that I am doing wrong. Thanks for your time. Kind regards, Chris |
| Sponsored Links | ||
|
|
|
||||
|
I think for loop can be replaced with a find command and while loop:
Code:
for f in `ls multipart/` Code:
find /path/to/multipart -iname "*.zip" -print0 | while read -d $'\0' file do echo "Something on $file..." # note $file is double quoted mv "$file" multipart/__temp/ # Move zip file to temp dir. # add rest of the commands done
__________________
Vivek Gite Linux Evangelist |
|
|||
|
Quote:
Quote:
|
![]() |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) |
|
| Thread Tools | |
| Display Modes | |
|
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Running php as root | Leszek.T | Ubuntu / Debian | 9 | 01-10-2009 05:53 PM |
| Newbie running shall script | houssam_ballout | Shell scripting | 1 | 21-06-2009 04:08 PM |
| Getting Squid 3.0 up and running | Mic | Linux software | 4 | 18-05-2008 03:56 PM |
| how to enumerate currently running process | hiimsa | Coding in General | 2 | 11-11-2006 03:02 PM |
| How long the sys was running? | jithendra | Linux software | 2 | 16-10-2006 05:31 PM |