Sponsored Content
Top Forums Shell Programming and Scripting Can anybody write this bash script ? Post 302277426 by Rhije on Friday 16th of January 2009 09:18:36 AM
Old 01-16-2009
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.

Code:
#!/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? Smilie

Last edited by Rhije; 01-16-2009 at 10:19 AM.. Reason: uh the # at the beginning of my shebang was gone.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash Script to Read & Write on different directories

Hi, root@server] df -h 121G 14G 101G 12% /home 147G 126G 14G 91% /backup We having our site files and images are storing in /backup/home/user/files/ through symbolic link created in /home directory pointing in /backup directory as following. root@server] cd /home... (1 Reply)
Discussion started by: mirfan
1 Replies

2. Homework & Coursework Questions

How to write script in bash.

I am very new to Linux/Unix. Kindly assist the following: I wish to write a bash shell script called how_many_to_go that calculates and prints the number of days, hours, minutes and/or seconds until the end of the current month (based on the output of the date command). Do ... (2 Replies)
Discussion started by: alobi
2 Replies

3. Shell Programming and Scripting

Help to write bash script code

I am newbie to UNIX. I came across this exercise in one the books.Can anyone help me with this question?????? Write a short Bash script that, given the name of a file as an argument, reads the file name and creates a new file containing only lines which consist of one word. Here is an example... (4 Replies)
Discussion started by: krthknaidu
4 Replies

4. Shell Programming and Scripting

Bash script reg-exp , replace , open and write

Hi All I am a new in scripting language and I would like help for you guys I would like to create a file named constant.h and search into all files *.m in specific directory for a reg-exp @"LBL_]+" exp: @"LBL_75847" , and write those matchs to constant.h if there are not written (no... (15 Replies)
Discussion started by: molwiko
15 Replies

5. Shell Programming and Scripting

how to write bash script that will automatically extract zip file

i'm trying to write a bash script that that will automatically extract zip files after the download. i writed this script #!/bin/bash wget -c https://github.com/RonGokhle/kernel-downloader/zipball/master CURRENDIR=/home/kernel-downloader cd $CURRENDIR rm $CURRENDIR/zipfiles 2>/dev/null ... (2 Replies)
Discussion started by: ron gokhle
2 Replies

6. Shell Programming and Scripting

How to write bash shell script for mentioned requirement?

Hi All, I am unable to write the script for the below requirement. Requirement: Main table dir_ancillary table contain three column "dir_ancillary.table_name"," dir_ancillary.text_file_name ", "dir_ancillary.Include" . This dir_ancillary contain undefined tables in the column... (2 Replies)
Discussion started by: Vineeta Nigam
2 Replies

7. Shell Programming and Scripting

How to write bash script for lvm snapshot?

Hi Team I am trying to put together a nice small script to mount my lvm snapshot Here are my objectives 1 Check whether snapshot is currently mounted. If so echo umount snapshot and exit from the script. 2 If it's not mounting, check whether the mount point exist, If so, create lvm... (0 Replies)
Discussion started by: fugeulu
0 Replies

8. UNIX for Dummies Questions & Answers

Script to break up file (write new files) in bash

Hello experts, I need help writing individual files from a data matrix, with each new file being written every time there is a blank line: From this cat file.txt col1 col2 col3 6661 7771 8881 6661 7771 8881 6661 7771 8881 col1 col2 col3 3451 2221 1221... (6 Replies)
Discussion started by: torchij
6 Replies

9. UNIX for Beginners Questions & Answers

How To Write my Bash Script To Automate it?

Hello guys, I need some help. I am new in bash and I don't know how to automate the following script. head -2 out1 > 1.fasta sed ‘1,2 d' out1 > out2 rm out1 head -2 out2 > 2.fasta sed ‘1,2 d' out2 > out1 rm out2 head -2 out2 > 3.fasta sed '1,2 d' out2 > out1 rm out2 .......... (3 Replies)
Discussion started by: dellia222
3 Replies

10. UNIX for Beginners Questions & Answers

How to write a value to a physical memory address in bash script?

How would I write a value to a physical memory address? I was able to read a physical memory address (for example, 0x400) using this line: dd if=/dev/mem count=4 bs=1 skip=$(( 0x400 )) But I get an error: dd: 'standard input': cannot skip to specified offset when I try to write using... (1 Reply)
Discussion started by: rabrandt
1 Replies
STOREBACKUPSEARCH(1)					User Contributed Perl Documentation				      STOREBACKUPSEARCH(1)

NAME
storeBackupSearch.pl - locates different versions of a file saved with storeBackup.pl. SYNOPSIS
storeBackupSearch.pl -g configFile storeBackupSearch.pl -b backupDirDir [-f configFile] [-s rule] [--absPath] [-w file] [--parJobs number] [-d level] [--once] [--print] [backupRoot . . .] DESCRIPTION
You need some basic understanding of linux and perl to use it. OPTIONS
--generate, -g generate a config file --print print configuration read from configuration file and stop --configFile, -f configuration file (instead of or additionally to parameters) --backupDir backupDirDir, -b backupDirDir top level directory of all backups --searchRule, -s rule for searching see README: 'including / excluding files and directories' --absPath, -a write result with absolute path names --writeToFile, -w write search result also to file --parJobs, -p number of parallel jobs, default = chosen automatically --debug, -d debug level, possible values are 0, 1, 2, default = 0 --once, -o show every file found only once (depending on md5 sum) backupRoot Root directories of backups where to search relative to backupDir. If no directories are specified, all backups below backupDir are chosen. COPYRIGHT
Copyright (c) 2008-2009 by Heinz-Josef Claes (see README). Published under the GNU General Public License v3 or any later version perl v5.14.2 2012-06-16 STOREBACKUPSEARCH(1)
All times are GMT -4. The time now is 11:13 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy