Archiving files using a time stamp.
Hey everyone. I have a quick question, in a class I am currently taking right now, one of our projects for the end of it is to write a script that is able to archive all of our files in the home directory based upon their time stamp for the month and year they were created/last modifided. Now, my teacher has suggested an array to do this but the thing is, I have no idea how to even begin writing this script. So I was wondering if you guys could give me some help and pointers in the right direction, because as of right now, I am completely lost on this one and this is the only script I have left to write for it. I know I need to start off the script by searching for all the files in my current directory by giving the ls command, but after that, I am not sure how to tell the script if it sees a file with a certain time script to place it into a certain folder. If you could help me answer this it would be great, thanks again. Oh, almost forgot, the language we are using to write these in is bash.
|
An array in bash script is declared like thie
Code:
A[0]="123" Code:
I=${A[0]} Or you can take a look here, this can be a bit complex, but it uses arrays, loops, etc. If you'll skip everything related to iptables in that post, You can find definition and use of arrays. But I recommend you to use "info bash" first... |
Thanks, I have and got a little farther, and once again stuck. This time though, it is more on the wording and logic of using an if statment to add an element into my array. Here is what I have so far for my script.
#!/bin/bash #Colt Whitaker #May 29, 2007 #This shell script is supposed to be able to archive/ back up all my files on my home directory #Into new and different directories dependant upon there date stamp. #I am trying to see if an array is my best option for filename in $(ls) do ls --full-time $filename done ls --full-time $filename | sed's/.*\([0-9]\{4\} - [0-9]\{2\}\).*/\1/' stamp = ls --full-time $filename | sed's/.*\([0-9]\{4\} - [0-9]\{2\}\).*/\1/' delcare -a dates declare -i i for(( i=0; i <${dates[@]} ; i++ )) do if [[ $stamp == ${dates[i]} ]] then #Dont do anything else #Add the element into the arry This is where I am stuck since I am unsure of how the else statment should look since I am not sure if I should say; "else ++1" Or something along those lines. Help would be appriciated again. thanks in advance. |
Quote:
2) "i++" in bash looks like Code:
i=$(($i+1)) There were loops in the script i've provided link to. Example: Code:
while [ "${PAID[$i]}" != "" ] Did that answer you question? |
All times are GMT -5. The time now is 11:18 AM. |