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.
Related
I am trying to add a late_command to my preseed.cfg file but I get following error.
command:
d-i preseed/late_command string \
no_proxy=0,1,2,3,4,5,6,7,8,9 preseed_fetch /scripts/preseed_late_commands.sh /tmp/preseed_late_commands.sh ; \
/target/usr/bin/dos2unix /tmp/preseed_late_commands.sh || true; \
log-output -t preseed_late_commands.sh sh /tmp/preseed_late_commands.sh
The error that I get:
Execution of preseeded command "d-i preseed/late_command string \
no_proxy=0,1,2,3,4,5,6,7,8,9 preseed_fetch /scripts/preseed_late_commands.sh /tmp/preseed_late_commands.sh ; \
/target/usr/bin/dos2unix /tmp/preseed_late_commands.sh || true; \
log-output -t preseed_late_commands.sh sh /tmp/preseed_late_commands.sh" failed with exit code 2.
Infos:
os: Debian 11 (Bullseye)
preseed.cfg directory: http/d-i/bullseye/preseed.cfg
preseed_late_commands.sh directory: http/d-i/bullseye/scripts/preseed_late_commands.sh
Error image:
Error image
What should I do to get this command to run?
How and where can I see a live log (console output) or find a log file?
I am trying to find the error in the curl command that I have created:
curl http://127.0.0.1:7777 -X POST -H 'Content-Type: application/json-rpc' -H "X_CSRF_TOKEN: SuperSecret" -d '{"jsonrpc": "2.0","method":"override_tlm","params": "[PI THERMAL_TLM SOLAR_PANEL1_TEMP = 9.3]", "id": 0}' {"jsonrpc":"2.0","id": 0,"result":null}
the error is:
curl: (3) [globbing] unmatched close brace/bracket in column 14
any suggestions? Also please feel free to point out any other errors you see. thank you.
Your JSON is malformed. I think this is what you meant:
[{"jsonrpc":"2.0","method":"override_tlm","params":"[PI THERMAL_TLM SOLAR_PANEL1_TEMP = 9.3]"},{"id":"0","jsonrpc":"2.0","result":null}]
I have a bash script which executes a multi-line command multiple times and I am changing the some values on each iteration. Here is my code below:
for (( peer=1; peer<=$nodesNum;peer++ ))
do
echo "Starting peer $peer"
nodeos -p eosio -d /eosio_data/node$peer --config-dir /eosio_data/node$peer --http-server-address=127.0.0.1:$http \
--p2p-listen-endpoint=127.0.0.1:$p2p --access-control-allow-origin=* \
-p "user$peer" --http-validate-host=false --signature-provider=EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV=KEY:5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3 \
--max-transaction-time=1000 --genesis-json /eosio_data/genesis.json --wasm-runtime=wabt --max-clients=2000 -e \
--plugin eosio::chain_plugin --plugin eosio::producer_plugin --plugin eosio::producer_api_plugin \
--plugin eosio::chain_api_plugin \
--p2p-peer-address localhost:8888 \
&>eosio_data/logs/nodeos_stderr$p2p.log & \
sleep 1
http=$((http+1))
p2p=$((p2p+1))
done
I need to add a --p2p-peer-address localhost:$((9010 + $peer)) command multiple times for each peer as part of the multi-line command. I new to bash scripting and I couldn't find a similar example.
It's not entirely clear what you need, but I think it's something like the following. An array of --p2p-peer-address options is created, then incorporated
into the larger set of common options. Each call to nodeos then has some peer-specific options in addition to the common options.
# for example
HTTP_BASE=8080
P2P_BASE=12345
# Set of --p2p-peer-address options for shared by all calls.
for ((peer=1; peer <= $nodesNum; peer++)); do
peer_args+=(
--p2p-peer-address
localhost:$((9010+$peer))
)
done
# These are the same for all calls
fixed_args=(
-p eosio
"--access-control-allow-origin=*"
--http-validate-host=false
--signature-provider=EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV=KEY:5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3
--max-transaction-time=1000
--genesis-json /eosio_data/genesis.json
--wasm-runtime=wabt
--max-clients=2000
-e
--plugin eosio::chain_plugin
--plugin eosio::producer_plugin
--plugin eosio::producer_api_plugin
--plugin eosio::chain_api_plugin
--p2p-peer-address localhost:8888
"${peer_args[#]}"
)
for ((peer=1; peer<=$nodesNum; peer++)); do
# Call-specific arguments, followed by common arguments.
# $peer is either incorporated into each argument value
nodeos -d /eosio_data/node$peer \
--config-dir /eosio_data/node$peer \
--http-server-address=127.0.0.1:$((HTTP_BASE + $peer)) \
--p2p-listen-endpoint=127.0.0.1:$((P2P_BASE + $peer)) \
-p "user$peer" \
"${fixed_args[#]}" \
&> eosio_data/logs/nodeos_stderr$((P2P_BASE + $peer)).log &
sleep 1
done
To avoid having each instance of nodeos try to connect to itself, build peer_args anew on each iteration of the loop. Remove "${peer_args[#]}" from the definition of fixed_args, then adjust the main loop like so:
for ((peer=1; peer <= $nodesNum; peer++)); do
peer_args=()
for ((neighbor=1; neighbor <= $nodesNum; neighbor++)); do
(( neighbor == peer )) && continue
peer_args+=( --p2p-peer-address localhost:$((9010+peer)) )
done
nodeos -d /eosio_data/node$peer \
--config-dir /eosio_data/node$peer \
--http-server-address=127.0.0.1:$((HTTP_BASE + $peer)) \
--p2p-listen-endpoint=127.0.0.1:$((P2P_BASE + $peer)) \
-p "user$peer" \
"${fixed_args[#]}" \
"${peer_args[#]}" \
&> eosio_data/logs/nodeos_stderr$((P2P_BASE + $peer)).log &
sleep 1
done
I think you were very close. The expression you authored --p2p-peer-address localhost:$((9010 + $peer)) can be inserted into your nodeos call as follows:
for (( peer=1; peer<=$nodesNum;peer++ ))
do
echo "Starting peer $peer"
nodeos -p eosio -d /eosio_data/node$peer \
--config-dir /eosio_data/node$peer \
--http-server-address=127.0.0.1:$http \
--p2p-listen-endpoint=127.0.0.1:$p2p \
--access-control-allow-origin=* \
-p "user$peer" \
--http-validate-host=false \
--signature-provider=EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV=KEY:5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3 \
--max-transaction-time=1000 --genesis-json /eosio_data/genesis.json --wasm-runtime=wabt --max-clients=2000 -e \
--plugin eosio::chain_plugin --plugin eosio::producer_plugin --plugin eosio::producer_api_plugin \
--plugin eosio::chain_api_plugin \
--p2p-peer-address localhost:$((9010 + $peer)) &>eosio_data/logs/nodeos_stderr$p2p.log &
sleep 1
http=$((http+1))
p2p=$((p2p+1))
done
On the command line, I'm able to get this rolling with no problem:
java weka.Run weka.classifiers.timeseries.WekaForecaster -W
"weka.classifiers.functions.MultilayerPerceptron -L 0.01 -M 0.2 -N 500 -V 0 -S 0 -E 20 -H 20 " -t "C:\MyFile.arff" -F DirectionNumeric -L 1 -M 3 -prime 3 -horizon 6 -holdout 100 -G TradeDay -dayofweek -weekend -future
But once I try to put the skip list, I start to get errors saying that it's missing a date that is not in the skip list even though the date is in fact on it:
java weka.Run weka.classifiers.timeseries.WekaForecaster -W "weka.classifiers.functions.MultilayerPerceptron -L 0.01 -M 0.2 -N 500 -V 0 -S 0 -E 20 -H 20 " -t "C:\MyFile.arff" -F DirectionNumeric -L 1 -M 3 -prime 3 -horizon 6 -holdout 100 -G TradeDay -dayofweek -weekend -future -skip ""2014-06-07#yyyy-MM-dd, 2014-06-12"
Does anybody knows how to get this working? Weka is low on documentation as far as I know.
Thank's in advance!
Forget it. I got it, the problem was the 's' must be in capital letters:
-Skip
instead of
-skip.
I want to run the following command for cron job
python test.py -sau 0 -bg 200000 -t mcs3245 > g2g.log
I have setup a cron job like below
5 0 * * * /local/mnt/workspace/username/scripts/python test.py -sau 0 -bg 200000 -t mcs3245 > g2g.log
am getting the following error
/bin/sh: /local/mnt/workspace/username/scripts/python: No such file or directory
Can anyonehelp on what is wrong and how to set this up?
Unless /local/mnt/workspace/username/scripts/ is the directory of your python installation I would suggest something like this:
5 0 * * * /usr/bin/python /path/to/script/test.py -sau 0 -bg 200000 -t mcs3245 > g2g.log
If you want to execute the script as user USERNAME:
5 0 * * * USERNAME /usr/bin/python /path/to/script/test.py -sau 0 -bg 200000 -t mcs3245 > g2g.log
Found that last one here on superuser.com.