How to filter files by extension with Perl File::RsyncP - perl

I am using Perl library File::RsyncP.
This moment script copies all files, but I need to use
extension and later pattern for example 2019*.xml
I don´t know how to filter files by extension.
I have tried following     
I take a connection into localhost
I have
/home/raimo/A/SRC/srcDirectory/1.xml
/home/raimo/A/SRC/srcDirectory/2.xml
/home/raimo/A/SRC/srcDirectory/3.txt
here
I would like to copy only xml files into    
I have tried:
rsyncCmd => "/bin/rsync -avz --include '*.xml' srcDirectory destDirectory ", and I have tired rsyncCmd => "/bin/rsync -avz --include '*.xml' destDirectory srcDirectory "
/home/raimo/A/SRC/destDirectory
my $rs = File::RsyncP->new({
logLevel => 5,
rsyncCmd => "/bin/rsync --include '*.xml'", #check if possible to filter
rsyncArgs => [
"--numeric-ids",
"--perms",
"--owner",
"--group",
"--devices",
"--links",
"--ignore-times",
"--block-size=700",
"--relative",
"--recursive",
"--verbose"
],
});
...
# Receive files from remote srcDirectory to local destDirectory
# # by running rsyncCmd with rsyncArgs.
$rs->remoteStart(1, srcDirectory);

Related

Execute app and move log created in a folder

I am trying to run an app and move log created in a folder. Here are my codes. Will this works?
Function Execute($command)
{ # execute:
Invoke-Expression $command; }
$extract_path = "E:\Utilities\PeakLicense";
## The name of your executable app
$app = 'E:\Magicxpi49\Runtime\JRE8x64\JRE\bin\java.exe';
## List of arguments:
# -jar Mg-License-Monitor.1.0.jar 1000 ESB-Prod-App01 1000
args = '-jar',
'Mg-License-Monitor.1.0.jar',
'1000',
'ESB-Prod-App01',
'1000';
## Execute the app and store in extract path
Execute "$app $args" x --o+ -c- "$extract_path";

How can I set makefile variables (CC, CFLAGS etc) to terminal or cmd using powershell scripts?

I want to write platform independent Makefile's environment variable setup script which can set Makefile's environment variable like CC, CFLAGS, LDFLAGS, LD etc. This is my make file. I want to run it on Window or Linux as per the user need. So instead of setting CC, CFLAGS, LDFLAGS, LD every time, I want to write a script which can set the variable for user depending on which platform they are using.
LDFLAG=-L..\..\test\lib
LIBS=-ltestlibs
INCLUDES = ..\..\test\inc
SRCS = $(wildcard *.c)
OBJS = $(SRCS:.c=.o)
EXECUTABLE = targetImage.exe
.PHONY: clean
all: myprog
myprog: $(OBJS)
$(CC) $(OBJS) $(LDFLAG) $(LIBS) -o $(EXECUTABLE)
$(OBJS): $(SRCS) $(INCLUDES)
$(CC) $(CFLAGS) -I$(INCLUDES) -c $(SRCS)
clean:
$(RM) $(OBJS) $(EXECUTABLE)
I know the .sh script but it can be run on CYGWIN or MINGW.
#!/bin/sh
echo "Finding the current OS type"
echo
osType="$(uname -s)"
#osType=$1
case "${osType}" in
"CYGWIN")
{
echo "Running on CYGWIN."
CURRENT_OS=CYGWIN
export CC=""
} ;;
Linux*)
{
echo "Running on Linux."
CURRENT_OS=Linux
export CC="-g -Wall"
} ;;
"MINGW")
{
echo "Running on MINGW."
CURRENT_OS=MINGW
} ;;
"Thor96")
{
source /opt/fsl-imx-xwayland/4.14-sumo/environment-setup-aarch64-poky-linux
CURRENT_OS=THOR96
};;
*)
{
echo "Unsupported OS:${osType}, exiting"
exit
} ;;
esac
echo ${CURRENT_OS}
But it can run on linux only. So how can I achieve the same using powershell .ps1 scripts ? So same script can work on any platform.
I have drafted this .ps1 file for reference but need to update it as I am not sure it's correct or not. Please guide me with proper solution. I am not able to find the proper solution for this.
Function RunOn-Windows
{
Write-Host 'The Script is Running on a Windows Machine'
$Env:CC = "gcc"
}
Function RunOn-Linux
{
Write-Host 'The Script is Running on a Linux Machine'
$Env:CC = "gcc"
}
Function RunOn-Mac
{
Write-Host 'The Script is Running on a Mac'
}
Function RunOn-Other
{
Write-Host 'The Script is Running on a Other'
$Env:CC = "aarch64-poky-linux-gcc"
}
If ($IsWindows)
{RunOn-Windows}
elseif ($IsLinux)
{RunOn-Linux}
elseif ($IsMacOS)
{RunOn-Mac}
else
{RunOn-Other}
I don't have a Windows box to do tests but if yours has GNU make available there is a chance that you can do what you want from inside your Makefile:
# List supported OS (as returned by uname -s, case sensitive)
SUPPORTED_OS := CYGWIN Linux MINGW Darwin
# Get OS
OS := $(shell uname -s)
# Check if OS is supported
ifneq ($(filter-out $(SUPPORTED_OS),$(OS)),)
$(error Unsupported OS: $(OS))
endif
# Define all OS-dependent make variables as OS_VARIABLE
# Linux:
Linux_CC := gcc
Linux_CFLAGS := -g -Wall
Linux_LDFLAGS := ...
# CIGWIN:
CYGWIN_CC := ...
CYGWIN_CFLAGS := ...
CYGWIN_LDFLAGS := ...
...
# Assign make variables
CC := $($(OS)_CC)
CFLAGS := $($(OS)_CFLAGS)
LDFLAGS := $($(OS)_LDFLAGS)

Unable to checkout SVN repo using Puppet

I am trying to checkout code from SVN repo for which I am accepting the URL as argument. I have quoted the URL as shown below because it contains spaces. I also checked the parameter by redirecting the $svn_url in file (shown below). If I pick the URL from the file and pass it as is on the command line to the given script, it works fine but somehow when invoked from Puppet, it's not working.
Puppet manifests:
repo_checkout.pp:
define infra::svn::repo_checkout ($svn_url_params) {
$svn_url = $svn_url_params[svn_url]
include infra::params
$repo_checkout_ps = $infra::params::repo_checkout_ps
file { $repo_checkout_ps:
ensure => file,
source => 'puppet:///modules/infra/repo_checkout.ps1',
}
util::executeps { 'Checking out repo':
pspath => $repo_checkout_ps,
argument => "\'\"$svn_url\"\'",
}
}
params.pp:
$repo_checkout_ps = 'c:/scripts/infra/repo_checkout.ps1',
site.pp:
$svn_url_ad = {
svn_url => 'https:\\\\some_repo.abc.com\svn\dir with space\util',
}
infra::svn::repo_checkout { "Checking out code in C:\build":
svn_url_params => $svn_url_ad
}
executeps.pp:
define util::executeps ($pspath, $argument) {
$powershell = 'C:/Windows/System32/WindowsPowerShell/v1.0/powershell.exe -NoProfile -NoLogo -NonInteractive'
exec { "Executing PS file \"$pspath\" with argument \"$argument\"":
command => "$powershell -file $pspath $argument",
timeout => 900,
}
}
PowerShell code:
$svn_url = $args[0]
Set-Location C:\build
echo "svn co --username user --password xxx --non-interactive '$svn_url'" | Out-File c:\svn_url
svn co --username user --password xxx --non-interactive '$svn_url'
Puppet output on agent node:
Util::Executeps[Checking out repo]/Exec[Executing PS file "c:/scripts/infra/repo_checkout.ps1" with argument "'"https:\\some_repo.abc.com\svn\dir with space\util"'"]/returns: executed successfully
Notice: Applied catalog in 1.83 seconds
Content of c:\svn_url:
'https:\\\\some_repo.abc.com\svn\dir with space\util'
UPDATE: Sorry for the confusion but i was trying out several permutations and combinations and in doing that, i forgot to mention that when the $svn_url contains backslash (\), it does NOT work on the command line too if i copy the SVN URL from the text file where i am redirecting the echo output.
Based on #Ansgar's suggestion, i changed '$svn_url' to "$svn_url" in powershell code but the output in text file then contained ' quote twice around the URL. So i changed the argument parameter from "\'\"$svn_url\"\'" to "\"$svn_url\"". Now the output file had only single quote present around the URL. I copied only the URL (along with single quotes around it) from the output file and tried passing it to the powershell script. I now get the following error:
svn: E020024: Error resolving case of 'https:\\some_repo.abc.com\svn\dir with space\util'
Another thing to note is that if i change the back slashes in URL to forward slashes, it works fine on the command line. Invoking from Puppet still doesn't work.
Posting the final configuration that worked out for me based on #AnsgarWiechers' suggestion.
[tom#pe-server] cat repo_checkout.pp
define infra::svn::repo_checkout ($svn_url_params) {
$svn_url = $svn_url_params[svn_url]
...
...
util::executeps { 'Checking out repo':
pspath => $repo_checkout_ps,
argument => "\"$svn_url\"",
}
}
[tom#pe-server] cat repo_checkout.ps1
$svn_url = $args[0]
Set-Location C:\build
svn co --username user --password xxx --non-interactive "$svn_url"
[tom#pe-server] cat params.pp
$repo_checkout_ps = 'c:/scripts/infra/repo_checkout.ps1',
[tom#pe-server] cat site.pp
$svn_url_ad = {
svn_url => 'https://some_repo.abc.com/svn/dir with space/util',
}
infra::svn::repo_checkout { "Checking out code in C:\build":
svn_url_params => $svn_url_ad
}
Thanks a lot #AnsgarWiechers! :)
Note:
In site.pp: Used forwardslashes (/) when specifying svn_url
In repo_checkout.ps1: Changed '$svn_url' to "$svn_url"
In repo_checkout.pp: Changed double-nested (' and ") quoting in argument to single (") nested i.e., from "\'\"$svn_url\"\'" to "\"$svn_url\""

shell "No such file or directory" on variable execution result

some basic function with goal to extract xml var by xpath:
function get_xml_value_from_config_dir {
local src_root=$1
local xpath_expr="//$2/text()"
local path_to_local="$src_root/app/etc/local.xml"
if [ ! -f $path_to_local ]; then echo "Config file not found: $path_to_local"; exit; fi;
echo $("$xmllint --nocdata --xpath '$xpath_expr' $path_to_local")
}
## and then
src_usr=$(get_xml_value_from_config_dir $src_dir username)
gives me
line 34: /usr/bin/xmllint --nocdata --xpath '//username/text()' /tmp/bin/app/etc/local.xml: No such file or directory
why? ( /usr/bin/xmllint exist as well as /tmp/bin/app/etc/local.xml )
It's telling you it can't find the file or directory named
/usr/bin/xmllint --nocdata --xpath '//username/text()' /tmp/bin/app/etc/local.xml
which indeed is unlikely to exist on your system.
Replace
echo $("$xmllint --nocdata --xpath '$xpath_expr' $path_to_local")
with
echo $($xmllint --nocdata --xpath "$xpath_expr" $path_to_local)
Incidentally, that will put all xmllint output on a single line; to avoid that, just use
xmllint --nocdata --xpath "$xpath_expr" $path_to_local

Overwrite if if it exists or create if it does not

I am trying to rewrite a file using puppet with the following function.
If the file exists I still want the file to be rewrite from the source. Will this be achieved with the following method?
define setup_sysctl_conf( $dependence=File[$dummy_dependence_file] )
{
file { $name:
path => '/etc/sysctl.conf',
ensure => present,
mode => 0777,
source => '/vagrant/files/sysctl.conf',
require => $dependence,
}
}
The file: /etc/sysctl.conf will already be present on your host (created by the initscripts package).
I would recommend to modify existing files with puppet using augeas instead of replacing them.
Example (changes net.ipv4.ip_forward to 1):
class sysctl_augeas_example {
augeas{"Set net.ipv4.ip_forward to 1":
context => "/files",
changes => [
"set etc/sysctl.conf/net.ipv4.ip_forward 1",
]
}
}
include sysctl_augeas_example
Save this example as test.pp and run it with puppet apply test.pp