Reputation: 666
I have a cron job that calls a shell script. The script sends POST requests to localhost using CURL.
Cron script:
PATH=/bin:/sbin:/usr/bin:/usr/sbin
0 0 * * * reboot now
2 11 * * 0 /bin/sh /usr/share/power/turn_off_outlets.sh
turn_off_outlets.sh:
#!/bin/sh
#arg 1 is outlet and arg two is the relay state(true for on, false for off)
power_ctrl_outlet() {
echo "Turning outlet $1 to $2"
curl -X PUT http://localhost/restapi/relay/outlets/$1/state/ -H 'Acc: application/json' -H 'Authorization: Basic YWRtaW46JGNpZW5jZQ==' -H 'Cache-Control: no-cache' -H 'Content-Type: application/x-www-form-urlencoded' -H 'cache-control: no-cache' -d "value=$2"
}
turn_off_all_outlets() {
power_ctrl_outlet 0 false
power_ctrl_outlet 1 false
power_ctrl_outlet 2 false
power_ctrl_outlet 3 false
power_ctrl_outlet 4 false
power_ctrl_outlet 5 false
power_ctrl_outlet 6 false
power_ctrl_outlet 7 false
}
turn_off_all_outlets
Running the script from the command line works fine but when cron executes the script it takes a very very long time. I have tried using nice
to set the priority level but that slows the entire system.
The system is BusyBox v1.22.1 () built-in shell (ash)
Any input is appreciated.
Upvotes: 1
Views: 475