script compare files and backup


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting script compare files and backup
# 1  
Old 07-10-2009
script compare files and backup

Im working on a shell script that uses three parameters, a string to replace, the string replacing, and a file name.

In this script it makes a back up file before the replacement occurs. However I want to be able to either search the file to see if it has the string and if it doesnt dont create a backup. Or do the substition and compare the two files. I am lost, I assume it would be easier to search the file for the string then go from there, but this is what I have.

#!/bin/csh

set old_pattern="$1"
set new_pattern="$2"
set file_name="$3"

mv $file_name $file_name.bak
sed -e "s/$old_pattern/$new_pattern/g" $file_name.bak > $file_name
# 2  
Old 07-10-2009
Code:
old=$1
new=$2
file=$3
grep $1 $3 > /dev/null
if [ $? -eq 0 ];then
	cp $3 ${3}.bak
	sed "s/$1/$2/g" $3 > ${3}~
	mv ${3}~ ${3}
fi

# 3  
Old 07-10-2009
thank you,is this using sh shell?

I cant get it to work, I assume I am using the wrong shell?

---------- Post updated at 01:53 AM ---------- Previous update was at 12:11 AM ----------

anyone have any ideas? still cant get it to workSmilie

---------- Post updated at 07:45 PM ---------- Previous update was at 01:53 AM ----------

bump, could anyone help?

Last edited by gordonheimer; 07-10-2009 at 01:26 AM..
# 4  
Old 07-10-2009
summer_cherry's syntax is Korn shell, if that helps?

It's more helpful when you say how it doesn't work.
# 5  
Old 07-10-2009
i get

grep:be: no such file or directory
# 6  
Old 07-11-2009
How many "words" are you passing to the script?

Try quoting the arguments as you pass them in.

i.e.
Code:
myScript this will be five arguments
...
$1=this
$2=will
$3=be
($4 and $5 are never used
 
 
Instead:
myScript "this will" "be three" arguments
...
$1="this will"
$2="be three"
$3=arguments

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. AIX

Script to remove backup files

HI, I want to remove my backup files keeping last 30 days. Now i am doing it manually. Does anyone have a script to automate this process? Thanks in advance (5 Replies)
Discussion started by: ElizabethPJ
5 Replies

2. Shell Programming and Scripting

Script or alias to backup all files opened by vi

we want to backup all opened files by vi before editing also with version information. i wrote below alias to backup crontab file content with version info. What i want know is to make this opened files by vi. We want to prevent user mistakes by adding this alias. alias crontab='DATE=$(date... (4 Replies)
Discussion started by: sebu
4 Replies

3. Shell Programming and Scripting

Backup script to split and tar files

Hi Guys, I'm very new to bash scripting. Please help me on this. I'm in need of a backup script which does the ff. 1. If a file is larger than 5GB. split it and tar the file. 2. Weekly backup file to amazon s3 using s3rsync 3. If a file is unchanged it doesn't need to copy to amazon s3 ... (4 Replies)
Discussion started by: ganitolngyundre
4 Replies

4. Shell Programming and Scripting

Script for taking backup of desktop files.

Hi Friends, I need help. I have around 100 users. I want to take date wise backup of files which are on desktop for every user. My user directory path is -: /home/dr/<user_name>/Desktop 1) Script has to run on a perticular time everyday 2) Script has to take backup of all files present... (2 Replies)
Discussion started by: paragnehete
2 Replies

5. Shell Programming and Scripting

error in sh script while copy files to a backup directory

I am trying to copy files from one directory to another using shell script. Can anyone please troubleshoot the code. thanks in advance... #!C:\Shell\sh.exe files_dir="C:\Documents and Settings\scripts\files" backup_dir="C:\Documents and Settings\scripts\ztest" echo cding to... (2 Replies)
Discussion started by: sureshcisco
2 Replies

6. Shell Programming and Scripting

Script to Backup files

Hi, I wrote a simple script to backup of index.php and index.html in my box. So, I wrote a script which take a copy of the index page as 1Mar09: but it does not comes up.. #! /bin/bash find . -name index.* > domains.txt for i in `cat domains.txt` ; do cp index* index*.1Mar09 $i; done But... (6 Replies)
Discussion started by: gsiva
6 Replies

7. Shell Programming and Scripting

script to compare files

HI i wil get input from sql query and that too i can get a list o f files or just one. i have to pick up a file from another directory which hads prefix to this prefix.x.x.x.x.x. And we have to discard prefix and use that file name. we have to compare this file name(no need... (0 Replies)
Discussion started by: pulse2india
0 Replies

8. Shell Programming and Scripting

request born script for creting backup files

script should make a backup sub-directory to make a backup copy of all the files that were created on a date . The name of the subdirectory should reflect the current month and day eg BackupsAug16. The backup files need to have extension .bak for each file script needs to check if there... (6 Replies)
Discussion started by: vinaysamineni
6 Replies

9. Solaris

creating log files for a backup script on solaris

I have a simple backup script that I am running to back up drives across the network. However I need to have detailed log files for this script such as time backup started, what was backed up, if there were any errors and the time that the backup was complete. I would also like the script to... (3 Replies)
Discussion started by: valicon
3 Replies
Login or Register to Ask a Question