Ask Your Question
0

How to create multiple directory after the directory name of current date-time?

asked 2016-02-11 21:26:02 -0500

yoga gravatar image

updated 2016-02-11 23:37:16 -0500

I want to create backup directory at the name of current date and time so i use below method in my init file.

 $time=generate('/bin/date', '+%d%b%y_%H-%M-%S'),

i can able to create the directory named ${time}.But i want to create multiple directory after the ${time} so that

         class currentgen::backup::backup_folder
         inherits currentgen{
         exec{"backup folder":
          path=>["/bin"],
          cwd=>"${prodequ_backup_path}",
          command=>"mkdir -p ${time}/servar/default/deploy",
          }
      }

After executing this i got error like

   Error: sh: line 1: /servar/default/deploy: No such file or directory
   Error: /Stage[main]/Currentgen::Backup::Backup_folder/Exec[backup folder]/returns: change from notrun to 0 failed: sh: line 1: /servar/default/deploy: No such file or directory

But this creates ${time} directory but sub directories of ${time} not created.

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
0

answered 2016-02-11 23:28:15 -0500

GregLarkin gravatar image

Do you mean that you have another resource that creates the top-level directory named for the value stored in the $time variable? If so, make sure that your exec resource includes a dependency on that other resource (likely a file resource) so it is applied first.

You have to make sure that all parent directories are in place before attempting to create subdirectories under them.

edit flag offensive delete link more

Comments

yeah i included that top level directory where i declare variable $time.

yoga gravatar imageyoga ( 2016-02-11 23:36:07 -0500 )edit
0

answered 2016-02-11 23:45:09 -0500

yoga gravatar image

updated 2016-02-11 23:46:11 -0500

I changed my code like below it creates subdirectories under ${time} , but the result of this execution i got filenamewith"?". i want only the file name with out "?".

                class currentgen::backup::backup_folder
                inherits currentgen{
                exec{"backup folder":
                path=>["/bin"],
                cwd=>"${prodequ_backup_path}",
                command=>"mkdir -p '${time}/server/default/deploy'",
                }
                }

result:

          12Feb16_11-02-35?/server/default/deploy
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2016-02-11 21:26:02 -0500

Seen: 157 times

Last updated: Feb 11 '16