You can add several commands separated by ;
Example, every hour:
Once the job is created, you can try it:
When the job is working, you can save it to cron:
bash './myscript'
Display example:
HTTP/1.1 200 OK
X-Powered-By: Express
content-length: 0
connection: close
date: Tue, 23 Jul 2024 09:33:05 GMT
server: Kestrel
HTTP/1.1 200 OK
X-Powered-By: Express
content-length: 0
connection: close
date: Tue, 23 Jul 2024 09:33:05 GMT
server: Kestrel
Crontab
Create a crontab using:
crontab -e
Add a line with your script execution:
* * * * * bash /home/myuser/script/start-connectors.sh
Cron format
If you need help to create your cron format, you can use https://crontab.guru/
Once edited, the script will be launched according to your cron.
You can check logs using:
grep 'home/myuser/script/start-connectors' /var/log/syslog
How to mass create connector
It is sometimes necessary to create a large number of connectors. You can automate the creation process by using ZSA's Rest APIs.
All APIs are available and can be viewed at this address: /zsa/api/v2/q/swagger-ui/
The creation of a connector use the POST API /zsa/api/v2/connectors
Example of full body:
{
"label":"Lpar",
"type":"CSV",
"host":"45.21.456.89",
"port":9999,
"autoStart":true,
"numberOfRetries":2,
"retryDelay":30,
"tags":[
],
"properties":[
{
"name":"NbInstances",
"value":"1"
},
{
"name":"MsgSize",
"value":"5000"
},
{
"name":"ConnectionSleepTime",
"value":"5"
},
{
"name":"AutoScaleInstances",
"value":"false"
}
]
}
All attributes are not mandatory, the mandatory attributes are the following:
{
"label":"Lpar",
"type":"CSV",
"host":"45.21.456.89",
"port":9999
}
Example of shell script to mass create connectors:
# To update
zetaly_host=https://zetaly
zetaly_user='user'
zetaly_password='password'
# List all connecteur/hosts/port
name=(Lpar1 Lpar2)
host=(localhost localhost2)
port=(9999 9999)
# Connector types to create
types=(CSV RAW)
# Set to 1 for more information
debug=0
#####################################
# Check values
#####################################
if [ "${#name[@]}" != "${#host[@]}" ] || [ "${#name[@]}" != "${#port[@]}" ]; then
echo "Error: All arrays does not have the same number of elements."
exit 8
fi
if [ "${#types[@]}" = "0" ]; then
echo "Error: Type arrays does not hae any value."
exit 8
fi
#####################################
# Login (get token)
#####################################
body="{\"username\":\"$zetaly_user\",\"password\":\"$zetaly_password\"}"
url="$zetaly_host/zhb/api/v1/users/public/login"
curlCmd="curl -s -k -H \"Accept: application/json\" -H \"Content-type: application/json\" $url -d '$body' --trace './login.log' -o './login.json'"
if [ "$debug" = 1 ]; then
echo "***********"
echo "Url to call: $url"
echo "Body to send: $body"
echo "Curl command to execute: $curlCmd"
echo "***********"
fi
eval $curlCmd
result=$(cat ./login.json)
if [ "$debug" = 1 ]; then
echo "***********"
echo "Curl result: $result"
echo "***********"
fi
token=$(echo $result | python3 -c "import sys, json; print(json.load(sys.stdin)['token'])")
if [ "$debug" = 1 ]; then
echo "***********"
echo "Token: $token"
echo "***********"
fi
#################################
# Create messaging
#################################
if [ -n "$token" ]; then
url="$zetaly_host/zsa/api/v2/connectors"
maxIndex="${#name[@]}"
forExpr={1..$maxIndex}
for (( i=0; i<maxIndex; i++))
do
connectorName="${name[i]}"
connectorHost="${host[i]}"
connectorPort="${port[i]}"
for type in "${types[@]}"
do
body="{\"label\":\"$connectorName\",\"type\":\"$type\",\"host\":\"$host\",\"port\":$port, \"autoStart\":true}"
curlCmd="curl -s -k -H 'token: $token' -H \"Accept: application/json\" -H \"Content-type: application/json\" $url -d '$body'"
if [ "$debug" = 1 ]; then
echo "***********"
echo "Messaging: $messaging"
echo "Url to call: $url"
echo "Curl command to execute: $curlCmd"
echo "***********"
fi
eval $curlCmd
done
done
else
echo "!!!!!!!!!!!!!!!! Login failed !!!!!!!!!!!!!!!!"
fi
echo ""