How to create a variable from a command that increments the folder name?
Hello
I am using this code and is working as expected.... Code:
# Increment $N as long as a directory with that name exists Quote:
Code:
backup bla bla bla --target-dir /backup/to/dir How should i know the created folder every time the script runs if it is inc1 or inc4 and create a variable from this command when it runs? Code:
mkdir -p "/backup/$DOMAIN/$DATE/database/inc$N" |
Save the directory name as a variable then make it.
Code:
mydir="/backup/$DOMAIN/$DATE/database/inc$N" Code:
mydir="/backup/$DOMAIN/$DATE/database/inc$N" Code:
a=cats |
I almost understand what you are trying to say, I think.
you have a script that creates dirs and adds 1 for each new sud-dir it created. when you then backup you want to know where to start or left off so you can pick up from there? You're going to need to look first to see where you're at then set it from where you left off at. Using your $N value. you should already know your values within your variables. Code:
/backup/$DOMAIN/$DATE/database/inc$N" that $DATE might mess you up, if it is using current date. /backup/$DOMAIN/*/database/inc$N" Code:
find /backup/$DOMAIN/*/database/inc* -type d >> ckfile -- just straight forward create incremented dir, check them, get number I left off at. Code:
#!/usr/bin/env bash |
Ok i got it working !!!!
Thanks all of you ! |
Code:
#!/bin/bash on filesystem you have /path/to/some/directory1 /path/to/some/dir1 ./script.sh /path/to/some/dir will make /path/to/some/dir3 safer Code:
#!/bin/bash /path/to/some/directory1 /path/to/some/dir1 /path/to/some/dir3 will just remake /path/to/some/dir3 because 2 + 1 = 3 PS Code:
lastline=$(echo -e $lastline | egrep -o [0-9]+ ) |
fixed typo ( dir should be Dir )
also wanted to point out that the script would break if passed a dir ending / e.g. ./script.sh /path/to/dir/ a fix would be Code:
Dir="${1%/}" https://www.tldp.org/LDP/abs/html/pa...stitution.html |
All times are GMT -5. The time now is 09:13 PM. |