LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-01-2004, 02:28 PM   #1
bullium
Member
 
Registered: Aug 2003
Location: Ohio
Distribution: Ubuntu 12.04, Mint 13, RHES 5.5, RHES 6
Posts: 146

Rep: Reputation: 17
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.

Thnx
Will
 
Old 11-01-2004, 02:34 PM   #2
secesh
Senior Member
 
Registered: Sep 2004
Location: Savannah, GA
Distribution: Ubuntu, Gentoo, Mythbuntu, ClarkConnect
Posts: 1,154

Rep: Reputation: 47
your she-bang line -- why isn't is #!/bin/bash?
Code:
today=$(date +%Y%m%d-%H%M)
echo $today
 
Old 11-01-2004, 02:35 PM   #3
itsme86
Senior Member
 
Registered: Jan 2004
Location: Oregon, USA
Distribution: Slackware
Posts: 1,246

Rep: Reputation: 59
itsme@dreams:~/scripts$ cat time.sh
#!/bin/bash

filename=`date +%Y%m%d-%H%M`.tgz
echo $filename
sleep 60
echo $filename
itsme@dreams:~/scripts$ ./time.sh
20041101-1232.tgz
20041101-1232.tgz
 
Old 11-01-2004, 02:42 PM   #4
bullium
Member
 
Registered: Aug 2003
Location: Ohio
Distribution: Ubuntu 12.04, Mint 13, RHES 5.5, RHES 6
Posts: 146

Original Poster
Rep: Reputation: 17
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.
 
  


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
Simple bash script lp449 Linux - Networking 3 08-02-2005 04:25 PM
Simple bash script Soulful93 Programming 1 06-04-2005 07:26 PM
Simple Bash Script Help njdownes Programming 2 03-05-2005 07:35 AM
Help with simple bash script - please tw001_tw Linux - Software 5 12-19-2004 09:02 PM
Simple BASH script fio Linux - General 5 01-18-2003 03:26 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:08 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