w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Bash script to wait for gnome-terminal to finish before continuing script, only works for first instance of script
#!/bin/bash date bash -c "sleep 7" & bash -c "sleep 5" & wait date As you can see while running this script, both sleep commands will run in parallel, but main thread stalls, while they are running. Sat. Jule 27 01:11:49 2013 Sat. Jule 27 01:11:56 2013 Replace sleep 7 with expect launchneuron.exp and sleep 5 with expect launchmpj.exp and add your plot commands after calling "wait": echo "Simulation Complete" ...(your code to plot results)

Categories : Bash

Why does the child of an eval call from bash get orphaned once the parent bash script dies?
This is normal and expected. You sent a signal (presumably SIGTERM) to parent-script and it died, but no signal was sent to another-script. It keeps on running. This is different than what happens when the parent-script job is running interactively on a terminal and you type ^C (or ^Z). In that case, a SIGINT signal is automatically sent to the whole foreground process group. Since another-script is un the same process group as parent-script (by default), they both get the signal and they both die. If you want another-script to die automatically when its parent dies in any other context than when it's a job running in a terminal with job control, you have a few options. parent-script can trap the SIGTERM signal. In the signal handler, it kills its child, and then exits itself. This, o

Categories : Linux

BASH: how to define an array as environment variable before calling a bash script
Incredibility weird.... I have never seen that before. It looks like the array is not passed to the subshell. One way around this is to source the script instead of executing it: declare -a MYARR=( 1 2 ); . ./myscript.sh

Categories : Arrays

Pass a full bash script line to another bash function to execute
optout is a command like any other, and so must be preceded by any local modifications to the environment. The command that optout runs will inherit that environment. CC=${BUILD_TOOL_CC} optout ./configure ${ZLIB_CONFIGURE_OPT} --prefix=${CURR_DIR}/${INSTALL_DIR} By the way, this is just one of the problems you are likely to encounter with your optout function. You cannot run arbitrary command lines in that fashion, only a simple command followed by zero or more arguments (and I would expect there are some exceptions to even that restricted set, as well).

Categories : Linux

escaping bash 'test' keywork in a bash script
test is a Bash builtin command, not a keyword or reserved word. This means Bash will only interpret it if it is the first token in a command, like test blah In python manage.py test Bash will just pass it as a parameter to python (that is, it will execute python with two parameters, manage.py and test); you don't need to escape it. In general, Bash doesn't have reserved words in the sense of C-like languages. The only things you need to escape are whitespace (which Bash uses to separate params), and certain symbols including $(&|; which Bash uses for its variables and command separators.

Categories : Bash

Can One Bash Script Launch Multiple Other Bash Scripts?
Run them in the background, just like you would in an interactive shell. command1 & command2 & command3 & wait # Wait for all background commands to finish The commands can be just about anything, not just other bash scripts.

Categories : Linux

'Globalize' Bash functions inside of a bash script
You can use this command in your startup.bash: source lib.bash the source command runs the file in the current shell environment, unlike using bash lib.bash (or . lib.bash) which creates a new, separate environment for that script (and only that script) and is why the function is not carried over. (source)

Categories : Linux

how to create a script from a perl script which will use bash features to copy a directory structure
First, I see that you want to make a copy-script - because if you only need to copy files, you can use: system("cp -r /sourcepath /targetpath"); Second, if you need to copy subfolders, you can use -r switch, can't you?

Categories : Perl

bash shell script error works on command line, not in script
Variables are supposed to contain data, and bash treats them as data. This means that shell meta-characters like quotes are also treated as data. See this article for a complete discussion on the topic. The short answer is to use arrays instead: ASCIIDOC_OPTS=( --asciidoc-opts='-a lang=en -v -b docbook -d book' ) DBLATEX_OPTS=( --dblatex-opts='-V -T db2latex' ) cmd=(a2x -v -f pdf -L "${ASCIIDOC_OPTS[@]}" "${DBLATEX_OPTS[@]}" "$1".asciidoc) # Print command in pastable format: printf '%q ' "${cmd[@]}" printf ' ' # Execute it "${cmd[@]}" Make sure not to use eval: eval "$cmd" #noooo This will appear to work with your code as you posted it, but has caveats and security problems.

Categories : Bash

Create bash script with menu of choices that come from the output of another script
This might work for you: #!/bin/bash # Set the prompt for the select command PS3="Type a number or 'q' to quit: " # Create a list of customer names and numbers (fill gaps with underscores) keys=$(/usr/local/bin/info $1 | sed 's/ /_/g') # Show a menu and ask for input. select key in $keys; do if [ -n "$key" ]; then /usr/local/bin/extrainfo $(sed 's/.*_11111/11111/' <<<"$key") fi break done

Categories : Bash

dump files from bash script in different directory from where python script ran it
You should change directory within the same command: cmd = "/path/to/executable/executable" outputdir = "/path/to/output/" subprocess.call("cd {} && {}".format(outputdir, cmd), shell=True)

Categories : Python

How to pass output from remote script to local script in bash
On your local script, in your ssh line, you can redirect some of the outputs to a file with tee: ssh ... | tee -a output.log If you want to filter which one goes to the output.log file, you can use process substitution: ssh .... | tee >(grep "Some things you want to filter." >> output.log) Besides grep you can use other commands as well like awk.

Categories : Bash

how can i pass a variable from my php script and send it to my bash script
Try using shell_exec in your php script to execute your shell script and pass your variable, like so: $cmd="perl -pi -e 's/ : /:/g' /opt/lampp/htdocs/" . escapeshellarg($variable); $r=shell_exec($cmd); escapeshellarg is used to escape any potentially dangerous characters in $variable, to prevent a command line injection attack.

Categories : PHP

Bash: increment a variable from a script every time when I run that script
A script is run in a subshell, which means its variables are forgotten once the script ends and are not propagated to the parent shell which called it. To run a command list in the current shell, you could either source the script, or write a function. In such a script, plain (( n++ )) would work - but only when called from the same shell. If the script should work from different shells, or even after switching the machine off and on again, saving the value in a file is the simplest and best option. It might be easier, though, to store the variable value in a different file, not the script itself: [[ -f saved_value ]] || echo 0 > saved_value n=$(< saved_value) echo $(( n + 1 )) > saved_value Changing the script when it runs might have strange consequences, especially when yo

Categories : Bash

BASH: How To Create a Setup Script to build another script
This answer, a work in progress; Your code while [ "$index" -lt "$elements" ] do ????????? echo "Your Directory is ~/$root/${gitdir[0]}/${gitdir[1]}/${colours[2]}" done becomes fullPath="/${root}/" index=1 while [ "$index" -lt "$elements" ] ; do # append values from $gitdir until you are done fullPath="${fullPath}/${gitdir[$index]}" (( index++ )) done # not sure how colours got introduced to this but same idea fullPath="${fullPath}/${colours[2]}" echo "Your Directory is ~/${fullPath}" use of (( index++ )) implies using a version of bash, ksh, zsh (maybe others) that support arithmetic evaluations. That said, it's not clear what your input into gitdir[@] will be and why you need to "count" the levels. Why not just accept user input as arguments, document the o

Categories : Arrays

Run PBS script and post-process output within bash script
I don't believe PBSPro supports this, but TORQUE (another PBS derivative) has a -x option that you might be interested in. You can submit a job like this: qsub -I -x <executable> This would run your job interactively and run the executable, with all of the output directed to your terminal, and the job will execute as soon as that executable terminates. You could then begin post-processing at that point. PBSPro may have similar functionality, but what I've described here is for TORQUE.

Categories : Bash

Canon SDK example for image processing
I know it's been a while since this question has been asked, still it might help someone. To process canon raw files with the SDK you have to do this: uint err; //Create input stream IntPtr inStream; err = EDSDK.EdsCreateFileStream("Test.CR2", EDSDK.EdsFileCreateDisposition.OpenExisting, EDSDK.EdsAccess.Read, out inStream); //Create image reference IntPtr imgRef; err = EDSDK.EdsCreateImageRef(inStream, out imgRef); //Set properties err = EDSDK.EdsSetPropertyData(imgRef, EDSDK.PropID_WhiteBalance, 0, 4, EDSDK.WhiteBalance_Cloudy); //TODO: set any imageRef compatible property you need here. //Create output stream IntPtr outStream; err = EDSDK.EdsCreateFileStream("TestOut.jpg", EDSDK.EdsFileCreateDisposition.CreateAlways, EDSDK.EdsAccess.Write, out outStream); //Get image info EDSDK.EdsIma

Categories : C#

How to reconstruct Bayer to RGB from Canon RAW data?
The first step should be setting black and saturation point because you need to apply white balance looking after saturated pixels in order to avoid magenta highlights: And before demosaicing, apply white balacing. See here (http://www.guillermoluijk.com/tutorial/dcraw/index_en.htm) how applying white balance before demosaicing introduce artifacts.

Categories : Image

How to set/get properties of pictures taken with canon EDSDK 2.12?
I can think of several solutions. Windows has an API (FindFirstChangeNotification and FindNextChangeNotificaton) that allows you to detect changes in a directory. Just use the "drive" that the camera is represented as on the computer as the "here is where I want to see notifications from". I have never programmed on a Mac, but it appears to have something called FSEvents that would do something similar. You can rely on the camera to store the image under a consistent name. When your application starts, find the last file in the drive that is the camera's storage. Then just number it up "IMG_0991.JPG" [replace "JPG" with "CR2" if you use RAW mode] will become "IMG_0992.JPG". This works every time, all the time. It will eventually wrap around to "IMG_0001.JPG" when you have taken 10000 im

Categories : C++

No callback from Event Handler Canon SDK 2.12
Firstly, the EDSDK doesn't really work in 64-bit mode, so use 32-bit. 64-bit is experimental at best. Secondly, the EDSDK uses the legacy COM STA threading model, which requires that you have a Windows message loop running in your main thread. If you don't have a message loop, you won't get any callbacks.

Categories : C++

Canon SDK - Downloading image to host PC
When you call EdsCreateFileStream, just prepend the fully qualified path where you want the file to go. dirItemInfo.szFileName is the file name only, so the image should appear in your working directory if you don't include a path.

Categories : C++

How to source a csh script from inside a bash script
WARNING : don't put the following script in your .bashrc, it will reload bash and so reload .bashrc again and again (stopable with C-c anyway) Use preferable this script in your kit/CDS stuff startup script. (cadence presumably) WARNING 2 : if anything in your file2source fails, the whole 'trick' stops. Call this script : cshWrapper.csh #! /bin/csh # to launch using # exec cshWrapper.csh file2source.sh source $1 exec $SHELL -i and launch it using exec ./cshWrapper.csh file2source.sh it will : launch csh, source your file and came back to the same parrent bash shell Example : $> ps PID TTY TIME CMD 7065 pts/0 00:00:02 bash $>exec ./cshWrapper.csh toggle.csh file sourced 1 $> echo $$ 7065 where in my case i use the file toggle.csh #! /bin/csh # source

Categories : Misc

need to call a php script from bash script through eval
There are still some parts of your script that I don't understand, or not sure it does really work, but about your question, I think your callback could only work if you place it on a function like: function mycallback { php /srv/www/scripts/mage/install-invoke-app.php } And call your install_repolist function as install_repolist $gitRepos 0 mycallback That should make your php command call with the file argument work but there is one thing: I don't think values of gitRepos could actually be passed like that. Most parts of your code has variables that actually needed to be quoted around double quotes "". One problem with it is that your php command would just end up in the final place where it is executed as one single argument php and no longer with the file due to word splitti

Categories : PHP

mac os and canon edsdk [take picture error 36103]
It seems hex(36103) => '0x8d07', resolves to EDSDK label EDS_ERR_TAKE_PICTURE_CARD_NG. Reported issues around this include the fix that you describe, must be a Lazarus specific issue.

Categories : Osx

Executing bash script from php script
I would have a directory somewhere called scripts under the WWW folder so that it's not reachable from the web but is reachable by PHP. e.g. /var/www/scripts/testscript Make sure the user/group for your testscript is the same as your webfiles. For instance if your client.php is owned by apache:apache, change the bash script to the same user/group using chown. You can find out what your client.php and web files are owned by doing ls -al. Then run <?php $message=shell_exec("/var/www/scripts/testscript 2>&1"); print_r($message); ?> EDIT: If you really want to run a file as root from a webserver you can try this binary wrapper below. Check out this solution for the same thing you want to do. Execute root commands via PHP

Categories : PHP

Bash: Why does parent script not terminate on SIGINT when child script traps SIGINT?
New answer: This question is far more interesting than I originally suspected. The answer is essentially given here: What happens to a SIGINT (^C) when sent to a perl script containing children? Here's the relevant tidbit. I realize you're not using Perl, but I assume Bash is using C's convention. Perl’s builtin system function works just like the C system(3) function from the standard C library as far as signals are concerned. If you are using Perl’s version of system() or pipe open or backticks, then the parent — the one calling system rather than the one called by it — will IGNORE any SIGINT and SIGQUIT while the children are running. This explanation is the best I've seen about the various choices that can be made. It also says that Bash does the WCE appr

Categories : Linux

Problems converting spool files generated by Canon iR-ADV C5235/5240 PCL6 printer driver
Odds are you have something like an EMF or similar file here. Ensure that the server queue (if you are printing to a network printer) is set to 'Render on client computer'. I would also look to set the Print Processor to Winprint RAW. It could also be that the Canon PCL printer isn't as generic as you'd like. You can always try a different PCL driver and see if your converter and the Canon device support the format. To confirm that the issue isn't the Windows Spooler you can set the port to FILE and/or use a capture utility to write out what the printer would actually receive post all processing. If that works but the SPL doesn't then you have a Windows Spooler and/or processor issue. vclpdcap Capture utility

Categories : Windows

bash script to write content into file. File content requires bash variables. How to do that?
You're actually deliberately turning off parameter subsitution by enclosing 'ENDFILECONTENT' in quotes. See this excerpt from example 19-7 of the advanced Bash scripting guide on Heredocs, slightly reformatted: # No parameter substitution when the "limit string" is quoted or escaped. # Either of the following at the head of the here document would have # the same effect. # # cat <<"Endofmessage" # cat <<Endofmessage Remove the single quotes around 'ENDFILECONTENT' and BASH will replace the variables as expected.

Categories : Bash

Bash script in Ant
The difference between you command line and the Ant script is the working directory. One is the current one, the other is the asterisk one. Probably you just want to do: <exec dir="${basedir}" executable="${basedir}/configure"> <arg line="--prefix=/home/some/path"/> </exec>

Categories : Bash

What is EOF!! in the bash script?
The bash manual lists this under "Event designators", saying: !! Refer to the previous command. This is a synonym for !-1`. I simply searched for "bash manual double exclamation".

Categories : Linux

how to run a bash script from php?
Place your command inside a subshell and tee its output: #!/bin/bash # test ( ssh root@192.168.526.33 "server -rx reload" ) 2>&1 | tee -a /some/where.log echo "success" Through that you'll see all the messages including possible messages from bash.

Categories : PHP

format of bash script
In bash, if conditions are wrapped between [] not (). There should always be space between condition and square brackets. And you need then in if-then-else-fi syntax. if [ -f file.txt ]; then echo "yes" else echo "no" fi

Categories : Linux

Linux bash script -
[grep -n -v '[0-9][0-9][0-9][0-9]' $line |wc -l==0] problem 1: [(space).....(space)] you need those spaces problem 2: there is no [ foo==bar ] you can do something like [ $(echo "0") = "0" ] or [[ $(echo "0") == 0 ]] here the $(echo "0") is an example, you should fill with your commands.

Categories : Linux

Need to run bash script in aws datapipeline
One way to achieve this would be to have a wrapper shell script, something like below which invokes "sample.rb". $INPUT1_STAGING_DIR/sample.rb >> $OUTPUT1_STAGING_DIR/output.txt Now instead of specifying "command", you could specify "Script Uri" pointing to the shell script in S3. You should also enable "Stage = true", and make the Input datanode point to s3 folder containing sample.rb script. More details on Staging can be found here You will need to modify your sample.rb and have appropriate path like "$INPUT1_STAGING_DIR/text.txt" instead of giving "text.txt". Hope this helps.

Categories : Ruby

Script parameters in Bash
In bash $1 is the first argument passed to the script, $2 second and so on /usr/local/bin/abbyyocr9 -rl Swedish -if "$1" -of "$2" 2>&1 So you can use: ./your_script.sh some_source_file.png destination_file.txt Explanation on double quotes; consider three scripts: # foo.sh bash bar.sh $1 # cat foo2.sh bash bar.sh "$1" # bar.sh echo "1-$1" "2-$2" Now invoke: $ bash foo.sh "a b" 1-a 2-b $ bash foo2.sh "a b" 1-a b 2- When you invoke foo.sh "a b" then it invokes bar.sh a b (two arguments), and with foo2.sh "a b" it invokes bar.sh "a b" (1 argument). Always have in mind how parameters are passed and expaned in bash, it will save you a lot of headache.

Categories : Linux

run bash script after git clone
Let us say the bash script you intend to run is in a file by the name shellscript.sh and it is on your path: You can add the following bash function to your ~/.bashrc. git() { if [[ $1 == "clone" ]]; then command git "$@" && shellscript.sh; else command git "$@"; fi; } Note: You can add any command after &&.

Categories : GIT

Executing ksh script from bash
Yeah, you can: bash yourscript Of course it will throw some errors if there are language specific features. But the question did not specify if it should work correctly or not. From man bash: the first argument is assumed to be the name of a file containing shell commands. If bash is invoked in this fashion, $0 is set to the name of the file, and the positional parameters are set to the remaining arguments. Bash reads and executes commands from this file, then exits. Bash's exit status is the exit status of the last command executed in the script. If no commands are executed, the exit status is 0. An attempt is first made to open the file in the current directory, and, if no file is found, then the shell searches the directories in PATH for the script In fact, that's e

Categories : Bash

Is the following bash script correct?
if [[ "$line2" = "moon" ]]; then echo "hi" fi Always quote string variables while doing string operation. And [[ ]] is a better option. Read about it here and here

Categories : Bash

Bash script - If conditional with [ ]
Replace if [ $exam_pct < 40 ] with if (( exam_pct < 40 )) Take a look at the link given by Bill. Unix shell history is full of non-intuitive extensions. Depending on your case, Bash should be safe to use though. If you are interested in shell history take a look at http://www.in-ulm.de/~mascheck/bourne/

Categories : Bash

How to shorten this bash script
How about this: file_needed=$(find /some/other/location -maxdepth 1 -printf '%T@ %p ' | sort -nr | head -1 | cut -c '23-') cp "$file_needed" . yum -y install "$file_needed"

Categories : Bash



© Copyright 2017 w3hello.com Publishing Limited. All rights reserved.