Comprehensive data protection for all workloads
Post Reply
baber
Veteran
Posts: 665
Liked: 4 times
Joined: Nov 21, 2013 12:02 pm
Full Name: Babak Seyedi nejad
Contact:

script output during surebackup

Post by baber »

Dear all
Hi

i have written a script and put that in surebackup and it run on my linux server without problem for example i said

Code: Select all

#!/bin/bash 
find /tmp -name 'b.txt' > /tmp/rep.txt
if [ -s /tmp/rep.txt ] 
then
echo "true"
fi

now i want if could not return true in job task for script part show fail means if rep.txt file was empty it show fail in veeam
what do i have to do ?

BR
PTide
Product Manager
Posts: 6551
Liked: 765 times
Joined: May 19, 2015 1:46 pm
Contact:

Re: script output during surebackup

Post by PTide »

Hi,

I think it would be easier to achieve what you want with another tool. It is similar to putty, and is called plink.

Thanks
baber
Veteran
Posts: 665
Liked: 4 times
Joined: Nov 21, 2013 12:02 pm
Full Name: Babak Seyedi nejad
Contact:

Re: script output during surebackup

Post by baber »

so thanks
before that i said script work perfect and i use plink but just want for example if my script not run or out put of my script was not that defined in surebackup task for script show failed for example in above script i say if report.txt file had size echo true it means if report.txt size file = 0 it had be failed but in both mode in surebackup job show succeed
PTide
Product Manager
Posts: 6551
Liked: 765 times
Joined: May 19, 2015 1:46 pm
Contact:

Re: script output during surebackup

Post by PTide »

For example, you can place this line in your .bat script that you start from VBR:

Code: Select all

plink -v 172.16.11.199 -l user -pw password "ls this.file -laht" > "/path/to/the/file/on/windows/machine.txt"
ls this.file -laht output will be saved in machine.txt on the Windows machine where you start your .bat from.

Thank
baber
Veteran
Posts: 665
Liked: 4 times
Joined: Nov 21, 2013 12:02 pm
Full Name: Babak Seyedi nejad
Contact:

Re: script output during surebackup

Post by baber »

so thanks
i think you did not understand my means this is my scenario :
1- i wrote my linux script and put it on veeam backup server and will be run during surebackup job and get succeed but for example i wrote an script that can check the size of txt file in a path and from the size of this file i can understand my backup is health or corrupted now how can i do that if my file don't have size in surebackup job in test script show fail and if my file had size in surebackup job show succedd

BR
PTide
Product Manager
Posts: 6551
Liked: 765 times
Joined: May 19, 2015 1:46 pm
Contact:

Re: script output during surebackup

Post by PTide »

This is how I understood what you need:

1. You start some windows script (.ps or .bat) that executes remote .sh linux script on a linux machine in a virtual lab.
2. The .sh script checks if some file exists on the remote host and also checks its size.
3. You want to know the size that the .sh script returns. Depending on the value your main SureBackup script that is started on VBR should return either '0' (success), or '1' (error) so you know if your backup is good or bad.

In other words - you want your remote .sh script to return the result to your VBR machine.

Is that correct?

Thanks
baber
Veteran
Posts: 665
Liked: 4 times
Joined: Nov 21, 2013 12:02 pm
Full Name: Babak Seyedi nejad
Contact:

Re: script output during surebackup

Post by baber »

so thanks
1-3 are correct now i want when my script run and according to script if the size of that file was not ok vbr return '1' instead of 0 and if it return '1' in sure backup task for script test will be show fail and according this fail i can understand my backup file is not ok

BR
PTide
Product Manager
Posts: 6551
Liked: 765 times
Joined: May 19, 2015 1:46 pm
Contact:

Re: script output during surebackup

Post by PTide »

Then use the example that I've provided in my previous post:

Code: Select all

plink -v 172.16.11.199 -l user -pw password "ls this.file -laht" > "/path/to/the/file/on/windows/machine.txt"
It executes ls this.file -laht command remotely on 172.16.11.199 and saves the output on your local machine in /path/to/the/file/on/windows/machine.txt.
You can parse that .txt file with your main script and, based on the result, return whatever value you need.

Thanks
baber
Veteran
Posts: 665
Liked: 4 times
Joined: Nov 21, 2013 12:02 pm
Full Name: Babak Seyedi nejad
Contact:

Re: script output during surebackup

Post by baber »

thanks

now imagine your script do "ls -this.file -lah" > /tmp/1.txt and it has an output now i want if output is such as below in 1.txt :

Code: Select all

-rw-r--r--  1 root   root       0 Feb 19 18:31 this.file
return '0' (success),

and if my output is other in 1.txt file

return '1' (error)

BR
PTide
Product Manager
Posts: 6551
Liked: 765 times
Joined: May 19, 2015 1:46 pm
Contact:

Re: script output during surebackup

Post by PTide »

Why can't you just use the same script that you run in your SureBackup job to check what's in the file and use if-else statement to return either 1 or 0 ?
baber
Veteran
Posts: 665
Liked: 4 times
Joined: Nov 21, 2013 12:02 pm
Full Name: Babak Seyedi nejad
Contact:

Re: script output during surebackup

Post by baber »

PTide wrote:Why can't you just use the same script that you run in your SureBackup job to check what's in the file and use if-else statement to return either 1 or 0 ?
I have used IF in my script this is my script

Code: Select all

#!/bin/bash
find /tmp -name 'b.txt' > /tmp/rep.txt
if [ -s /tmp/rep.txt ]
then
echo "true"
fi
but

in above script i said write the output of find command in rep.txt and if rep.txt file had size my backup file is ok
i run this script in my sure backup in first scenario while there was b.txt file and rep.txt had size and surebackup get succeed
in script check part but
in second scenario i delete b.txt file and there was not any output in find command and rep.txt file had no size but another in sure backup task for script test part get succeed
what do i have to do ?
tdewin
Veeam Software
Posts: 1818
Liked: 655 times
Joined: Mar 02, 2012 1:40 pm
Full Name: Timothy Dewin
Contact:

Re: script output during surebackup

Post by tdewin »

Well like I understand your question, you want to do the following:
- if the file exists, surebackup job should be succesful
- if the file does not exists, surebackup job should fail (maybe logging extra stuff)

In my test setup I put putty in a directory c:\bin\, eg c:\bin\plink.exe. Then I created a powershell wrapper c:\bin\wrapper.ps1 . This one contains:

Code: Select all

<#
accept ssl certif with PsExec.exe  -i -s c:\bin\plink 192.168.15.166 (first boot with hang)
https://docs.microsoft.com/en-us/sysinternals/downloads/pstools
#>
param(
$fexist = "/root/hellodarknessmyoldfriend.txt",
$plink = "C:\bin\plink.exe",
$ip = "192.168.1.166",
$username = "root",
$password = "mysecretpassword"
)

write-host "Testing for $fexist @ $ip"
$argplink = @("-v",$ip,"-l", $username, "-pw", $password,"ls $fexist")
$pinfo = New-Object System.Diagnostics.ProcessStartInfo
$pinfo.FileName = $plink
$pinfo.RedirectStandardError = $true
$pinfo.RedirectStandardOutput = $true
$pinfo.UseShellExecute = $false
$pinfo.Arguments = $argplink
$p = New-Object System.Diagnostics.Process
$p.StartInfo = $pinfo
$p.Start() | Out-Null
$p.WaitForExit()
$stdout = $p.StandardOutput.ReadToEnd()
$stderr = $p.StandardError.ReadToEnd()
if($stdout.trim() -ne "") {
    write-host "File exists"
    exit 0
} else {
    write-host "Something went wrong, ... dumping $stderr"
    $stderr >> c:\bin\log.txt
    exit 1
}
I then use the following Test script settings:
Path :

Code: Select all

C:\bin\wrapper.ps1
Arguments :

Code: Select all

-ip %vm_ip% -fexist "/root/fakenews.txt"
(where /root/fakenews.txt is the file I want to test)

You can then check the Surebackup logs. They are normally under C:\ProgramData\Veeam\Backup\<JOBNAME>\Job.<JOBNAME>.log e.g. C:\ProgramData\Veeam\Backup\SureBackup_Job_SureLinux\Job.SureBackup_Job_SureLinux.log in my case. You can look for [Console] in the file to look for the "write-host" you do in powershell

Success if the file exists (I tested for /root as you can see)

Code: Select all

[20.02.2018 18:39:03] <19> Info     [SureBackup] [surelinux] [ScriptTests] [Console] Testing for /root @ 192.168.15.166
[20.02.2018 18:39:14] <19> Info     [SureBackup] [surelinux] [ScriptTests] [Console] File exists
Fail if the file doesn't exists (I tested for /root/fakenews.txt but it doesn't exists on the server)

Code: Select all

[20.02.2018 18:44:04] <20> Info     [SureBackup] [surelinux] [ScriptTests] [Console] Testing for /root/fakenews.txt @ 192.168.15.166
[20.02.2018 18:44:14] <21> Info     [SureBackup] [surelinux] [ScriptTests] [Console] Something went wrong, ... dumping Looking up host "192.168.15.166"
[20.02.2018 18:44:14] <21> Info     [SureBackup] [surelinux] [ScriptTests] [Console] Connecting to 192.168.15.166 port 22
[20.02.2018 18:44:14] <21> Info     [SureBackup] [surelinux] [ScriptTests] [Console] Server version: SSH-2.0-OpenSSH_7.4
[20.02.2018 18:44:14] <21> Info     [SureBackup] [surelinux] [ScriptTests] [Console] Using SSH protocol version 2
[20.02.2018 18:44:14] <21> Info     [SureBackup] [surelinux] [ScriptTests] [Console] We claim version: SSH-2.0-PuTTY_Release_0.62
[20.02.2018 18:44:14] <20> Info     [SureBackup] [surelinux] [ScriptTests] [Console] Using Diffie-Hellman with standard group "group14"
[20.02.2018 18:44:14] <20> Info     [SureBackup] [surelinux] [ScriptTests] [Console] Doing Diffie-Hellman key exchange with hash SHA-1
[20.02.2018 18:44:14] <20> Info     [SureBackup] [surelinux] [ScriptTests] [Console] Host key fingerprint is:
[20.02.2018 18:44:14] <20> Info     [SureBackup] [surelinux] [ScriptTests] [Console] ssh-rsa 2048 e0:ab:d9:77:cd:93:1b:80:4e:3e:bd:30:75:1c:2f:28
[20.02.2018 18:44:14] <20> Info     [SureBackup] [surelinux] [ScriptTests] [Console] Initialised AES-256 SDCTR client->server encryption
[20.02.2018 18:44:14] <20> Info     [SureBackup] [surelinux] [ScriptTests] [Console] Initialised HMAC-SHA1 client->server MAC algorithm
[20.02.2018 18:44:14] <20> Info     [SureBackup] [surelinux] [ScriptTests] [Console] Initialised AES-256 SDCTR server->client encryption
[20.02.2018 18:44:14] <20> Info     [SureBackup] [surelinux] [ScriptTests] [Console] Initialised HMAC-SHA1 server->client MAC algorithm
[20.02.2018 18:44:14] <20> Info     [SureBackup] [surelinux] [ScriptTests] [Console] Using username "root".
[20.02.2018 18:44:14] <20> Info     [SureBackup] [surelinux] [ScriptTests] [Console] Using SSPI from SECUR32.DLL
[20.02.2018 18:44:14] <20> Info     [SureBackup] [surelinux] [ScriptTests] [Console] Attempting GSSAPI authentication
[20.02.2018 18:44:14] <20> Info     [SureBackup] [surelinux] [ScriptTests] [Console] GSSAPI authentication request refused
[20.02.2018 18:44:14] <20> Info     [SureBackup] [surelinux] [ScriptTests] [Console] Sent password
[20.02.2018 18:44:14] <20> Info     [SureBackup] [surelinux] [ScriptTests] [Console] Access granted
[20.02.2018 18:44:14] <20> Info     [SureBackup] [surelinux] [ScriptTests] [Console] Opened channel for session
[20.02.2018 18:44:14] <20> Info     [SureBackup] [surelinux] [ScriptTests] [Console] Started a shell/command
[20.02.2018 18:44:14] <20> Info     [SureBackup] [surelinux] [ScriptTests] [Console] Server sent command exit status 2
[20.02.2018 18:44:14] <20> Info     [SureBackup] [surelinux] [ScriptTests] [Console] ls: cannot access /root/fakenews.txt: No such file or directory
[20.02.2018 18:44:14] <20> Info     [SureBackup] [surelinux] [ScriptTests] [Console] Disconnected: All channels closed
[20.02.2018 18:44:14] <20> Info     [SureBackup] [surelinux] [ScriptTests] [Console] 
tdewin
Veeam Software
Posts: 1818
Liked: 655 times
Joined: Mar 02, 2012 1:40 pm
Full Name: Timothy Dewin
Contact:

Re: script output during surebackup

Post by tdewin »

Small update to the wrapper that will automatically send "yes" to stdin so that certificate will be accepted automatically and check if the output match the filename (so ls really replied /root/myfile.txt check)

Code: Select all

<#
accepts certifs automatically
#>
param(
$fexist = "/root/hellodarknessmyoldfriend.txt",
$plink = "C:\bin\plink.exe",
$ip = "192.168.1.166",
$username = "root",
$password = "mypass"
)

write-host "Testing for $fexist @ $ip"
$argplink = @("-v",$ip,"-l", $username, "-pw", $password,"ls $fexist")
$pinfo = New-Object System.Diagnostics.ProcessStartInfo
$pinfo.FileName = $plink
$pinfo.RedirectStandardError = $true
$pinfo.RedirectStandardOutput = $true
$pinfo.RedirectStandardInput = $true
$pinfo.UseShellExecute = $false
$pinfo.Arguments = $argplink
$p = New-Object System.Diagnostics.Process
$p.StartInfo = $pinfo
$p.Start() | Out-Null
$p.StandardInput.Write("yes")
$p.WaitForExit()
$stdout = $p.StandardOutput.ReadToEnd()
$stderr = $p.StandardError.ReadToEnd()
if($stdout.trim() -eq "$fexist") {
    write-host ("File exists {0}" -f $stdout.trim())
    exit 0
} else {
    write-host "Something went wrong, ... dumping $stderr"
    $stderr >> c:\bin\log.txt
    exit 1
}
Post Reply

Who is online

Users browsing this forum: No registered users and 83 guests