Using tar with wildcards & space in file hierarchy

Hello,

I am creating a script to collect some log files on each system, archive them and compress them.

This is what I have so far.

Code:
#!/bin/sh

# ~sedna log reporter.sh
# 
#
# Created by Dan Hayman on 27/08/2011.
# Copyright 2011 __MyCompanyName__. All rights reserved.

# Some Log Locations
# ~/Library/Logs/PresenterScheduler
# ~/Library/Logs/PresenterSync
# ~/Library/Logs/presenterPlayer
# ~/Library/Application\ Support/Presenter\ Player/de.sedna.PresenterPlayer.Screen?.plist

# ~/Library/Logs/DiagnosticReports
# ~/Library/Logs/CrashReporter

# Somewhere to store the report... does it exist?
if [ ! -d ~/Documents/SednaReports ] 
then
mkdir ~/Documents/SednaReports
fi

# Gather the players name to use in tar.bz2 name
machineName=`uname -n`

# Gather the date to use in tar.bz2
date=-`date +'%d_%m_%y%H:%M:%S'`

# Create a system profile in user home
system_profiler -xml  -detailLevel full > ~/sysprofile.spx

# Create the file detailing the playout.presenter permissions in user home
ls -l -R ~/Library/Application\ Support/Presenter\ Player > ~/AppSupportDirListing.txt

# Create the archive
tar -jcf ~/Documents/SednaReports/$machineName$date.tar.bz2 sysprofile.spx AppSupportDirListing.txt -C
 `ls /var/log/system*` `ls ~/Library/Logs/CrashReporter/Presenter*` `ls
 ~/Library/Logs/DiagnosticReports/Presenter*` `ls ~/Desktop/BHX\ Service\ Machine/presenter-log-
 report/Users/sednaadmin/Library/Application\ Support/Presenter\ Player/playout.presenter/objects*` `ls
 ~/Desktop/BHX\ Service\ Machine/presenter-log-report/Users/sednaadmin/Library/Application\
 Support/Presenter\ Player/de.sedna.PresenterPlayer.Screen?.plist`

#Tidy up some files which are no longer needed.
rm ~/AppSupportDirListing.txt
rm ~/sysprofile.spx

My problem arises with the final two ls commands. It seems as though the tar command doesn't read spaces within names instead interprets two files or folders.

I need to use the ls command as it enables me to use wildcards to filter out any irrelevant files from the log report. I have read that tar does not like wildcards.

Any help will be gratefully received. If I haven't explained what I am trying to achieve effectively then please say and I will try to rephrase.


Cheers
Dan
 
SirDice - Will do, cheers for the link

phoenix - I can't rename the logs they are stored in that specific location by an application.

I suppose I could copy them to a temporary location which doesn't have spaces in. But surely there is a better solution?

Cheers
Dan
 
The wildcards are expanded by the shell, not ls(). Therefore replace things like
Code:
`ls /var/log/system*`
by simply
Code:
/var/log/system*

The shell will not split the results of pathname generation again.
 
Back
Top