I recently updated my dev machine from Fedora 30 to 31, but I still need to target a Fedora 30 machine.
I am trying to build a SPEC using the parameter --target f30, but I get an error for 'xargs' out of nowhere...
rpmbuild -bb ~/rpmbuild/SPECS/Project.spec --target f30
Building target platforms: f30
Building for target f30
Executing(%prep): /bin/sh -e /var/tmp/rpm-tmp.hUazCA
+ umask 022
+ cd /home/matthew/rpmbuild/BUILD
+ cd /home/matthew/rpmbuild/BUILD
+ rm -rf Project-1.9.1
+ /usr/bin/gzip -dc /home/matthew/rpmbuild/SOURCES/Project-1.9.1.tar.gz
+ /usr/bin/tar -xof -
+ STATUS=0
+ '[' 0 -ne 0 ']'
+ cd Project-1.9.1
+ /usr/bin/chmod -Rf a+rX,u+w,g-w,o-w .
+ RPM_EC=0
++ jobs -p
+ exit 0
Executing(%build): /bin/sh -e /var/tmp/rpm-tmp.TnKydD
+ umask 022
+ cd /home/matthew/rpmbuild/BUILD
+ cd Project-1.9.1
+ RPM_EC=0
++ jobs -p
+ exit 0
Executing(%install): /bin/sh -e /var/tmp/rpm-tmp.GIPsyB
+ umask 022
+ cd /home/matthew/rpmbuild/BUILD
+ '[' '/home/matthew/rpmbuild/BUILDROOT/Project-1.9.1-1.fc31.%{_arch}' '!=' / ']'
+ rm -rf '/home/matthew/rpmbuild/BUILDROOT/Project-1.9.1-1.fc31.%{_arch}'
++ dirname '/home/matthew/rpmbuild/BUILDROOT/Project-1.9.1-1.fc31.%{_arch}'
+ mkdir -p /home/matthew/rpmbuild/BUILDROOT
+ mkdir '/home/matthew/rpmbuild/BUILDROOT/Project-1.9.1-1.fc31.%{_arch}'
+ cd Project-1.9.1
+ mkdir -p '/home/matthew/rpmbuild/BUILDROOT/Project-1.9.1-1.fc31.%{_arch}/opt/Project'
+ cp -a README.md __dump__ __files__ __scripts__ __wheels__ apps dbms dbtools graph.png loc manage.py meta program requirements.txt rgs static veh '/home/matthew/rpmbuild/BUILDROOT/Project-1.9.1-1.fc31.%{_arch}/opt/Project'
+ /usr/lib/rpm/check-buildroot
xargs: invalid number for -P option
Usage: xargs [OPTION]... COMMAND [INITIAL-ARGS]...
Run COMMAND with arguments INITIAL-ARGS and more arguments read from input.
Mandatory and optional arguments to long options are also
mandatory or optional for the corresponding short option.
-0, --null items are separated by a null, not whitespace;
disables quote and backslash processing and
logical EOF processing
-a, --arg-file=FILE read arguments from FILE, not standard input
-d, --delimiter=CHARACTER items in input stream are separated by CHARACTER,
not by whitespace; disables quote and backslash
processing and logical EOF processing
-E END set logical EOF string; if END occurs as a line
of input, the rest of the input is ignored
(ignored if -0 or -d was specified)
-e, --eof[=END] equivalent to -E END if END is specified;
otherwise, there is no end-of-file string
-I R same as --replace=R
-i, --replace[=R] replace R in INITIAL-ARGS with names read
from standard input; if R is unspecified,
assume {}
-L, --max-lines=MAX-LINES use at most MAX-LINES non-blank input lines per
command line
-l[MAX-LINES] similar to -L but defaults to at most one non-
blank input line if MAX-LINES is not specified
-n, --max-args=MAX-ARGS use at most MAX-ARGS arguments per command line
-P, --max-procs=MAX-PROCS run at most MAX-PROCS processes at a time
-p, --interactive prompt before running commands
--process-slot-var=VAR set environment variable VAR in child processes
-r, --no-run-if-empty if there are no arguments, then do not run COMMAND;
if this option is not given, COMMAND will be
run at least once
-s, --max-chars=MAX-CHARS limit length of command line to MAX-CHARS
--show-limits show limits on command-line length
-t, --verbose print commands before executing them
-x, --exit exit if the size (see -s) is exceeded
--help display this help and exit
--version output version information and exit
Report bugs to <bug-findutils#gnu.org>.
+ /usr/lib/rpm/redhat/brp-ldconfig
+ /usr/lib/rpm/brp-compress
+ /usr/lib/rpm/brp-strip /usr/bin/strip
+ /usr/lib/rpm/brp-strip-comment-note /usr/bin/strip /usr/bin/objdump
+ /usr/lib/rpm/brp-strip-static-archive /usr/bin/strip
xargs: invalid number for -P option
Usage: xargs [OPTION]... COMMAND [INITIAL-ARGS]...
Run COMMAND with arguments INITIAL-ARGS and more arguments read from input.
Mandatory and optional arguments to long options are also
mandatory or optional for the corresponding short option.
-0, --null items are separated by a null, not whitespace;
disables quote and backslash processing and
logical EOF processing
-a, --arg-file=FILE read arguments from FILE, not standard input
-d, --delimiter=CHARACTER items in input stream are separated by CHARACTER,
not by whitespace; disables quote and backslash
processing and logical EOF processing
-E END set logical EOF string; if END occurs as a line
of input, the rest of the input is ignored
(ignored if -0 or -d was specified)
-e, --eof[=END] equivalent to -E END if END is specified;
otherwise, there is no end-of-file string
-I R same as --replace=R
-i, --replace[=R] replace R in INITIAL-ARGS with names read
from standard input; if R is unspecified,
assume {}
-L, --max-lines=MAX-LINES use at most MAX-LINES non-blank input lines per
command line
-l[MAX-LINES] similar to -L but defaults to at most one non-
blank input line if MAX-LINES is not specified
-n, --max-args=MAX-ARGS use at most MAX-ARGS arguments per command line
-P, --max-procs=MAX-PROCS run at most MAX-PROCS processes at a time
-p, --interactive prompt before running commands
--process-slot-var=VAR set environment variable VAR in child processes
-r, --no-run-if-empty if there are no arguments, then do not run COMMAND;
if this option is not given, COMMAND will be
run at least once
-s, --max-chars=MAX-CHARS limit length of command line to MAX-CHARS
--show-limits show limits on command-line length
-t, --verbose print commands before executing them
-x, --exit exit if the size (see -s) is exceeded
--help display this help and exit
--version output version information and exit
Report bugs to <bug-findutils#gnu.org>.
error: Bad exit status from /var/tmp/rpm-tmp.GIPsyB (%install)
RPM build errors:
Bad exit status from /var/tmp/rpm-tmp.GIPsyB (%install)
Using the very verbose -vv option with 'rpmbuild' didn't provide anything useful. Any ideas what the issue could be?
Even when targeting f31 (the platform itself) specifically, the build fails, but when not adding a target such that it defaults to f31, it succeeds.
The target option is for architecture. And even that works only if you do some other low level magic. You should do:
rpmbuild -bs ~/rpmbuild/SPECS/Project.spec
# this will produce Project.src.rpm
mock -r fedora-30-x86_64 Project.src.rpm
And it will does not matter whether you are on F30 or 31 or on CentOS.
Related
I'm setting up jenkins freestyle job with bash script build step with ack command, Why I am not getting same result as from command bash on macOS?
Jenkins is set up on this macOS. I am using sck 2.28 version. I have tried to specify exact path to SCK declaration.
DEVVER=$\(/usr/local/Cellar/ack/2.28/bin/ack /path/to/file/app.config.ts -o --match '(?<=devVersion = ")(\d+\.)(\d+\.)(\d+)'\)
echo ${DEVVER}
Expected Output:
1.9.16
Actual Output:
/path/to/file/app.config.ts: line 1: export: `{': not a valid identifier
/path/to/file/app.config.ts: line 3: static: command not found
... (same for each line till 221;)
/path/to/file/app.config.ts: line 221: syntax error: unexpected end of file
As a workaround solution (not too good one) I have changed a command. Now I use grep -E "regex" in which I have removed ?<= and replaced spaces with . and cut the not matching characters in found line.
I would like to run the following command from Jenkins:
ssh -i ~/.ssh/company.pem -o StrictHostKeyChecking=no user#$hostname "supervisorctl start company-$app ; awk -v app=$app '$0 ~ "program:company-"app {p=NR} p && NR==p+6 && /^autostart/ {$0="autostart=true" ; p=0} 1' /etc/supervisord.conf > $$.tmp && sudo mv $$.tmp /etc/supervisord.conf”
This is one of the last steps of a job which creates a CloudFormation stack.
Running the command from the target server's terminal works properly.
In this step, I'd like to ssh to each one of the servers (members of ASG's within the new stack) and search and replace a specific line as shown above in the /etc/supervisord.conf, basically setting one specific service to autostart.
When I run the command I get the following error:
Usage: awk [POSIX or GNU style options] -f progfile [--] file ...
Usage: awk [POSIX or GNU style options] [--] 'program' file ...
I've tried escaping the double quotes but got the same error, any idea what I'm doing wrong?
You are running in to this issue due to the way the shell handles nested quotes. This is a use case for a HERE DOCUMENT or heredoc - A HERE DOCUMENT allows you to write multi-line commands passed through bash without worrying about quotes. The structure is as follows:
$ ssh -t user#server.com <<'END'
command |\
command2 |\
END
<--- Oh yeah, the -t is important to the ssh command as it lets the shell know to behave as if being used interactively, and will avoid warnings and unexpected results.
In your specific case, you should try something like:
$ ssh -t -i ~/.ssh/company.pem -o StrictHostKeyChecking=no user#$hostname <<'END'
supervisorctl start company-$app |\
awk -v app=$app '$0 ~ \"program:company-\"app {p=NR} p && NR==p+6 \
&& /^autostart/ {$0="autostart=true" ; p=0} 1' \
/etc/supervisord.conf > $$.tmp && sudo mv $$.tmp /etc/supervisord.conf
END
Just a note, since I can't be sure about your desired output of the command you are running, be advised to keep track of your own " and ' marks, and to escape them accordingly in your awk command as you would at an interactive terminal. I notice the "'s around program:company and I am confused a bit by them If they are a part of the pattern in the string being searched they will need to be escaped accordingly. P.S.
A little context for my project: We have an arbitrary number of files that need a separate process for each file then need to search using an exec() call to find every time a specific KEY is used. I know how to use grep from the command line using this command:
grep -o KEY FILENAME.txt | wc -l > OUTPUT.txt
But I cannot figure out how to do this in c++. I found a thread on here that gave me this line.
execl("/bin/grep","grep",pattern,filename,NULL);
It compiles and runs so I think it works but the problem is I need to output the number of times the pattern occurred to a file and I tried the line below but expectedly it didn't work. It gave this error "grep: out.txt: No such file or directory"
execl("/bin/grep", "grep",pattern,fileName,output,NULL);
Here are the directions of this part of my project.
You can do this by means of the
system call exec() , providing it with the path to the executable of the shell (typically, /bin/sh )
and, as arguments of /bin/sh , the string -c and the string corresponding to the search command
( grep -o ... ).
Some guidance here would be much appreciated!
For the actual execution as you would do on command line would be:
execl("/bin/sh", "/bin/sh", "-c", "grep -o KEY FILENAME.txt | wc -l > OUTPUT.txt")
This will mean that the shell would take the line grep -o KEY FILENAME.txt | wc -l > OUTPUT.txt, interpret it and run it. Note that this will include wild card expansion and all what the shell does.
Then of course if you wan't to continue after it has completed you will have to fork first because execl does not return if it's successful at starting the program (ie bash).
I'm trying to create a pre-commit hook in Git that will check for any debugging code and prompt the user to fix it. I have a regex that I'm grepping for (ignore the fact that it won't exclude occurrences in multiline comments!):
grep -IiRn --exclude-dir={node_modules,vendor,public,lib,contrib} --include=\*.{module,inc,install,php,js} -P '^\s*(?!\/\/)\s*(dpm\(|dsm\(|console.log\()' /path/to/code/
This works fine when I run it normally in the console, but when I try it in an executable .sh script it does nothing. None of the following has worked for me:
#!/bin/sh
grep ...
MYVAR =`grep ...` # Note the backticks!
echo $MYVAR
MYVAR =$(grep ...)
echo $MYVAR
MYVAR ="`grep ...`"
echo $MYVAR
I tried doing it with Python and os.system() but that did nothing either. It seems to just have no STDOUT. There's possibly something obvious I'm missing but I'm at a loose end.
Any help would be much appreciated! Thanks.
Edit:
This is the exact script, even though it's at the earliest possible stage due to not being able to actually do the first bit. I've hidden the exact folder names because it's probably best to not share my company's code base on SO ;)
#!/bin/bash
echo "Test!"
ONE=`grep -IiRn --exclude-dir={node_modules,vendor,public,lib,contrib} --include=\*.{module,inc,install,php,js} -P '^\s*(?!\/\/)\s*(dpm\(|dsm\(|console.log\()' /company/projects/company/www/sites/all/modules/custom/`
TWO=$(grep -IiRn --exclude-dir={node_modules,vendor,public,lib,contrib} --include=\*.{coffee} -P '^\s*(?!\#)\s*(dpm\(|dsm\(|console.log)' /company/projects/company/www/sites/all/modules/custom/)
echo $ONE
echo "$TWO"
... and running bash -x pre-commit returns:
ubuntu#ip-12-34-56-78:/company/projects/company/scripts$ bash -x pre-commit
+ echo 'Test!'
Test!
++ grep -IiRn --exclude-dir=node_modules --exclude-dir=vendor --exclude-dir=public --exclude-dir=lib --exclude-dir=contrib '--include=*.module' '--include=*.inc' '--include=*.install' '--include=*.php' '--include=*.js' -P '^\s*(?!\/\/)\s*(dpm\(|dsm\(|console.log\()' /company/projects/company/www/sites/all/modules/custom/
+ ONE='/company/projects/company/www/sites/all/modules/custom/some_module/some_module.report.inc:594: dsm('\''test'\'');
/company/projects/company/www/sites/all/modules/custom/goals_app/goals_app.module:170: console.log(e.stack);
/company/projects/company/www/sites/all/modules/custom/company_usage_reports/js/script.js:300: console.log('\''fetch success'\'');
/company/projects/company/www/sites/all/modules/custom/another_module/js/another_module_change_workgroup.js:19: console.log('\''wtf?'\'');
/company/projects/company/www/sites/all/modules/custom/another_module/js/another_module_reorder_table.js:33: console.log(resp);
/company/projects/company/www/sites/all/modules/custom/another_module/js/another_module_reorder_table.js:39: console.log(ui.placeholder);
/company/projects/company/www/sites/all/modules/custom/another_module/js/another_module_goal_form.js:4: console.log($( ".required" ));
/company/projects/company/www/sites/all/modules/custom/another_module/js/another_module_reorder.js:40: console.log(resp);
/company/projects/company/www/sites/all/modules/custom/company_goals/js/views/goal-list.js:87: console.log(data);'
++ grep -IiRn --exclude-dir=node_modules --exclude-dir=vendor --exclude-dir=public --exclude-dir=lib --exclude-dir=contrib '--include=*.{coffee}' -P '^\s*(?!\#)\s*(dpm\(|dsm\(|console.log)' /company/projects/company/www/sites/all/modules/custom/
+ TWO=
+ echo /company/projects/company/www/sites/all/modules/custom/some_module/some_module.report.inc:594: 'dsm('\''test'\'');' /company/projects/company/www/sites/all/modules/custom/goals_app/goals_app.module:170: 'console.log(e.stack);' /company/projects/company/www/sites/all/modules/custom/company_usage_reports/js/script.js:300: 'console.log('\''fetch' 'success'\'');' /company/projects/company/www/sites/all/modules/custom/another_module/js/another_module_change_workgroup.js:19: 'console.log('\''wtf?'\'');' /company/projects/company/www/sites/all/modules/custom/another_module/js/another_module_reorder_table.js:33: 'console.log(resp);' /company/projects/company/www/sites/all/modules/custom/another_module/js/another_module_reorder_table.js:39: 'console.log(ui.placeholder);' /company/projects/company/www/sites/all/modules/custom/another_module/js/another_module_goal_form.js:4: 'console.log($(' '".required"' '));' /company/projects/company/www/sites/all/modules/custom/another_module/js/another_module_reorder.js:40: 'console.log(resp);' /company/projects/company/www/sites/all/modules/custom/company_goals/js/views/goal-list.js:87: 'console.log(data);'
/company/projects/company/www/sites/all/modules/custom/some_module/some_module.report.inc:594: dsm('test'); /company/projects/company/www/sites/all/modules/custom/goals_app/goals_app.module:170: console.log(e.stack); /company/projects/company/www/sites/all/modules/custom/company_usage_reports/js/script.js:300: console.log('fetch success'); /company/projects/company/www/sites/all/modules/custom/another_module/js/another_module_change_workgroup.js:19: console.log('wtf?'); /company/projects/company/www/sites/all/modules/custom/another_module/js/another_module_reorder_table.js:33: console.log(resp); /company/projects/company/www/sites/all/modules/custom/another_module/js/another_module_reorder_table.js:39: console.log(ui.placeholder); /company/projects/company/www/sites/all/modules/custom/another_module/js/another_module_goal_form.js:4: console.log($( ".required" )); /company/projects/company/www/sites/all/modules/custom/another_module/js/another_module_reorder.js:40: console.log(resp); /company/projects/company/www/sites/all/modules/custom/company_goals/js/views/goal-list.js:87: console.log(data);
+ echo ''
... but running it without the -x flag STILL doesn't work.
Edit two:
In case anyone is wondering, my env is as follows...
ubuntu#ip-12-34-56-78:~$ uname -a
Linux ip-12-34-56-78 3.2.0-31-virtual #50-Ubuntu SMP Fri Sep 7 16:36:36 UTC 2012 x86_64 x86_64 x86_64 GNU/Linux
ubuntu#ip-12-34-56-78:~$ whereis sh && whereis bash
sh: /bin/sh /bin/sh.distrib /usr/share/man/man1/sh.1.gz
bash: /bin/bash /etc/bash.bashrc /usr/share/man/man1/bash.1.gz
I can't say for sure until you post the actual script you're running, but in your current code snippet have
#!/bin/sh
Depending on your OS, this may be a link to /bin/bash, for example, or it may be the actual Bourne shell, which does not support brace expansion (e.g. {a, b, c}). Even if /bin/sh does point to /bin/bash on your machine, you should only use portable constructs if your shebang is #!/bin/sh (i.e. say what you mean). If you want to use brace expansion in your script, change the shebang to #!/bin/bash.
If you put
set -x
at the top of your script, it will print detailed information that can help with debugging. You can also do this by invoking the shell directly instead of modifying your script, for example
sh -x /path/to/script
or
bash -x /path/to/script
EDIT: On Ubuntu, /bin/sh is dash, the Debian Almquist shell. Like the Bourne shell, dash is fairly restrictive, and does not support brace expansion. See this page for a discussion of portability issues and dash.
How to pass a regular expression as a parameter to a shell script?
I need to write a shell script, which will take parameters and give them to unix commands. And I'd like to use regular expressions there. Is this possible at all?
Or reformulation - how to write the script equivalent to "cp" command, using only this command?
I'm trying to make a file "mycp"
#!/bin/bash -fx
cp $2 $1
and call it by
mycp myDir "*sh"
and want it to do the same as "cp *sh myDir".
But resulting bash interpretation is:
+ cp '*sh' myDir
cp: *sh: No such file or directory
Revised question
I'm trying to make a file "mycp"
#!/bin/bash -fx
cp $2 $1
and call it by
mycp myDir "*sh"
In that case, you still need eval, but you'd write:
#!/bin/bash -x
eval cp "$2" "$1"
You're running into problems because you have specified the -f option. man bash says (in part):
After word splitting, unless the -f option has been set, bash scans each word for the characters *, ?, and [.
Remove the f from the 'shebang' (first) line of the script.
Original question
Given that you want mycp "*sh*" aa to do shell expansion on the argument, you'll probably end up using eval in your script:
eval cp "$#"
However, the use of eval is dangerous; it can lead to unexpected side-effects. The use of "$#" is important; it preserves the number of arguments and spaces in them. Unfortunately, using eval then undoes that, but we can't have everything — or not easily.
For quite a long time (say 1987* to 1999), I used this script as a cover for cp:
: "#(#)$Id: cp.sh,v 1.3 1997/06/02 21:45:00 johnl Exp $"
#
# Alternative copy command
case $# in
0) /bin/cp ;;
1) /bin/cp $1 . ;;
2) /bin/cp "$#" ;;
*) if [ -d `la "$#"` ]
then /bin/cp "$#"
else /bin/cp "$#" .
fi;;
esac
It uses a very simple C program called la (for 'last argument') to get the last argument and checks whether the given last argument is a directory. More than 99% of the time, if I typed (by accident) 'cp /some/where/sh' rather than cp /some/where/*sh* ., the second was what I meant, and the script fixed things. I haven't used it for quite some time; it may have been in the last millennium, but was probably sometime earlier in this one that I gave up using it.
* Although the version string says '1997', the code is identical to the 1987 version. Version 1.1 and 1.2 were under SCCS and used different SCCS ID strings; the conversion to RCS made them identical. Version 1.3 reinstated the #(#) identifier string used by the SCCS what command to the RCS version handling. So, the script is ancient — 1987, really.
Try this: eval cp $1 $2
Bash reference manual: eval
If all you want to do is specify the directory first, look at the -t option to GNU cp:
alias mycp='cp -t'
mycp mydir *.sh
Otherwise:
mycp() {
local dir=$1
shift
cp "$#" "$dir"
}
mycp mydir *.sh
Either way, let the shell expand the wildcards and avoid the use of eval
(note, *.sh is not a regular expression, it's a shell "pattern", often referred to as a "glob pattern")