Questions about bash only, as opposed to other Bourne/POSIX shells. For all Bourne/POSIX-style shells, use the /shell tag instead.

learn more… | top users | synonyms

1
vote
2answers
25 views

script to add users to otrs

Im looking for a fast way to import customer users into otrs (ticket system) I have an export from Active Directory with: firstname lastname password email username There is a script in the otrs/bin ...
0
votes
2answers
19 views

Redirecting stdout to terminal and file without using a pipe?

I have code, that goes something like this: #!/bin/bash VAR=0 func() { VAR=$((VAR+1)) echo 'Logging information.' } func 2>&1 | tee 'log.txt' echo "Should be 1: ${VAR}" When ...
9
votes
2answers
500 views

How do I force a user to change a password at the first time login using ssh?

I'm trying to force a newly created user to change a password at the first time login using ssh. For security reasons I want to give him a secure password until he logs in for the first time. I did ...
10
votes
3answers
121 views

Finding the correct tmp dir on multiple platforms

I have a script that needs to create temporary files for its work, and clean up after itself. My question is about finding the right base directory for the temporary files. The script needs to work ...
1
vote
1answer
17 views

Process id of a command ran by an user

Consider i am running just some basic command.. ls Now would the above command have a pid, when it was getting executed? If yes, then how can i determine that pid? when i try echo $! right ...
8
votes
2answers
90 views

How can I conditionally pass a subshell through 'time'?

I have a setup script for a Vagrant box where I used to measure single steps with time. Now I would like to conditionally enable or disable the time measurements. For example, previously a line would ...
0
votes
0answers
21 views

pkill -P $ID working while kill — -$ID not

I was playing around with creating and killing process groups on linux ( ubuntu ) I am trying to kill a process group and am being driven crazy by the fact that pkill -P $ID works while kill -- -$ID ...
2
votes
2answers
49 views

Am I hitting a race condition in bash?

I have a script which compares the output of a command with the output of the same command as it was ran previously, it works most of the time, but every now and then it doesn't work as expected. ...
4
votes
1answer
126 views

How do I use null bytes in Bash?

I've read that, since file-paths in Bash can contain any character except the null byte (zero-valued byte, $'\0'), that it's best to use the null byte as a separator. For example, if the output of ...
2
votes
2answers
64 views

What is the purpose of using shift in bash scripts?

I have came across this script: #! /bin/bash ...
1
vote
2answers
56 views

How do I expect 'echo -e “? \c”'?

I'm an absolute newbie to the UNIX world and have been asked to write a script that interacts with another one - but I'm stuck. The script that I interact with echos the following and I need to send a ...
3
votes
1answer
30 views

Problem with passing parameters containing spaces and wild card characters

I have a problem passing parameters if the parameters may contain wildcards and/or spaces, if those parameters are optional. Since this sounds pretty abstract, let's have a small example: The ...
6
votes
6answers
41k views

Why does find -mtime +1 only return files older than 2 days?

CentOS 5.9 I'm struggling to wrap my mind around why the find interprets file modification times the way it does. Specifically, I don't understand why the -mtime +1 doesn't show files less than 48 ...
0
votes
3answers
349 views

Solaris jdk 7 installation error java -version No such file or directory

Am trying to follow this website for instruction on how to install jdk for Solaris 10 with the following information: $ isainfo -v 64-bit amd64 applications ssse3 tscp sse3 sse2 sse fxsr mmx ...
2
votes
4answers
13k views

Yum update problems on CentOS 6.5 minimal as VMware guest

INFO: I am using Windows 7 Pro (64bit) with VMware Workstation version 10.0.1 . I am using CentOS(64bit) 6.5 minimal, for the first time. I am running this from my workplace network, which may use a ...
4
votes
3answers
332 views

How can I start a process with any name which does nothing?

I want to start a process that does nothing but is still running. Say I start a process called sadhadxk, and when I run pgrep -x "sadhadxk" I will get the PID number back, like any normal process ...
55
votes
16answers
41k views

How can I get my external IP address in bash?

I need to find my external IP address from a bash script. At the moment I use this function: myip () { lwp-request -o text checkip.dyndns.org | awk '{ print $NF }' } But it depends on ...
4
votes
1answer
221 views

How to set an optional parameter? [closed]

Suppose you have the following problem: Depending on if a script is executed within a pipe or not, you want to append the -print0 parameter to find. I can think of at least two ways to do this: [[ ...
3
votes
4answers
61 views

Inner loop conditions shall depend on outer loop run

How can I build an inner loop such that the loop condition depends on the outer loop run? My very situation does probably not matter for the code I am looking for, but here it is: I have a crawler ...
1
vote
4answers
92 views

Killing a shell script running in background

I have written a shell script to monitor a directory using the inotifywait utility of inotifyt-tools. I want that script to run continuously in the background, but I also want to be able to stop it ...
4
votes
2answers
3k views

Bash globbing and argument passing

I have the following simplified bash script #!/bin/bash files=("$@") if [ "X$files" = "X" ]; then files=$HOME/print/*.pdf; fi for file in "${files[@]}"; do ls "$file"; done If I pass ...
4
votes
5answers
203 views

efficient cross-os file size shell function

I'm looking for a simpler way to have a cross-os-unix file size check. I could use wc -c but I'm concerned the performance may suck on large files (I'm assuming it just counts chars and doesn't do a ...
0
votes
1answer
148 views

Trying to pass user generated variable to an external command

I have a bash script that is asking a user for input, then passes that variable to a find command. I've tried quoting/escaping the variable every way I know, but it keeps failing. read -p "Please ...
4
votes
4answers
14k views

BASH: launch background process and check when it ends

How can I launch a process in background and check when it ends within a bash script? My idea is a script like this: launch backgroundprocess & while [ Process is running ];do echo "PROCESS ...
12
votes
7answers
3k views

Test if multiple variables are set

I'd like to make sure that at a certain point of a script, after sourceing a configuration file, several variables are set and, if they are not, to stop execution, telling the user about the missing ...
-1
votes
2answers
1k views

Input validation in a bash script [duplicate]

I've got the basics of bash scripting (I think anyways), and i'm trying to move on to more advanced stuff. I am trying to write a script that will perform input validation (the user must input either ...
1
vote
1answer
51 views

processing multiple extensions

I have done a script to convert recursive .jpg files to another size: echo $re mkdir "$re"_tmp for a in *.jpg ; do convert "$a" -resize $re "$re""_tmp/${a%.*} ["$re"].jpg" ; done I'd like integrate ...
10
votes
0answers
330 views

How was the Shellshock Bash vulnerability found?

Since this bug affects so many platforms, we might learn something from the process by which this vulnerability was found: was it an εὕρηκα (eureka) moment or the result of a security check? Since we ...
1
vote
2answers
144 views

aliasing a slightly complex script on Linux/bash

Stormvirux provided this nice script in another thread. It puts column headings on the output of an ls -l listing: #!/bin/bash { echo Permissions links Owner Group Size Last_modMonth Last_modTime ...
0
votes
1answer
50 views

skip line that doesn't contain perticular character eg .colon

I am reading lines from the file in while loop. while read line do #process line done I want to skip the line that does not contain colon. Any help?
0
votes
2answers
882 views

How to get the value from rows and columns from text file in bash?

I am working on a bash project. I need to get all the values (one at a time because I will be using them somewhere else) from a text file. The text file I will be getting is structured like this: ...
2
votes
2answers
103 views

I want a script which will take multiple column numbers from a user and reverse the contents

I want a Unix script which will take multiple column numbers from the user and reverse the contents. declare -a param="$@" # enter 0 when exit the insert element echo "Enter the numbers" read n while ...
1
vote
2answers
230 views

Using if statement with or to validate arguments for shell script

I'm working on a bash script to restart multiple apache instances in different environments. It's working fine except I'd like to add some logic to ensure only correct arguments are entered. I've ...
2
votes
2answers
112 views

How to write a function in bash?

I am drawing blank here. How should I have written this script? #!/bin/sh XZY_NODES="\ vl-ocnt-1 \ vl-ocnt-2 \ vl-onet-1 \ vl-onet-2 \ vl-ocmp-1 \ vl-oomp-2 \ " is_xyz_node () { host=$1 ...
7
votes
5answers
428 views

List out strings which are substrings of other strings in the list

I have a list of names like so: dog_bone dog_collar dragon cool_dragon lion lion_trainer dog I need to extract out names that appear in other names like so: dragon lion dog I looked through the ...
3
votes
2answers
81 views

exclude particular file from bash_completion

I have a simple bash_completion code. The only thing it does, is when I type grcat and then Tab, it offers to complete filenames from /etc/grcat. _grcat() { local word COMPREPLY=() if [ 1 ...
2
votes
2answers
280 views

bash function execution from command line

I love to play with bash script a lot. But I want to enhance the way I use bash script. I have a script(nepleaks.sh) as below used during my programming, ~ 1 clean(){ ...
5
votes
1answer
153 views

bash_completion rule for resolving ip into hostnames

I am trying to create a bash_completion rule for my script rmpxe. This script takes <hostname> as its only argument. It then resolves this hostname into <ip_address> and removes the ...
1
vote
2answers
65 views

command condition sometimes integer sometimes string

I want to execute this condition while [ $(cat /path_of a file/) -eq 1 ] The condition is only correct if $(cat /path_of a file/) is an integer and not a string ! How can I overcome this ...
1
vote
1answer
245 views

How to implement retry mechanism while executing the server url in the shell script?

I am working on a project in which I need to make a url call to one of my server from the bash shell script.. http://hostname.domain.com:8080/beat After hitting the above url, I will be getting the ...
2
votes
1answer
572 views

Forward SIGTERM to child in Bash

I have a Bash script, which looks similar to this: #!/bin/bash echo "Doing some initial work...."; /bin/start/main/server --nodaemon Now if the bash shell running the script receives a SIGTERM ...
0
votes
1answer
203 views

Got “syntax error near unexpected end of file” in bash script

I'm making an script that gives me a day like this jjj/yyyy when I give it a day like this dd/mm/yyyy and I need it to have an error when you don't write correctly but I'm starting and it's not ...
4
votes
1answer
70 views

Calling `source` from bash function

I'm trying to source a file whose name is passed from stdin. My plan is to create a function like this: mySource() { # get stdin and pass it as an argument to `source` source $(cat) } to be ...
4
votes
2answers
713 views

TinyCore Linux & RVM

I'm running TinyCore Linux and when I tried to install RVM (needed a portable linux distro for QA Automation) I keep getting an error sh: syntax error:unexpected redirection. I am unsure why I am ...
8
votes
4answers
6k views

how to count total number of words in a file?

I am looking for a command to count number of all words in a file. For instance if a file is like this, today is a good day then it should print 5, since there are 5 words there.
3
votes
3answers
54 views

source /dev/stdin doesn't work as expected

Let's start with simple tests that work for me to check that source /dev/stdin can be used at all. # echo -ne 'echo a\necho b\n' | source /dev/stdin a b Now I would like to source an actual ...
130
votes
11answers
38k views

Preserve bash history in multiple terminal windows

I consistently have more than one terminal open. Anywhere from two to ten, doing various bits and bobs. Now let's say I restart and open up another set of terminals. Some remember certain things, some ...
4
votes
2answers
104 views

Find and create empty files with the same name in another location

I want create empty files with the same name, but in another location. Is it possible? find some files use only filenames touch an empty file in another place Something like this: find . -type f ...
0
votes
1answer
39 views

replacing some text in square brakets in bash

I have this string that I get from running jack_lsp. a2j:Arturia BeatStep [28] (capture): Arturia BeatStep MIDI 1 in a xml file, I save the connections state from a previous jack session. ...
0
votes
1answer
1k views

Proper escaping of double quotations for curl post data?

I'm trying to test out a server, by sending it JSON data and reading the response. I need to POST data like {"item":"value with spaces"} but when I use curl I find that it sends the backslashes as ...