i’m running a bash script that submits some pbs Jobs on a Linux based Cluster multiple times. each Submission calls Matlab, reads some data, performs calculations, and writes the results back to my Directory. This process works fine without one exception. For some calculations the m-file starts, loads e…
Tag: bash
PID of infinite loop run in background (&) in bash script
I have simple bash script How can I assign pid of this loop to variable, to kill process in future ? I try trap, but loop has own pid so I should know pid of loop running in background to kill it for example after SIGTERM. Answer The PID of the background-process started can be extracted from this $! variable…
Better way of using the redirection symbol in conjunction with find -exec
My goal is to empty every file in a directory. I DON’T want to actually delete the file, I just want to delete it’s contents. If you want to do this with a single file you can do > file.txt If I want to run this operation on every file in a directory I can do this: Notice how the
Replace very near word to a number with another word [closed]
Closed. This question needs debugging details. It is not currently accepting answers. Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question. Closed 6 years ago. Improve this question Repla…
Strange output in shell script
I’m encountering a very strange thing while writing a shell script. Initially I have the following script. When I ran this script, every 60 seconds, I’ll see the $DATETIME,$FIELD1 values in my log file. What is very strange, is that every 30 seconds or so, after the first minute has passed, I̵…
how to replace decimal in linux
I have a csv file with error in one field, the fields are separated by “,” but the error is in decimal field, for example 34.25,” i need replace by 34.25″,”. Search ,” and replace by “,” is not option, others fields will modified. Answer Check that the character…
Using grep and * to get the exact file name
I have following heapdump files now if I use I get following output But I use I get no output. Could anybody help where is my mistake and how to search the heapdump files. My expected output is should give me due to some reason I could not use Answer It looks like you’re confusing glob patterns with reg…
How to restrict a particular command in bash?
I have bash-3.2.tar.gz I have all the tools needed to compile the bash. Now I need to restrict a command in the compiled bash binary, e.g. I want to restrict the command “kill” in the compiled bash binary. How to achieve this? Thanks in advance. Answer It’s not clear exactly what you’r…
Bash if condition doesn’t match when comparing particular string
Bash if condition doesn’t match when comparing particular string Matching string: Code: I expected this to match, but it does not. The same code works with other strings. Is this failing because of ( or ) character in the string? Answer You have variable matching reversed. You have to use * matching aro…
Shell script executed from php, but commands in sh script wont run
I’m making a PHP page with the purpose of creating and activating Apache VirtualHost files. The pages generates the files and places it in /etc/apache2/sites-available/. After that a shell script is called by with: shell_exec(“/bin/sh /usr/local/bin/myscript.sh”); myscript.sh: The script see…