Discussion Locked

Need a quick Script

0 helpful
2 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

I am not familiar with Unix Shell scripting so I was hoping someone could help me create a simple script.

I need to tar the entire contents of directory /usr/local/backup into a file.
I would like the file to be named
date_backup.tar (ie 06jun2000_backup.tar)
Then take that filename and compress it to a .Z file then move that filename onto another filesystem /disk1_backup

That's it! Also, if you could recommend a good, easy to understand Unix Shell Scripting Book.

For you guru's, I'm sure this isn't tough, so it's a quick way to get 250 points

Thanks
Paul

2 replies

by hugevlad

Hello Paul,
Voila your script:
===== cut ======
#!/bin/sh
fname=/tmp/`date +%d%b%Y`_backup.tar
tar -cvf $fname /usr/local/backup
gzip $fname
cp $fname.gz /disk1_backup
rm $fname.gz
===== cut ======

Notes.
1. Make sure, that there is enough free space on file system with /tmp directory.
2. I use in my script gzip (GNU zip) program, which add ".gz" extention to the original name and remove original file. If you use other compress utilities, make appropriate changes.

About Unix Shell Scripting Book. I have read one little book (in Russian) and look throu douzen scripts, written by other people. This is a good way to learn shell scripting. Also, try search some books at O'Relly.

With best regards,
Vlad.

This discussion is closed to new replies.