Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I have a shell script that executes a backup program and saves the output in a folder. I would like to update the name of the output folder every time the shell script run. In the end I want to have many files with different names like this:

innobackupex --user=root --password=@g@1n --database="open_cart" /var/backup/backup_1 --no-timestamp

And after running the shell script again:

innobackupex --user=root --password=@g@1n --database="open_cart" /var/backup/backup_2 --no-timestamp
share|improve this question
    
use backup_ instead and check for existence of files starting at 1. when you get to one that doesn't exist, use that... –  hbdgaf Aug 28 '12 at 14:12
2  
Cool but why so difficult? Why not use a standard time stamp? Use $(date +"%m-%d-%Y") and you do not need to worry about iteration –  Rinzwind Aug 28 '12 at 14:13
    
@Rinzwind i think this will be much better as i will have different folders each time thanks alot –  Sitati Aug 28 '12 at 20:37
    
Sorry but a timestamp makes it a different folder and you get to see when it was made ;) @Sitati –  Rinzwind Aug 28 '12 at 21:34
add comment

1 Answer 1

up vote 1 down vote accepted

You need to store the incremental value somewhere, for example in a log file

#!/bin/bash
FILENAME="logfile.txt"
NUM=`cat $FILENAME`
(( NUM++ ))
echo "INCREMENTAL NUM  : $NUM"
echo $NUM>$FILENAME
share|improve this answer
    
I have also tried this and it works fine –  Sitati Aug 28 '12 at 20:38
1  
if it suites your needs please upvote the answer (and accept it if is also acceptable ;) ) @Sitati thanks in advance –  Rinzwind Aug 28 '12 at 21:34
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.