ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Distribution: Ubuntu 12.04, Mint 13, RHES 5.5, RHES 6
Posts: 146
Rep:
simple bash script question
here is my code I'm backing up a directory with
I call the script like this.
[bash#]./scriptname directory
<start code>
#!/bin/sh
echo "backing up $1 directory to remote storage"
echo "compressing $1 to $1.$(date +%Y%m%d-%H%M).tgz" <- I want this filename saved in a variable so that it can be called later as $filename
tar czf $1.$(date +%Y%m%d-%H%M).tgz $1
echo "done."
echo "moving $filename to /var/ftp/backup/web"
./mv
echo "done."
exit $?
<end code>
I would just use the $1.$(date +%Y%m%d-%H%M).tgz piece agian to display the filename, but it takes longer than a minute to compress the directory. So after it compress's the directory the filename displayed would be different than the real filename.
I doubt it is a very hard thing to do I'm just not that experienced with scripting yet, any help would be apreciated.
Distribution: Ubuntu 12.04, Mint 13, RHES 5.5, RHES 6
Posts: 146
Original Poster
Rep:
Man you guys are fast. I don't know why I didn't think of the first posts answer! declaring the current time as a variable from the get go was a perfect solution.
Thanks to all.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.