简体   繁体   English

如何在Linux上的新贵脚本中复制文件?

[英]How to copy a file in a upstart script on Linux?

I have a simple upstart job. 我的工作很简单。 I want to copy a file there when it is restarted. 我想在重新启动文件时将文件复制到那里。 I can not get it to work. 我无法正常工作。 I have read how to execute bash scripts etc from upstart but I dont get it to work. 我已经阅读了如何从新贵那里执行bash脚本等,但是我没有使其工作。 This is what I have tried: 这是我尝试过的:

script
    exec bash -c 'cp /opt/test/test.log /opt/test/test.log.old'
end script

When I stop and start the service the file is not copied. 当我停止并启动服务时,不会复制文件。 Any ideas what I am doing wrong? 有什么想法我做错了吗?

This should be run within the pre-start script tag: 这应该在pre-start script标记中运行:

pre-start script
    exec bash -c 'cp /opt/test/test.log /opt/test/test.log.old'
end script

Add an Upstart job: 添加新贵工作:

Create /etc/init/myjob.conf 创建/etc/init/myjob.conf

vi /etc/init/myjob.conf vi /etc/init/myjob.conf

with content like the following: 内容如下:

description "my job" 描述“我的工作”

start on startup 开始启动

task 任务

exec /path/to/my/script.sh exec /path/to/my/script.sh

Your script.sh file contains: 您的script.sh文件包含:

cp /opt/test/test.log /opt/test/test.log.old cp /opt/test/test.log /opt/test/test.log.old

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM