1

I have a cronjob which executes a python script. python script takes two parameter username and pass.

for example : execute.py vijay hTbY87

Requirement is to take this username and pass from dataBag i have in chef. My instance where i need to run this cronjob is in AWS.

Is there a way to have such a cronjob ?

Rahul Kumar
  • 13
  • 1
  • 4
  • The purpose of databag mainly is to store contents and later use in recipes/knife commands. I think for your purpose you can decode password inside your Python script instead of passing it plain text? – slashpai Mar 26 '18 at 16:27
  • Yes thought of the same but pychef is not currently installed on the instance. – Rahul Kumar Mar 27 '18 at 04:24

2 Answers2

2

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:

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
coderanger
  • 52,400
  • 4
  • 52
  • 75
0

Create a cronrun.sh file that contains the following:

#!/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. To search for another time interval, Google crontab.guru every ___ minutes or hours or days or whatever you want.

Make sure that you type chmod +x cronrush.sh so that the file becomes executable.

rodcoelho
  • 44
  • 4