Bad resource requirement syntax Error - memory

I am trying to use the memory resource allocation command available in LSF.
A normal format of the command is :
bsub -R "rusage [mem=1000]" sleep 100s
When I launch this command directly from terminal,it works.
When i lsunch this command from a script, it fails.
Here is my script:
#! /bin/csh -f
set cktsim_memory = $1
set tmp = "|rusage [mem = $cktsim_memory]|" #method2
set tmp = `echo $tmp | sed 's/ =/=/g'` #method2
set tmp = `echo $tmp | sed 's/|/"/g' `
set bsub_option = ""
set bsub_option = ( "$bsub_option" "-R" "$tmp") #method2
set cmd = "bsub $bsub_option sleep 100s"
echo $cmd
$cmd
Its run output is:
>./cktsim_memory_test 100
bsub -R "rusage [mem= 100]" sleep 100s
Bad resource requirement syntax. Job not submitted.
>bsub -R "rusage [mem= 100]" sleep 100s
Job <99775> is submitted to default queue <medium>.
As you can see in the terminal output above- when the bsub command launched from script, it fails, when the same command run from terminal it is ok...
Please help me debug the issue.

set cktsim_memory = $1
set temp = "'rusage [mem = $cktsim_memory]'" #method2
set temp = `echo $temp | sed 's/ =/=/g'` #method2
set bsub_option = ( "$bsub_option" "-R" "$temp")

Related

MediaInfo output to stdout

I have used MediaInfo before to extract information in a shell script in CygWin.
#!/bin/bash
IFS=$'\n'; for file in $(ls *.mp3 /.mp3 ); do count="C:/Program Files/MediaInfo/MediaInfo.exe" $file | grep "Bit rate mode" | grep "Variable" | wc -l; if [ $count -gt 0 ]; then echo $file VBR; fi done
For some reason, it no longer outputs to stdout. It displays the data in a window. Is there some command line flag tp force stdout?
You use the Graphical Interface (GUI) version of MediaInfo, you need to use the Command Line Interface (CLI) version of MediaInfo.
See the different download options in the MediaInfo Windows download page.

How to have a derivation not clash with derived environment in Nix?

I get the following collision error when attempting to build an environment that, as far as I can see, shouldn't have a collision (in this case, scala-env depends on ideaLocal, so it shouldn't conflict with it):
...
idea-IU-172.4155.36/bin/libyjpagent-linux.so
idea-IU-172.4155.36/bin/libyjpagent-linux64.so
idea-IU-172.4155.36/help/ideahelp.jar
idea-IU-172.4155.36/lib/libpty/linux/x86/libpty.so
idea-IU-172.4155.36/lib/libpty/linux/x86_64/libpty.so
idea-IU-172.4155.36/bin/format.sh
idea-IU-172.4155.36/bin/fsnotifier
idea-IU-172.4155.36/bin/fsnotifier-arm
idea-IU-172.4155.36/bin/fsnotifier64
idea-IU-172.4155.36/bin/idea.sh
idea-IU-172.4155.36/bin/inspect.sh
idea-IU-172.4155.36/bin/printenv.py
idea-IU-172.4155.36/bin/restart.py
building path(s) ‘/nix/store/29g92lnpi0kywy9x7vcgl9yivwa2blm6-scala-env’
created 696 symlinks in user environment
building path(s) ‘/nix/store/qrnbff8nhpmxlzkmv508aymz5razbhgf-user-environment’
Wide character in die at /nix/store/64jc9gd2rkbgdb4yjx3nrgc91bpjj5ky-buildenv.pl line 79.
collision between ‘/nix/store/75sz9nklqmrmzxvf0faxmf6zamgaznfv-idea-local/bin/idea’ and ‘/nix/store/29g92lnpi0kywy9x7vcgl9yivwa2blm6-scala-env/bin/idea’; use ‘nix-env --set-flag priority NUMBER PKGNAME’ to change the priority of one of the conflicting packages
builder for ‘/nix/store/8hp5kdicxy9i02fa07vx85p1gvh4i1bq-user-environment.drv’ failed with exit code 255
error: build of ‘/nix/store/8hp5kdicxy9i02fa07vx85p1gvh4i1bq-user-environment.drv’ failed
Here is the nix expression (most of which can be ignored, but it isn't too long so I'll paste the whole thing):
with import <nixpkgs> { };
let
ideaLocal = stdenv.mkDerivation {
name = "idea-local";
buildInputs = [ ];
builder = builtins.toFile "builder.sh" ''
source $stdenv/setup
mkdir -p $out/bin
tar zxvf $src -C $out/
ln -sf $out/idea-IU* $out/idea
ln -sf $out/idea/bin/idea.sh $out/bin/idea
'';
shellHook = ''
IDEA_JDK=/usr/lib/jvm/zulu-8-amd64
'';
src = fetchurl {
url = https://download.jetbrains.com/idea/ideaIU-2017.2.4-no-jdk.tar.gz;
sha256 = "15a4799ffde294d0f2fce0b735bbfe370e3d0327380a0efc45905241729898e3";
};
priority = 5;
};
in
buildEnv {
name = "scala-env";
paths = [
ammonite
boehmgc
clang
dbus # needed non-explicitly by vscode
emacs
git
# idea.idea-ultimate # disabled temporarily
ideaLocal
less
libunwind
openjdk
openssh
re2
rsync
sbt
stdenv
syncthing # for syncrhonizing data between containers
tmux
unzip
vscode
zlib
];
# builder = builtins.toFile "builder.sh" ''
# source $stdenv/setup
# mkdir -p $out
# echo "" > $out/Done
# echo "Done setting up Scala environment."
# '';
buildInputs = [ makeWrapper ];
# TODO: better filter, use ammonite script?:
postBuild = ''
for f in $(ls -d $out/bin/* | grep "idea"); do
sed -i '/IDEA_JDK/d' $f
wrapProgram $f \
--set IDEA_JDK "/usr/lib/jvm/zulu-8-amd64" \
--set CLANG_PATH "${clang}/bin/clang" \
--set CLANCPP_PATH "${clang}/bin/clang++"
done
'';
}
Edit:
(DevContainer)which idea
/home/brandon/.nix-profile/bin/idea
(DevContainer)ls -last /home/brandon/.nix-profile/bin/idea
4 lrwxrwxrwx 1 brandon brandon 63 Jan 1 1970 /home/brandon/.nix-profile/bin/idea -> /nix/store/75sz9nklqmrmzxvf0faxmf6zamgaznfv-idea-local/bin/idea
So it looks like ideaLocal is being imported as an environment - what's the right way to just have it installed as a package that is a dependency of scalaEnv?
Apparently the solution was to specify the profile, which I think of as the name of the environment, so that both environments aren't installed simultaneously:
nix-env -if scala-default.nix -p scala-env

Erlang shell - no input for commands

My os: arch linux. I recently installed erlang (Erlang (BEAM) emulator version 9.0.1).
When I type "erl" command I expect the erlang shell to start invoking the commands I type (for the simplest example: 2+3. should return 5)
However, after I run "erl" nothing shows up on screen. I can type anything I want, nothing is executed. Images with example are attached.
What I expect.jpg
What I got.jpg
Now I only started to learn erlang, and this is confusing. Don't know if it is some repository bug, or erlang normal behavior?
UPD: I got some custom configuration in .bashrc file:
# setup color variables
color_is_on=
color_red=
color_green=
color_yellow=
color_blue=
color_white=
color_gray=
color_bg_red=
color_off=
color_user=
if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then
color_is_on=true
color_black="\[$(/usr/bin/tput setaf 0)\]"
color_red="\[$(/usr/bin/tput setaf 1)\]"
color_green="\[$(/usr/bin/tput setaf 2)\]"
color_yellow="\[$(/usr/bin/tput setaf 3)\]"
color_blue="\[$(/usr/bin/tput setaf 6)\]"
color_white="\[$(/usr/bin/tput setaf 7)\]"
color_gray="\[$(/usr/bin/tput setaf 8)\]"
color_off="\[$(/usr/bin/tput sgr0)\]"
color_error="$(/usr/bin/tput setab 1)$(/usr/bin/tput setaf 7)"
color_error_off="$(/usr/bin/tput sgr0)"
# set user color
case `id -u` in
0) color_user=$color_red ;;
*) color_user=$color_green ;;
esac
fi
function prompt_command {
# get cursor position and add new line if we're not in first column
exec < /dev/tty
local OLDSTTY=$(stty -g)
stty raw -echo min 0
echo -en "\033[6n" > /dev/tty && read -sdR CURPOS
stty $OLDSTTY
[[ ${CURPOS##*;} -gt 1 ]] && echo "${color_error}↵${color_error_off}"
# build b/w prompt for git and vertial env
[[ ! -z $GIT_BRANCH ]] && PS1_GIT=" (git: ${GIT_BRANCH})"
[[ ! -z $VIRTUAL_ENV ]] && PS1_VENV=" (venv: ${VIRTUAL_ENV#$WORKON_HOME})"
# calculate fillsize
local fillsize=$(($COLUMNS-$(printf "${USER}#${HOSTNAME}:${PWD}:${PWDNAME}${PS1_GIT}${PS1_VENV} " | wc -c | tr -d " ")))
local FILL=$color_white
while [ $fillsize -gt 0 ]; do FILL="${FILL}─"; fillsize=$(($fillsize-1)); done
FILL="${FILL}${color_off}"
# set new color prompt
PS1="${color_user}${USER}${color_off}#${color_yellow}${HOSTNAME}${color_off}:${color_white}${PWD}:${PWDNAME}${color_off}${PS1_GIT}${PS1_VENV} ${FILL}\n➜ "
}
PROMPT_COMMAND=prompt_command
After removing this configuration, erl started to work normally.

csh - suppress STDERR when using backticks

I'd like to write a bit of code that looks like this:
while ( `ls -1 ${JOB_PREFIX}_${job_counter}_*.out | wc -l` > 0 )
echo "Do something here."
end
But every time there is no ls -1 ${JOB_PREFIX}_${job_counter}*.csh it gives an annoying ls: No match.
Is it possible to suppress this error message but still pipe STDOUT to wc ? I went through the existing questions on this but most of the answers are either not working on csh or tries to combine STDOUT and STDERR with |& which I do not want.
The cleanest way would have been to mute the ls itself, but it is not possible.
You can suppress your entire script, meaning:
If your loops is in a file called myscript.cs and you call your file with some args myscript.cs -arg1 blabla -arg2 bla, add >& to your shell command to redirect stderr to wherever you want. e.g.
myscript.cs -arg1 blabla -arg2 bla >& /dev/null
It's not answering your answer directly, but it should solve your problem.
Edit
Since the comment added that the script should be redirected to another script, you can split your line to two lines:
if `ls -1 ${JOB_PREFIX}_${job_counter}_*.out >& /dev/null` then
while < your while here >
end
endif
csh and tcsh cannot redirect stderr by itself, one of many reasons you should not use it for scripting.
If you're okay with spawning another shell, you can change JOB_COUNTER into an environment variable and do:
while ( `sh -c '2>/dev/null ls -1 ${JOB_PREFIX}_${JOB_COUNTER}_*.out | wc -l'` > 0 )
echo "Do something here."
end
If you want to use a test as a condition in a while loop instead of an expression, you have to get creative.
#!/bin/tcsh -f
set i = 4
while ( 1 )
if ( $i <= 0 ) break
echo hi
# i = ($i - 1)
end
In your case, this might look something like: I changed the wc -l to a grep -q . so that we can use the exit status instead of the result printed to stderr.
#!/bin/tcsh -f
set dir_exit_status = 0
while ( $dir_exit_status = 0 )
( ls -1 ${JOB_PREFIX}_${job_counter}_*.out | grep -q '.') >& /dev/null
set dir_exit_status = $status
end

Finding bundle identifier in XCode project using shell script

A Bundle identifier in Info.plist of an Xcode project could have various forms, for e.g.
com.company.$(PRODUCT_NAME:rfc1034identifier)
$(PRODUCT_BUNDLE_IDENTIFIER)
Someone could design their own product bundle identifier for debug, release etc types of build and write a variable against Bundle identifier, e.g. com.company.$(PRODUCT_NAME:rfc1034identifier).$(someRandomVariable)
I want to write a shell script that just reads the bundle identifier properly.
However, if you only know shell script - I know, how to figure out values of variables in $(), but want a shell script that should give me all such variables in the string and then I will have code to figure out their values, post which I will create string back with the variables replaced with values.
function getBundleIdentifier
{
cfBundleIdentifier=${PRODUCT_BUNDLE_IDENTIFIER}
if [ ${#cfBundleIdentifier} -lt 1 ]; then
SOURCE="rfc1034identifier"
cfBundleIdentifier=$(/usr/libexec/PlistBuddy -c "Print :CFBundleIdentifier" "${PROJECT_DIR}/${INFOPLIST_FILE}")
if echo "$cfBundleIdentifier" | grep -q "$SOURCE"; then
echo `eval echo $cfBundleIdentifier``eval echo ${PRODUCT_NAME:rfc1034identifier}`
else
echo `eval echo $cfBundleIdentifier`
fi
else
echo $cfBundleIdentifier
fi
}
This is what I have written, but it does not cover all the cases.
It's very easy, just run this command:
BUNDLE_ID=`xcodebuild -showBuildSettings | grep PRODUCT_BUNDLE_IDENTIFIER`
echo $BUNDLE_ID
you can use this
xcodebuild -project Myproject.xcodeproj \-showBuildSettings | grep PRODUCT_BUNDLE_IDENTIFIER | awk -F ' = ' '{print $2}'
or just consolidated the non-xcode portion into :
xcodebuild……. |
{m,g}awk '$!NF = $(NF=2*/PRODUCT_BUNDLE_IDENTIFIER/)' FS=' = '
To get get the bundle identifier in a shell script, I found this to be the simplest way:
xcodebuild -showBuildSettings | awk -F ' = ' '/PRODUCT_BUNDLE_IDENTIFIER/ { print $2 }'
If your script works currently in a different path, use -project option:
xcodebuild -project Myproject.xcodeproj -showBuildSettings | awk -F ' = ' '/PRODUCT_BUNDLE_IDENTIFIER/ { print $2 }'

Resources