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

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

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

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

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

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

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

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: 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

Converting a jRuby script into a Groovy script
I'm no Ruby guru, but AFAIK, Proc is similar to Groovy's Closure, so my guess it'd be something like: class ProcButtonHandler extends ButtonHook { Closure proc ProcButtonHandler(id, proc) { super(id) this.proc = proc } void handle(player, slot, parameter) { proc player, slot, parameter } }

Categories : Ruby

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

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

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

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

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

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

'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

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

PowerShell - script 1 calls script 2 - how to return value from script 2 to script 1
You could make use of ProcessStartInfo and Process which would allow you to read the StandardOutput. Here's an example of what you might do: $startInfo = New-Object System.Diagnostics.ProcessStartInfo $startInfo.FileName = "powershell.exe" $startInfo.Arguments = "C:scriptscript2.ps1" $startInfo.RedirectStandardOutput = $true $startInfo.UseShellExecute = $false $startInfo.CreateNoWindow = $false $startInfo.Username = "DOMAINUsername" $startInfo.Password = $password $process = New-Object System.Diagnostics.Process $process.StartInfo = $startInfo $process.Start() | Out-Null $standardOut = $process.StandardOutput.ReadToEnd() $process.WaitForExit() # $standardOut should contain the results of "C:scriptscript2.ps1" $standardOut

Categories : Powershell

Google Apps Script Spreadsheets - Assign script to image from a script
This would be a cool feature, but here is a possible workaround, it might even offer more functionality. You can build a UI using Google API. More detailes here. The UI allows you to create side bars/menus/etc. You could even create floating dialog windows. Using AbsolutePanel, you can even choose where the dialogue shows up.

Categories : Google Apps Script

unable to access variable declared in ksh script to csh script using shell script
The ksh script is not doing what you think it is doing when used by ksh; it sets $1 first to MyUser=root and then MyPassword=shroot. However, when you source it from your C shell script, because the syntax is compatible with C shell (checked with tcsh), you would set the two variables. If you sourced the script from a Bourne-shell derivative, the exit at the end of the ksh script would cause the shell to exit; it does not seem to cause the C shell to exit. So, what you've got is a weird hybrid. Normally, you stick to one language and use it exclusively. Where you need to use another shell, you can do so, but you simply run the script written for the other shell. You can communicate to the other script with environment variables. You don't normally try writing sourceable code that ca

Categories : Shell

Powershell start-process script calls a second script - how to make one script only
Windows does not allow a process to elevate while running. There are some tricks but in one way or another they will spawn a new process with the elevated rights. See here for more info. So the easiest way for PowerShell is still using one script to Start-Process the other script elevated.

Categories : Powershell

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

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

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

Run a script in the same shell(bash)
You can still do something like: cd (specific benchmark directory) specinvoke & pid=$(pgrep milc_base.gcc43-64bit) If there are several invocation of the milc_base.gcc43-64bit binary, you can still use pid=$(pgrep -n milc_base.gcc43-64bit) Which according to the man page: -n Select only the newest (most recently started) of the matching processes

Categories : Linux

unplug HDD via a bash script
How about this: Run diskutil list [disk] in a loop over the disk names For each disk, if it has a partition with “Microsoft” in the name, save the name of the disk to the variable disk_to_eject After the loop is done, if $disk_to_eject is not empty, eject that disk? The code would be: disk_to_eject= for disk in disk0 disk1; do if diskutil list "$disk" | grep -q Microsoft; then disk_to_eject="$disk" fi done if [ -n "$disk_to_eject" ]; then hdiutil eject "$disk_to_eject" fi

Categories : Osx

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

unexpected fi in bash script
while ends with done, not exit. Try this: if type "java" 2>&1; then echo "All ok . . . "; exit else read -n1 -r -p "Yo need to install" while true; do echo "Want to install??" select yn in "y" "n"; do case $yn in y ) echo "Installing here..."; break;; n ) echo "Ok... stopping..."; exit;; esac # <-- ending `case` done # <-- ending `select` done # <-- while ends with `done`, not `exit`! fi # <-- ending `if`

Categories : Bash

What does : ${ROOT_DIR:="."} do in a bash script?
ROOT_DIR is not special, it's just a variable this shell script happens to use. : does nothing. In particular, it is used here as a dummy command to allow the side effect of := to take effect, assigning the default value to ROOT_DIR. You can get a bit more detail from the bash man page: : [arguments] No effect; the command does nothing beyond expanding arguments and performing any specified redirections. A zero exit code is returned. "Expanding arguments" is the important part here, it allows the default assignment to occur. ${parameter:=word} Assign Default Values. If parameter is unset or null, the expansion of word is assigned to parameter. The value of parameter is then substituted. Positional parameters and special par

Categories : Bash

Awk/Bash writing script
This answer doesn't explore alternatives like using split or csplit to partition the file. Assuming that a=$(wc -l < $1), and that $3 contains the number of fragments (10 in the example written out longhand), then you can take your existing code and package it as one or two loops using seq to generate the numbers you need: a=$(wc -l < "$1") n=${3:-10} for i in $(seq 1 $n) do # a = number of records in file # n = number of parts the file is to be split into # p = part number of current part awk -v a=$a -v n=$n -v p=$i '{if (NR<(a/n*p)&&NR>=(a/n*(p-1))) print }' "$1" >"$1.$i" bash "$2" "$1.$i" & done wait # For all the background processes to complete That's the single loop version; you can create all the files first and then run a second

Categories : Bash

How to run cd within bash script (outside of subshell)
When you source a file from tcsh, it tcsh runs the commands. The #! is ignored as a comment because you're not running the file as a script, just reading commands from it as if they'd been entered at the shell prompt. Your mission is doomed to failure. Only a tcsh cd command can change the current directory of a tcsh process. But if you're willing to bend a little, you can write a script which runs as a separate process and outputs the name of the directory to cd to. Then set the alias like alias gotodir 'cd `/blah/blah/thescript`' Addendum Adding an argument is possible, but tricky. Alias arguments look like history expansion, with !:1 expanding to the first argument. But quotes don't protect the ! character. You have to backslash it to prevent it being expanded during creation of t

Categories : Bash

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

Run bash script on `cd` command
One feature of Unix shells is that they let you create shell functions, which are much like functions in other languages; they are essentially named groups of commands. For example, you can write a function named mycd that first runs cd, and then runs other commands: function mycd () { cd "$@" if ... ; then workon environment fi } (The "$@" expands to the arguments that you passed to mycd; so mycd /path/to/dir will call cd /path/to/dir.) As a special case, a shell function actually supersedes a like-named builtin command; so if you name your function cd, it will be run instead of the cd builtin whenever you run cd. In that case, in order for the function to call the builtin cd to perform the actual directory-change (instead of calling itself, causing infinite recurs

Categories : Python

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.