Can anybody write this bash script ?

hi, first congratulations on the nice forum!

Can anybody write script, which can make copy of some or all files of the current directory in new directory (called "backups", which must be made in the current directory, if it's not already exist). And bring out a massage (report) with the count of the successfull copied files.

Thank you in advance!

regards

Give it a try yourself first and then best ask when you encounter problems.

I have no idea of Unix and Linux. But i need this script.... I just thinked that may be you can help me... Anyway..... I understand you :o

Yeah, it doesn't take much to learn this kind of stuff (at least for what you want to do).. but I did make a very basic script to do it.

#!/bin/bash

tempfile="temp`date +%Y-%m-%d`.log"
if [ ! -d "./backups" ] ; then
        mkdir backups
fi
for file in `find . -type f -maxdepth 1`; do
        cp --reply=no -v $file ./backups/ >> $tempfile
done

filecount=$(cat $tempfile | wc -l);
rm -f $tempfile

echo "Backup Complete.";
echo "Successfully copied $filecount files to ./backups";

It checks to see if ./backups is a directory and if not, then creates a directory named backups/ . Then it goes through a loop for all files in the current directory and puts them in backups/ , but will automatically say "no" to overwriting files that already exist in that directory with the same name.

It will report how many files were successfully copied.

I do agree with zaxxon however, and you should learn it. But I am bored, and stuff.. Anything else? :slight_smile:

Thank you vary much!!! I'm so gratefull for your help.

Yes this is intersting and i will start learning it very soon !

best regards

Hey Cecko,

You got me interested in the script now, anything else you need? Send me a message if you want!

Please follow our rules.

(10) Don't post your email address and ask for an email reply. Don't send a private message with a technical question. The forums are for the benefit of all, so all Q&A should take place in the forums.

Thanks

I apologize. I wasn't saying to message me so I could answer any technical questions. I was merely saying that I could keep modifying the script. I will keep it in the forums though.