for example, I have a directory : /full/path/to/your/dir which contains below files:
$ls /full/path/to/your/dir
/full/path/to/your/dir/test.1.log.gz
/full/path/to/your/dir/test.2.log.gz
/full/path/to/your/dir/test.3.log.gz
if I run the cmd directly on the target host, it will print result without error:
$ls /full/path/to/your/dir/test.!(3).log*
/full/path/to/your/dir/test.1.log.gz
/full/path/to/your/dir/test.2.log.gz
but if i run on another host via ssh to the target host for execution, like:
$ssh myself#hostname "ls /full/path/to/your/dir/test.!(3).log*"
bash: -c: line 0: syntax error near unexpected token `('
bash: -c: line 0: `ls /full/path/to/your/dir/test.!(3).log*'
Also, I tried with below:
$ssh myself#hostname "ls /full/path/to/your/dir/test.'!(3)'.log*"
ls: /full/path/to/your/dir/test.!(3).log*: No such file or directory
Can anyone help to tell how to correct the cmd ?
You are trying to use extended pattern matching features which must be enabled first see here and here That can be enable by shopt -s extglob
what you can do is :
ssh myself#hostname 'ls | grep -v test\.\(3\)\.log$'
Related
I am looking for a reliable method for generating and using temporary, disposable folders, as part of tox environment creation.
[testenv:var-test]
description = Try to store output of a shell command
tmpdir = mktemp -d
commands =
echo {[testenv:var-test]tmpdir}
# prints "mktemp -d" (command is not run)
tmpdir = mktemp -d
# ERROR: InvocationError for command could not find executable tmpdir
There may be better ways, but you certainly can call a bash script from within the commands section.
tox.ini
[testenv]
whitelist_externals = bash
commands =
bash {toxinidir}/commands.sh
commands.sh
TEMP=`mktemp -d`
echo $TEMP
output of a tox run
❯ tox
python run-test-pre: PYTHONHASHSEED='562823002'
python run-test: commands[0] | bash /home/jugmac00/stackOverflow/commands.sh
/tmp/tmp.snc2T0Fa6W
_________________________________________________________ summary __________________________________________________________
python: commands succeeded
congratulations :)
I am using gsutil to move files, but this generates an exception if none of the files are moved.
This is the command I run:
gsutil -m mv gs://{url}/20200116* gs://{destional url}/data/rtbiq_data/
The exception I see:
CommandException: No URLs matched: gs://{url}/20200116*
CommandException: 1 file/object could not be transferred.
I want it to just go through without any exception being thrown even if none of the files are moved. How can I do that?
There isn't an official gsutil mv option to do that, but an one approach is to simply redirect the output of the command to /dev/null, essentially supressing stderr:
gsutil -m mv gs://{url}/20200116* gs://{destional url}/data/rtbiq_data/ 2> /dev/null
I have the following line in my run.sh :
svm-train -s 0 -c 5 -t 2 -g 0.5 -e 0.1 $file >>logfile
and I'm getting the following:
error run.sh: 10: run.sh: svm-train: not found
I have installed libsvm as follows :
Downloaded the zip file
$ cd libsvm-3.0
$ make
$ cd python/
$ make
import svm
Why am I getting the error?
Maybe svm-train is not on your $PATH. One way of checking if svm-train is on your $PATH or not is by typing the following on the command line:
echo $PATH | grep svm-train
If this doesn't display any output and returns directly to the command prompt, this means that svm-train is really not on your $PATH.
To add svm-train to your path, type the following on the command line:
1. [Optional but recommended] Back up the contents of your original $PATH first:
echo $PATH > path.txt
If you open path.txt, you can see that the current value of your $PATH environment variable has been written on this file. Let's designate this as "/original/path".
The reason why you might want to perform this step is that in case you want to revert to your original $PATH, you can just copy the contents of path.txt and type:
export $PATH=/original/path
Determine the full path (or full location) of svm-train is stored on your computer. Let's say this location is "/full/path/to/svm-train" as an example.
Finally, add the location to your $PATH environment variable by typing:
export PATH=$PATH:/full/path/to/svm-train
All
I have following shell command working as per expectation on shell but not working when invoked inside perl
Shell command:
grep -P -s -irl --include \*.v "\s+hello\s?[(].*" <PATH>
working fine
Inside Perl:
$inst_search = `grep -P -s -irl --include \*.v "\s+$inst\s?[(].*" #plt_dirs`;
not working
I am suspecting i am missing something with regexp inside grep..please correct me !
Thanks,
Vivek
Perl will escape special shell characters when calling exec/system/qx (or backticks) with a string.
Try using the exec or system functions, but passing a list, e.g.
system('grep', '-P', '-s', '-irl', '--include', '\*.v', '"\s+hello\s?[(].*"', #plt_dirs);
You may also want to look at a module that does some of the error handling for you, like IPC::System::Simple.
Try this one:
$inst_search = qx#grep -P -s -irl --include \*.v "\s+$inst\s?[(].*" #plt_dirs#;
Or use any other non-alphanumeric character instead of "#"for quoting.
I have a (maybe) unusual situation. I need to run VMware CLI commands in a Windows box, but via the cygwin CLI inside a shell script. I can NOT change this for now, so any suggestions to "why not do this instead" may be futile, although appreciated. Here's a sample script.
#!/bin/bash
# Paths for vmware-cmd.pl file to run vmware commands from vsphere cli
_vcli_dir="/cygdrive/c/Program Files (x86)/VMware/VMware vSphere CLI"
_vcli_bin="$_vcli_dir/bin"
_vcli_perl="$_vcli_dir/Perl"
_vcli_perl_bin="$_vcli_perl/bin"
_vcli_perl_lib="$_vcli_perl/lib"
_vcli_perl_vlib="$_vcli_perl_lib/VMware"
_vcmd=vmware-cmd.pl
export _orig_path=$PATH
# Add above directories to path variable
export PATH=$PATH:$_vcli_dir:$_vcli_bin:$_vcli_perl:$_vcli_perl_bin:$_vcli_perl_lib:$_vcli_perl_vlib
echo $PATH
$_vcmd /?
export PATH=$_orig_path
echo $PATH
When I run the above script, I get
Can't locate VMware/VIRuntime.pm in #INC (#INC contains:
/usr/lib/perl5/site_perl/5.14/i686-cygwin-threads-64int
/usr/lib/perl5/site_perl/5.14
/usr/lib/perl5/vendor_perl/5.14/i686-cygwin-threads-64int
/usr/lib/perl5/vendor_perl/5.14
/usr/lib/perl5/5.14/i686-cygwin-threads-64int /usr/lib/perl5/5.14
/usr/lib/perl5/site_perl/5.10 /usr/lib/perl5/vendor_perl/5.10
/usr/lib/perl5/site_perl/5.8 .) at /cygdrive/c/Program Files
(x86)/VMware/VMware vSphere CLI/bin/vmware-cmd.pl line 8. BEGIN
failed--compilation aborted at /cygdrive/c/Program Files
(x86)/VMware/VMware vSphere CLI/bin/vmware-cmd.pl line 8.
I can run the same vmware-cmd.pl script from a DOS command prompt
c:> vmware-cm.pl
So I now my installation is correct.
Any clues please?
This post gave me the idea to fix it. But now I get a core dump.
How is Perl's #INC constructed? (aka What are all the ways of affecting where Perl modules are searched for?)
The added line is the second export PERL5LIB line.
#!/bin/bash
# Path for vmware-cmd.pl file to run vmware commands from vsphere cli
_vcli_dir="/cygdrive/c/Program Files (x86)/VMware/VMware vSphere CLI"
_vcli_bin="$_vcli_dir/bin"
_vcli_perl="$_vcli_dir/Perl"
_vcli_perl_bin="$_vcli_perl/bin"
_vcli_perl_lib="$_vcli_perl/lib"
_vcli_perl_vlib="$_vcli_perl_lib/VMware"
_vcmd=vmware-cmd.pl
export _orig_path=$PATH
# Add above directories to path variable
export PATH=$PATH:$_vcli_dir:$_vcli_bin:$_vcli_perl:$_vcli_perl_bin:$_vcli_perl_lib:$_vcli_perl_vlib
export PERL5LIB=$_vcli_dir:$_vcli_bin:$_vcli_perl:$_vcli_perl_bin:$_vcli_perl_lib:$_vcli_perl_vlib
echo $PATH
$_vcmd /?
export PATH=$_orig_path
echo $PATH
I solved by going through my elbow to get to my a**, as the saying goes.
What I did was
- Install vmware cli on my Windows box to the default directory
- Added environment variables for the VMware main directory, the bin directory, the Perl directory and the Perl/bin directory
- Added these environment variables to my PATH variable.
Then I created a vmware-cli.bat file that takes parameters and concatenates them into a vmware-cli command with the correct values. For example, I call this to list the VMs in the server
cygwin:> ./vmware-cli.bat vmware-cmd.pl --server MyServer --username User --password PW -l
Inside the batch file I essentailly do
REM Get first parm as the command, and then concatenate the rest of the parms
set VCLI_CMD=%1
shift
:LOOP
if %1x==x goto :EXECUTE
set VCLI_CMD=%VCLI_CMD% %1
shift
goto LOOP:
:EXECUTE
%VCLI_CMD%
This is an alternative to the previous posted that will allow you to keep it in the same shell script
VIMCMD="/cygdrive/C/Program Files (x86)/VMware/VMware vSphere CLI/bin/vmware-cmd.pl"
VIMCMD_DOS=$(cygpath -d "$VIMCMD")
DOS_VIMCMD="cmd /c $VIMCMD_DOS"
Then you can run:
$ $DOS_VIMCMD --version
vSphere SDK for Perl version: 6.0.0
Script 'vmware-cmd.pl' version: 6.0.0