I am trying to create a script that will read directories over 180 days so I can tar them and back them up. I am stuck on this part.
When I run this I get "expr: syntax error"
If i replace
FIND_OLD_DIR='find . -type d -mtime +180' with
FIND_OLD_DIR='WELCOME'
then it works and displays "LCOM"
I am assuming it is because FIND_OLD_DIR is holding multiple values from my multiple directories.
My question is how do I make this work. Do I need an array? Do I write it out to a file and then read the file back in one at a time? What is the easiest way. I am new to shell scripting.
FIND_OLD_DIR is holding the literal string "find . -type d -mtime +180". You used single quotes, not backticks.
You don't need backticks or eval, though. Which is good because
1) Backticks can only hold a limited number of results
2) Eval is dangerous. If someone had a file named `rm -Rf ~/*` they'd have a real rotten day.
You also want find to stop when it matches a dir and match no deeper, otherwise it may find more folders inside the folder.
If you find thousands and thousands of directories, tar might be run more than once because there'd be too many filenames to fit in one call to tar. Hunting for folders instead of files should definitely reduce the number of things that need to be fed into tar, though.
---------- Post updated at 03:04 PM ---------- Previous update was at 02:45 PM ----------
If you're in Linux, you can avoid this limitation by feeding the filenames into tar with -T:
Last edited by Corona688; 09-23-2011 at 05:52 PM..
I an trying just the find command that you gave me but I am gettin the following error:
Error:
find: `\'!\'': No such file or directory
It does nothing of the sort when I copy-paste it into my shell, what did you actually do?
You still haven't put it in backticks, by the way, that's double-quotes. backticks are the same key as the tilde key minus the shift.
Quote:
If I type it out in the command line like this:
find . ! -name . -type d -mtime +180 -prune
it works fine...any suggestions??
Solving simple problems with eval is like mowing the lawn with a flamethrower -- silly, difficult, dangerous, often touches things you didn't mean to, and the result is almost never exactly what you wanted. eval is to be avoided if you possibly can.
My suggestion is to use the code I gave you in the manner it's intended. Copy-paste it into your script, with comments or without, and it ought to work.
If my code doesn't do what you need, please explain what you're trying to do and I'll show you better ways to accomplish that than eval + backticks.
Hi All,
need help with reading the array and sum of the array elements.
given an array of integers of size N . You need to print the sum of the elements in the array, keeping in mind that some of those integers may be quite large.
Input Format
The first line of the input consists of an... (1 Reply)
hello,
i need a bit of help on how to do this effectively in bash without a lot of extra looping or massive switch/case
i have a long array of M elements and a short array of N elements, so M > N always. M is not a multiple of N.
for case 1, I want to stretch N to fit M
arrayHuge
H = (... (2 Replies)
Hi All
I have multiple arrays like below.
set -A val1 1 2 4 5
set -A val2 a b c d
.
.
.
Now i would like to pass the individual arrays one by one to a function and display/ do some action.
Note : I am using ksh
Can you please advise any solution...
Thanks in advance. (7 Replies)
Trying to do some control flow parsing based on the index postion of an array member. Here is the pseudo code I am trying to write in (preferably in pure bash) where possible. I am thinking regex with do the trick, but need a little help.
pesudo code
if == ENDSINFIVEINTS ]]; then
do... (4 Replies)
I have an array and two variables as below,
I need to check if $datevar is present in $filename.
If so, i need to replace $filename with the values in the array.
I need the output inside an ARRAY
How can this be done.
Any help will be appreciated. Thanks in advance. (2 Replies)
Hi
I want to write a script which store all the parameters passed to the script into an array.
Once it is stored I want scan through the array and and delete those files for last month present inside the directory. The files in directory is appneded with YYYY_MM_DD.
I want to know how can I... (3 Replies)
Hi Everyone,
#!/usr/bin/perl
use strict;
use warnings;
my @test=("a;b;qqq;c;d","a;b;ggg;c;d","a;b;qqq;c;d");
would like to split the @test array into two array:
@test1=(("a;b;qqq;c;d","a;b;qqq;c;d"); and @test2=("a;b;ggg;c;d");
means search for 3rd filed.
Thanks
find the... (0 Replies)
Hi All,
I'm writing a nagios check that will see if our ldap servers are in sync...
I got the status data into a nested array, I would like to search key of each array and if "OK" is NOT present, echo other key=>values in the current array to a variable
so...eg...let take the single array... (1 Reply)
I am facing a strange error while creating posix threads:
Given below are two snippets of code, the first one works whereas the second one gives a garbage value in the output.
Snippet 1
This works:
--------------
int *threadids;
threadids = (int *) malloc (num_threads * sizeof(int));
... (4 Replies)
Hi,
I wish to store $string1 in $string1array a character in each array element.
Then i wish to echo the entire array to the screen so that it reads as the normal string again.
I have been trying with the code below but does not work. Please help...
To put string into array:
... (5 Replies)