I need help finding out why this script wont run. The chmod is okay, but i get an error saying that I need '&&' on line 5.
I think you missing a single quote '
it still says i need '&&' on line 5... does everything else look right?
here is how it looks now
try this
#! /bin/ksh
read x
for file in `ls -al | awk $6 == "Sep" && $7 < 18''`
do
mv $file ~/compressed.tar/$file
read x
done
for file in 'ls al | awk '$6 != "Sep"''
do
mv $file ~/compressed.tar/$file
read x
done
tar -cvf compressed.tar
Anyways, what are you trying to achive here??
i get
but no more '&&' needed in line 5... thanks for helping.
Oops try this
read x
for file in `ls -al | awk '{$6 == "Sep" && $7 < "18"}'`
do
mv $file ~/compressed.tar/$file
read x
done
for file in 'ls al | awk '{$6 != "Sep"}'
do
mv $file ~/compressed.tar/$file
read x
done
tar -cvf compressed.tar sourcefilename
hitmansilentass,
what do think this will do?
ls -al | awk '{$6 == "Sep" && $7 < "18"}'
could you rephrase the question to be an informative statement?
thank you for being patient w/ me...
ls -al | awk '{$6 == "Sep" && $7 < "18"}'
I have changed the syntax of the awk command. and i am not sure what exactly tefflox is trying to achive, i had also requested tefflox to specify his requirements so that i could make the appropriate changes to the condition
i am trying to compress all files older than ten days old.. your script, as such:
gives these errors:
also, you could try the find command with mtime option and exec to compress the file. right now i dont have access to the unix box, anyways, the command should look something like
find . -mtime 10 -exec tar -cvf destinationfilename source filename
now i'm learning that my $file variable is wrong, should be something like
for $9 in `ls...." where $9 is the actual file name
it's giving me errors trying to mv the permission lists & stuff
but it means i am making progress, w/ your generous help
how do I make "file" change to the name of the field $9 in the ls -lF, which is the name of the file?
???
Why would you use the 'ls' command to determine whether or not to compress a file? I think that it would be a lot easier and a better design to use 'find' instead.
If I create a file older than 10 days ago... .
$ touch -t 200609160000.00 hello
$ ll hello
-rw-rw-r-- 1 kshuser kshuser 0 Sep 16 00:00 hello
$ find . -mtime +10 -exec ls -ld {} \;
-rw-rw-r-- 1 kshuser kshuser 211 Mar 7 2006 ./x.c
-rw-rw-r-- 1 kshuser kshuser 0 Sep 16 00:00 ./hello
-rw-rw-r-- 1 kshuser kshuser 1693 Aug 24 12:56 ./client.c
Now if I change the timestamp on the same file to 9 days ago... .
$ touch -t 200609180000.00 hello
$ find . -mtime +10 -exec ls -ld {} \;
-rw-rw-r-- 1 kshuser kshuser 211 Mar 7 2006 ./x.c
-rw-rw-r-- 1 kshuser kshuser 1693 Aug 24 12:56 ./client.c
So you could just use the 'find' command above, and replace the "ls -ld" with your compress command. The { } characters represent the filename.
i'm sorry to say that it's too advanced for me to follow. i think it's too much to ask at this point for me to learn a bunch of new stuff and start over. just let me get it my way this time,and then i will start to learn more...
can you help so the file identifier is employed correctly later on in the script, so it doesn't try to "mv -rwx..." ? thanks
edit: okay, since all else is failing, i will try to climb the learning curve another inch or two.
no, i am unable to figure your suggestion. my script is almost working, be it ugly, but it has put some files into thte compressed.tar folder, which means i am almost home. i still need help compressing the directory "compressed.tar"
thanks, to all who helped. i feel that i've gotten over a little hump, dug myself in to get over a couple more. thanks again. comp sci forums are great!
Alternatively try this command and it is working perfectly fine.
find . -mtime +10 -exec tar -cvf test.tar {} \;