Not correct processing of “\ “ in names of dirs inside shell script (tar command - system backup scr
Hello,
Recently, I've started with shell scripting, and decided to write a script for my system backup using tar. When I was dealing with tar execution inside shell script I found this, inside shell we have the following code:
with reflection
So, command should exclude “my songs” from gzip archive, bit it doesn't. If I execute this command directly in shell, everything is ok, but when the same is in shell script it doesn't work! I've tested with:
I'm using ubuntu 11.04
(Please note: with my backup and restore scripts I want to exclude all users folders with files like heavy video and audio etc., but not users settings (like .hidden_files))
I'm writing about “spaces” because”, my wife Dasha may create such directories. If you want to look on my scripts, see the attachments.
Will be appreciate for any answers and comments, why this happens.
P.S I live in Russia, so sorry if I have language mistakes, I'm studding English with passion in deed...
Thanks for reply
I,ve tried this, but unfortunately, it was included in tar archive anyway, the code, that does changes from " " => "\\ " inside dir names is:
Code:
OLD_IFS="$IFS"
IFS=""
USER_EXCLUDE=`ls -d ${HOME_DIR}/*/*/`
USER_EXCLUDE=`echo $USER_EXCLUDE | sed s/" "/"\\\\\\\\\\\\\ "/g`
USER_EXCLUDE=`echo $USER_EXCLUDE | sed s/"\(.*\)\/"/"--exclude=\1"/g`
IFS=$OLD_IFS
It's required so many \\\\\\\\\\\..., to reflect "\\"
If the value stored in the variable $EXCLUDE contains any IFS characters (by default, space, newline, and tab), after the shell expands $EXCLUDE into its value, it will split the resulting string into fields on those IFS characters. All the backslashes and quotes in the world within the value of $EXCLUDE won't stop that, since those backslashes and quotes are not in any way special to the shell (by the time field splitting begins, the parsing step that looks for quotes has completed).
I suppose there is no way to expand $EXCLUDE with correct meaning of "\ " I think this is kind of disadvantage of shell programming to traditional. There should be clear text manipulation(processing) mechanism...
[/CODE]It's required so many \\\\\\\\\\\..., to reflect "\\"
That's because you're using double-quotes, where the shell handles escaping itself and needs two to tell it to ignore it. Try single single-quotes, where escaping doesn't happen in the shell:
Code:
's/ /\\ /g' is equivalent to "s/ /\\\ /g"
And you can single-quote just part of an expression too, the way you've been doing with double quotes.
I just remembered another trick: IFS=$'\n' This will cause the shell to split only on newlines when expanding variables -- spaces in directory names won't bother it at all. IFS is a special variable telling it how to expand variables and how to split when using read. This is the 'clear text processing mechanism' you wanted
Last edited by Corona688; 06-10-2011 at 01:46 PM..
Hi,
i have a source file and have 3 columns and separated by "|" .i want to split this 3 columns in different variable.When i am executing this values indivisually giving correct result but when the same execute inside a for loop,it's giving issues.
Src file(jjj.txt)
-------... (8 Replies)
Hello All,
I need immediate help in creating shell script to call archivebkup.ksh script when archive file system capacity reaches threshold value or 60%
Need to identify the unique file system that reaches threshold value.
ex:
capacity
... (4 Replies)
hii,,
I am trying to automate jira. during my scripting using bash script, in the terminal i got the terminal message like this:
"Configure which ports JIRA will use.
JIRA requires two TCP ports that are not being used by any other
applications on this machine. The HTTP port is where you... (1 Reply)
Guys,
I need you help please.
The script below is not working correclty for checking via a awk/if statement . Can you tell me what i am doing wrong in the script code "if($1 == "$RETENTION_LEVEL") "
Syntax
RETENTION_LEVEL=`echo $LINE | cut -f2 -d" "`
echo " ==============... (4 Replies)
Hi All,
Is there any way to monitor a command inside shell script ? I have a script inside which I have a tar command which zips around 200GB data.
tar zcvf $Bckp_Dir/$Box-BaseBackup-$Day.tar.gz * --exclude 'dbserver_logs/*' --exclude postmaster.pid --exclude 'pg_xlog/*'
I want to... (3 Replies)
hi all
im making a script for backing up a specific filesystem that is an output of our DB13(SAP) into tape..which is around 40g +
which is suitable tar or backup command
i heard tar has limitations ..i heard it can only backup upto 2 gig??? is this ryt?
and ill put this into cron.
... (6 Replies)
hi,
i wat to get the output of a grep command in a file. but when i am trying out the same grep command in the unix prompt its working fine.. i am getting the output properly.. but when i am writing the same command inside my shell script , its just creating a new output file with no contents... (1 Reply)
Please help me in resolving the issue.
I have taken backup using the below command
$ tar cvf - . |compress -> /opt/globusback2/needed_backups/apglsg.tar.Z
I tried to restore the backup using the below command.
$ zcat /opt/globusback2/needed_backups/apglsg.tar.Z | tar -xvf -
... (2 Replies)
Hi,
I am using tar cvf inside a shell script to archive files.
Is there an option to surpress any prompts which come up if the desired archive name already exists ?
Thanks in Advance.
Kas. (2 Replies)