When using Taskctl to dispatch a service, if you need cross-user or cross-server scheduling can be implemented by installing TASKCTL agent, but sometimes there are only a few scripts on the server that needs to execute the job, then deploying the agent at this time is a bit of a loss. We know that Taskctl supports any type of job extension, so we can consider using SSH remote connection to execute these small number of scripts.
The following is the step by extension taskctl with SSH connection to support dispatching remote job, on the one hand to solve some friends urgent scheduling needs, on the other hand, so that we can expand in taskctl more to adapt to their needs of the job plug-in.
The procedures written below refer to http://www.taskctl.com/forum/detail_33.html.
1, first in the server $taskctldir/src/plugin/ssh/shell/directory add cprunssh.sh Job plug-in, is actually a shell program, the code is as follows: #!/bin/sh
#------------------------------------------------------------------------------
# function: SSH mode to execute remote script driver plug-in program
Parameters
# 1. Progname and SH jobs, which correspond to the Progname property of the corresponding task, are generally the full path name of the script
# 2. Para and SH work similarly, corresponding to the corresponding task Para property, usually the script's entry parameters, in the format of Para1 para2 ...
# 3. Exppara corresponds to the Exppara property of the corresponding task, which is usually the location of the script file, where the remote connection IP address and user name
# sip=172.22.1.1 SSH Remote IP address
# sport=9527 SSH Remote connection port
# suser=taskctl SSH remote user
# return value: 0 success; 1 failure
#
# Process Pattern Code Task Definition Example:
# The SH script on the remote server with default 2 input parameters (if multiple, etc.)
# <ssh>
# <name>job1</name>
# <progname>/home/username/test.sh</progname>
# <PARA>PARA1 Para2</para>
# <exppara>sip=172.22.1.1,[sport=22,]suser=taskctl</exppara>
# </ssh>
#
#------------------------------------------------------------------------------
If [$#-ne 3]
Then
echo "Param Error!"
echo "Usage: $ progname para Expara"
Exit 126
Fi
#------------------------------------------------------------------------------
# First step: Receive parameters
#------------------------------------------------------------------------------
Progname=$1
Para=$2
Exppara=$3
#------------------------------------------------------------------------------
# Step Two: Parse Exppara
#------------------------------------------------------------------------------
function GetValue () {
If [$#-ne 2]
Then
echo "..."
Exit 1
Fi
Str= ' echo $2|awk-v record=$1 ' BEGIN {
Split (Record,myarray, ",");
}
end{
For (i in myarray) {
if (myarray[i]~$1) {
if (index (myarray[i],$1) = = 1) {
Print Myarray[i];
Break
}
}
}
}
'`
echo $str |awk-f "=" ' {print $} '
}
Exppara= ' echo $ExpPara ' #此处为了去前后空格 in order to determine if there is a real entry parameter
sip= ' getValue $ExpPara sip '
#sport = ' GetValue $ExpPara sport ' #默认没有修改端口 pass the parameters without first shielding
Sport=22
Suser= ' GetValue $ExpPara suser '
#------------------------------------------------------------------------------
# Step Three: Detect if an ssh-free connection is configured
#------------------------------------------------------------------------------
Ssh-o numberofpasswordprompts=0-o stricthostkeychecking=no-p $sport $suser @ $sip ' pwd ' &>/dev/null
If [$?! = 0];then
Echo-e "\ n cannot connect to $sip"
Echo-e "\ n can refer to the following statement to try to configure a secret-free connection"
Echo-e "\nssh-keygen-t rsa-p"
Echo-e "\nssh-copy-id-p $sport $suser @ $sip"
Exit 1
Else
Echo-e "\n$sip:ssh Connect is OK"
Fi
#------------------------------------------------------------------------------
# Fourth Step: Run the job and wait for the result
#------------------------------------------------------------------------------
#echo "Ssh-o numberofpasswordprompts=0-o stricthostkeychecking=no-p $sport $suser @ $sip sh $ProgName $Para" #此处为打印执行命令行, For debugging to determine if there is a real entry parameter
echo "================================================================================"
Ssh-o numberofpasswordprompts=0-o stricthostkeychecking=no-p $sport $suser @ $sip "sh $ProgName $Para"
Ret=$?
#------------------------------------------------------------------------------
# Fifth Step: Plugin return
#------------------------------------------------------------------------------
echo "================================================================================"
if [[$ret = = 0]]; Then
echo "Run Job success!"
Exit 0
Else
echo "Run Job failed!"
Exit 1
Fi
2, in the desktop software admin into the "task type" function, set the SSH job type, as shown in the following image:
3, design the SSH job in desktop software designer The following code snippet: <!--process set by plugin rules--
<ssh>
<name>MainModul_JobNode0</name>
<progname>/home/cdchen/successjob.sh</progname>
<para>para1 para2</para>
<exppara>sip=47.94.203.124,suser=cdchen</exppara>
<jobdesc> Test SSH Jobs </jobdesc>
</ssh>
4, debugging test work to meet the expectations