简体   繁体   English

如何拥有一个cron脚本,该脚本每次运行时都应调用Chef-databag来获取用户名和密码?

[英]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.

相关问题 我应该如何使用 python 脚本将用户名和密码传递给 Cassandra - How should i pass username and password to Cassandra using python script 运行GET请求循环的Python脚本抛出“ KeyError”,但并非每次都抛出 - Python script that runs GET request loop throws “KeyError”, but not every time 每次脚本运行时更改函数名称 - Changing function name every time script runs 脚本在终端上运行,但不是 cron - Script runs on terminal, but not as cron 如何让python每隔x小时执行一次脚本而不使用cron? - How to have python execute a script every x hours without using cron? 每次运行 python 脚本时,如何使用新结果更新 google 表? - How to update google sheet with new outcome every time python script runs? 如何避免每次脚本运行时重新导入模块和重新定义大对象 - How to avoid re-importing modules and re-defining large object every time a script runs Python脚本在bash中运行,但不在cron中运行? - Python script runs in bash, but not in cron? 为什么我的Python脚本每次运行都会给我一个错误? - Why is my Python script giving me an error every time it runs? Python脚本,每次运行时都会在序列中输入下一个数字。 - Python script to input the next number in a sequence every time it runs.
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM