LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 10-02-2006, 12:58 PM   #1
xtremeclones
Member
 
Registered: Jan 2006
Posts: 70

Rep: Reputation: 15
shell backup script


Hey guys,

i need to make a shell script that automatically saves a copy of a .ini file to a specified directory and saves it with the date.

for example at 7pm everynight it saved me.ini to /home/me as me.ini.20061002

i also need help knowing how to put it in the cron conifgutation.

can anyone please give me a hand with this.

thank in advanced.
 
Old 10-02-2006, 01:21 PM   #2
b0uncer
LQ Guru
 
Registered: Aug 2003
Distribution: CentOS, OS X
Posts: 5,131

Rep: Reputation: Disabled
I'm not a bash script master myself, but you could try the following (please test it first with some unimportant file): create a new text file in which you put the following:

Code:
#!/bin/sh
filedate=$(date +"%F_%H.%M")
cp /path/to/your/me.ini /home/me/me_"$filename".ini
Then save it as "me_copy.sh" (or whatever you like). Then make it executable:
Code:
chmod +x me_copy.sh
...and run
Code:
crontab -e
and add this line there:
Code:
0 19 * * * /path/to/me_copy.sh
And that should work, hopefully at least I didn't check that, so try it out yourself.

EDIT: read man date for more information about how to format the datestamp. And every time that is run, it overwrites (if that's default) the older file (unless it asks something, in which case that doesn't run -- check man cp). So you might want to add something to the script so that it copies the older file off first, and then the new one instead.

Last edited by b0uncer; 10-02-2006 at 01:24 PM.
 
Old 10-02-2006, 01:33 PM   #3
MOS JEFF-INITELY
Member
 
Registered: Sep 2006
Distribution: Windows .. MUAHAHAHA
Posts: 66

Rep: Reputation: 15
check this link for cron: http://www.unixgeeks.org/security/ne...ix/cron-1.html

I think this is the line you want for a copy:
cp me.ini /home/me/me.`date +%m.%d.%y`

you can change the format of the date output there are many ways just man date.

peace.
 
Old 10-03-2006, 02:13 PM   #4
xtremeclones
Member
 
Registered: Jan 2006
Posts: 70

Original Poster
Rep: Reputation: 15
Thanks, ill give it a shot today.

again thanks for the help!!
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Shell script to remove backup ~ files hallamigo Linux - General 3 09-13-2010 03:47 PM
Shell Script for backup BBQ_Matt Linux - Software 7 06-30-2005 05:19 PM
Incremental Backup shell script. datadriven Linux - General 3 06-02-2004 09:19 AM
writting a backup shell script yenonn Slackware 2 03-18-2004 07:49 PM
bash shell backup script turnip Programming 0 04-03-2003 06:00 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 07:45 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration