[英]How to have a cron script that should call chef-databag to get username and password every time it runs?
I have a cronjob which executes a python script. 我有一个执行python脚本的cronjob。 python script takes two parameter username and pass.
python脚本需要两个参数username和pass。
for example : execute.py vijay hTbY87 例如:execute.py vijay hTbY87
Requirement is to take this username and pass from dataBag i have in chef. 要求是使用此用户名并从我在厨师中拥有的dataBag传递。 My instance where i need to run this cronjob is in AWS.
我需要运行此cronjob的实例在AWS中。
Is there a way to have such a cronjob ? 有没有办法进行这种cronjob?
So assuming you're using the built-in cron
resource (you might want to use the cron_d
resource instead, there are some subtle differences), it's all just writing the Ruby code you want: 因此,假设您正在使用内置的
cron
资源(您可能想使用cron_d
资源,则存在一些细微的差异),它们都只是编写您想要的Ruby代码:
params = data_bag_item('bagname', 'itemname')
cron 'myscript' do
command "python /path/to/execute.py #{params['user']} #{params['password']}"
# Other properties here to set the schedule.
# ...
end
Create a cronrun.sh file that contains the following: 创建一个cronrun.sh文件,其中包含以下内容:
#!/usr/bin/env bash
crontab <<EOF
*/30 * * * * /path/to/execute.py vijay hTbY87 > /path/to/logs/output.log 2>&1
EOF
This would execute every 30 minutes and will pipe the output (or Error message) to a logs directory. 这将每30分钟执行一次,并将输出(或错误消息)通过管道传输到日志目录。 To search for another time interval, Google
crontab.guru every ___ minutes
or hours or days or whatever you want. 要搜索另一个时间间隔,
crontab.guru every ___ minutes
或几小时或几天或任何您想要的时间,谷歌crontab.guru every ___ minutes
。
Make sure that you type chmod +x cronrush.sh
so that the file becomes executable. 确保键入
chmod +x cronrush.sh
以便该文件变为可执行文件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.