首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用rex创建目录

如何使用rex创建目录
EN

Server Fault用户
提问于 2018-01-29 12:22:30
回答 1查看 113关注 0票数 1

如果rex不存在,我想用它创建一个目录。我读过,但我找不到该怎么做。

如果在没有目录的情况下发送文件,则会得到以下错误:

代码语言:javascript
复制
ERROR - upload: /usr/local/path/file.ext is not writable

有什么暗示吗?

EN

回答 1

Server Fault用户

回答已采纳

发布于 2018-02-12 12:56:56

我认为rex书中的文档有点老了。

请看这里的https://www.rexify.org/docs/api/或(截至今天)这里的最新文档:https://www.rexify.org/docs/api/1.4/rex/commands/file.pm.html#file-file_名字-选项- (它说的是1.4版,而当前的cpan版本是1.6,但没关系)

所以,用一个例子来回答你的问题:

代码语言:javascript
复制
task "backuptask", group => "mygroup", sub { 
    #
    # 1.) define the Backup Dir (you could do it without this step)                                                                                                                        
    my $backupdir = "/tmp/backup";  
    #                                                                                                      
    # 2.) "ensure" that the file is a (existing) "directory"        
    file $backupdir, 
            ensure=> "directory", 
            owner => "myowner", 
            group => "mygroup", 
            mode => 700, 
            on_change => sub { say "File was changed";};

    #                                                                                                                                    
    # 3.) define Backup File                                                                                                                         
    my $currTimestamp = strftime('%y%m%d',localtime);                                                                                     
    my $backupfile = "$backupdir/somebackup$currTimestamp";
    #                                                                            
    # 4.) "ensure" the the file is "present" at the defined path
    file $backupfile, ensure=> "present";

    ...execute something here...

}  ;                                                                                               
票数 1
EN
页面原文内容由Server Fault提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://serverfault.com/questions/894597

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档