$1: IP (as string, but must be a valid IP)
$2: username (as string with length > 0)
$3: script name (as string with length > 0)
$4: extra instructions on command line (as quoted escaped string between parenthesys)
what return: “DONE” if is done, else nothing.
I have another question. My SSH script transfer function does not work, although everything seems to be correct. Here the task is not to immediately execute the function, but to take the text of the repository script, transfer it and create a script on the SSH server with the same text as the source. Then it can be executed if needed.
And this is not always the case. It transfers quite simple scripts normally.
I understand that this is unpleasant for you, but could you point out my mistake in the text of my script?
# $1 is the address of the remote SSH server
# $2 - username of remote SSH server for SSH connection
# $3 is the name of the source script on the SSH client
# $4 is the name of the executable script created on the SSH server
# $5 - run - if you need to run the passed script immediately, in this case, after execution, it is removed from the repository
# if $5 is not set, the passed script is placed in the repository and is not executed.
:global SSHscript do={
:local ReplaceChars do={
:local cmd
:for idx from=0 to=([:len $1] - 1) do={
:local char [:pick $1 $idx]
:if ($char~"(\a|\b|\f|\n|\r|\v)") do={:set char ";"}
:if ($char = "\t") do={:set char " "}
:set cmd "$cmd$char"
}
:return $cmd
}
:if ([:len $1]=0) do={:return "Error IP SSH-Server"}
do {:set $1 [:toip $1]} on-error={:return "Error syntax address IP SSH-Server"}
:if (!any $2) do={:return "Error username"}
:if ([:len $3]=0) do={:return "Error Script-sourse name not set"}
:if ([:len $4]=0) do={:return "Error Script SSH name not set"}
:if ([:len [/system script find name=$3]]=0) do={:return "Error Script $3 no find in repository"}
:global F
:do {
:set F [/system script get $3 source]
:log warning $F
} on-error={:return "Error reading a script into a variable script larger than 4096 bytes"}
:set F [$ReplaceChars $F]
:log error $F
:if ([:len $5]=0) do={
:do {
[/system ssh-exec address=$1 user=$2 command="/system script remove \"$4\""]
:delay 2s;
[/system ssh-exec address=$1 user=$2 command="/system script add name=\"$4\" source=\"$F\""]
} on-error={:return "Error transmitting or creating a script on the SSH server"}
:log warning "Script $3 was transferred to the SSH server $1"; :return "Done"
}
:if (([:len $5]!=0) && ($5="run")) do={
:do {
[/system ssh-exec address=$1 user=$2 command="/system script remove \"$4\""]
:delay 2s;
[/system ssh-exec address=$1 user=$2 command="/system script add name=\"$4\" source=\"$F\"; /system script run \"$4\"; /system script remove \"$4\""]
} on-error={:return "Error transmitting or creating a script on the SSH server"}
:log warning "Script $3 was transferred to the SSH server $1 and executed"; :return "Done"
} else={:return "Error parametr $5"}
}
:local sshAns [$SSHscript 192.168.1.2 admin ip2bin ScriptSSH]
:if ($sshAns!="Done") do={:log error $sshAns}
I’m not going to waste my time with people who foolishly keep contradicting me.
It’s not that I’m never wrong, but when something is certain I don’t waste time explaining it over and over again.
“as-value” does not exist for either v6 or v7.7
Spending all the time refuting what I write is not a collaborative attitude,
go to hell.
You are probably a talented person, but this does not give you the right to send others somewhere … (for example, to hell).
Better help me with the function. I really need your help.
If for some reason it is not convenient for you to correspond here, we can go to the section of private messages that no one will see
Once again I emphasize that I am writing something not to convict you of a mistake, but because it is important for me to understand and understand. I don’t have the knowledge you have, but that doesn’t mean I’m stupid. The doctor also has to be patient, explaining many medical issues to his patients, but I don’t call them fools and don’t send them to hell